初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
WiFiManager wm;
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
//reset settings - wipe credentials for testing
//wm.resetSettings();
wm.setConfigPortalBlocking(false);
wm.setConfigPortalTimeout(60);
//automatically connect using saved credentials if they exist
//If connection fails it starts an access point with the specified name
if(wm.autoConnect("AutoConnectAP")){
Serial.println("connected...yeey :)");
}
else {
Serial.println("Configportal running");
}
}
void loop() {
wm.process();
// put your main code here, to run repeatedly:
}

View File

@@ -0,0 +1,36 @@
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
WiFiManager wm;
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40);
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
//reset settings - wipe credentials for testing
//wm.resetSettings();
wm.addParameter(&custom_mqtt_server);
wm.setConfigPortalBlocking(false);
wm.setSaveParamsCallback(saveParamsCallback);
//automatically connect using saved credentials if they exist
//If connection fails it starts an access point with the specified name
if(wm.autoConnect("AutoConnectAP")){
Serial.println("connected...yeey :)");
}
else {
Serial.println("Configportal running");
}
}
void loop() {
wm.process();
// put your main code here, to run repeatedly:
}
void saveParamsCallback () {
Serial.println("Get Params:");
Serial.print(custom_mqtt_server.getID());
Serial.print(" : ");
Serial.println(custom_mqtt_server.getValue());
}

View File

@@ -0,0 +1,85 @@
/**
* OnDemandNonBlocking.ino
* example of running the webportal or configportal manually and non blocking
* trigger pin will start a webportal for 120 seconds then turn it off.
* startAP = true will start both the configportal AP and webportal
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
// include MDNS
#ifdef ESP8266
#include <ESP8266mDNS.h>
#elif defined(ESP32)
#include <ESPmDNS.h>
#endif
// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0
WiFiManager wm;
unsigned int timeout = 120; // seconds to run for
unsigned int startTime = millis();
bool portalRunning = false;
bool startAP = false; // start AP and webserver if true, else start only webserver
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once
Serial.begin(115200);
Serial.setDebugOutput(true);
delay(1000);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
// wm.resetSettings();
wm.setHostname("MDNSEXAMPLE");
// wm.setEnableConfigPortal(false);
// wm.setConfigPortalBlocking(false);
wm.autoConnect();
}
void loop() {
#ifdef ESP8266
MDNS.update();
#endif
doWiFiManager();
// put your main code here, to run repeatedly:
}
void doWiFiManager(){
// is auto timeout portal running
if(portalRunning){
wm.process(); // do processing
// check for timeout
if((millis()-startTime) > (timeout*1000)){
Serial.println("portaltimeout");
portalRunning = false;
if(startAP){
wm.stopConfigPortal();
}
else{
wm.stopWebPortal();
}
}
}
// is configuration portal requested?
if(digitalRead(TRIGGER_PIN) == LOW && (!portalRunning)) {
if(startAP){
Serial.println("Button Pressed, Starting Config Portal");
wm.setConfigPortalBlocking(false);
wm.startConfigPortal();
}
else{
Serial.println("Button Pressed, Starting Web Portal");
wm.startWebPortal();
}
portalRunning = true;
startTime = millis();
}
}