diff --git a/WiFiManager.h b/WiFiManager.h index c44057d..7f77483 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -31,7 +31,7 @@ // #include "soc/efuse_reg.h" // include to add efuse chip rev to info, getChipRevision() is almost always the same though, so not sure why it matters. -// #define esp32autoreconnect // implement esp32 autoreconnect event listener kludge, deprecated +// #define esp32autoreconnect // implement esp32 autoreconnect event listener kludge, @DEPRECATED // autoreconnect is WORKING https://github.com/espressif/arduino-esp32/issues/653#issuecomment-405604766 #define WM_WEBSERVERSHIM // use webserver shim lib diff --git a/examples/Advanced/Advanced.ino b/examples/Advanced/Advanced.ino index 700ab6c..21a4bd9 100644 --- a/examples/Advanced/Advanced.ino +++ b/examples/Advanced/Advanced.ino @@ -69,11 +69,11 @@ void setup() { void checkButton(){ // check for button press if ( digitalRead(TRIGGER_PIN) == LOW ) { - // poor mans debounce/press-hold, not recommended for production code + // poor mans debounce/press-hold, code not ideal for production delay(50); if( digitalRead(TRIGGER_PIN) == LOW ){ - // holding button 3000 ms, reset settings + // still holding button for 3000 ms, reset settings, code not ideaa for production delay(3000); // reset delay hold if( digitalRead(TRIGGER_PIN) == LOW ){ Serial.println("Erasing Config"); diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 8ceebd8..308eb1a 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -2,39 +2,17 @@ * This is a kind of unit test for DEV for now */ #include // https://github.com/tzapu/WiFiManager +#include #define TRIGGER_PIN 0 const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; WiFiManager wm; -bool TEST_CP = true; // always start the configportal - +bool TEST_CP = false; // always start the configportal +bool TEST_NET = true; // do a network test, get ntp time char ssid[] = "*************"; // your network SSID (name) char pass[] = "********"; // your network password -void debugchipid(){ - // WiFi.mode(WIFI_STA); - // WiFi.printDiag(Serial); - // Serial.println(modes[WiFi.getMode()]); - - // ESP.eraseConfig(); - // wm.resetSettings(); - // wm.erase(true); - WiFi.mode(WIFI_AP); - // WiFi.softAP(); - WiFi.enableAP(true); - delay(500); - // esp_wifi_start(); - delay(1000); - WiFi.printDiag(Serial); - delay(60000); - ESP.restart(); - - // AP esp_267751 - // 507726A4AE30 - // ESP32 Chip ID = 507726A4AE30 -} - void saveWifiCallback(){ Serial.println("[CALLBACK] saveCallback fired"); } @@ -68,12 +46,8 @@ void setup() { Serial.setDebugOutput(true); // delay(3000); Serial.println("\n Starting"); - // WiFi.setSleepMode(WIFI_NONE_SLEEP); + // WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability - //WiFiManager - //Local intialization. Once its business is done, there is no need to keep it around - // WiFiManager wm; - wm.debugPlatformInfo(); //Local intialization. Once its business is done, there is no need to keep it around @@ -90,12 +64,12 @@ void setup() { // wm.setConnectTimeout(5); // wm.setShowStaticFields(true); - WiFiManagerParameter custom_html("

This Is Custom HTML

"); + WiFiManagerParameter custom_html("

This Is Custom HTML

"); // only custom html WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40); WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6); WiFiManagerParameter custom_token("api_token", "api token", "", 16); WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); // id is invalid, cannot contain spaces - WiFiManagerParameter custom_ipaddress("input_ip", "input IP", "", 15,"pattern='\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}'"); + WiFiManagerParameter custom_ipaddress("input_ip", "input IP", "", 15,"pattern='\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}'"); // custom input attrs (ip mask) // callbacks wm.setAPCallback(configModeCallback); @@ -114,11 +88,12 @@ void setup() { custom_html.setValue("test",4); custom_token.setValue("test",4); + // Set cutom menu via menu[] or vector // const char* menu[] = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"}; - // wm.setMenu(menu,9); + // wm.setMenu(menu,9); // custom menu array must provide length std::vector menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"}; - // wm.setMenu(menu); + // wm.setMenu(menu); // custom menu, pass vector // set static sta ip // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); @@ -153,7 +128,10 @@ void setup() { wm.setConfigPortalTimeout(60); wm.startConfigPortal(); } - + else { + //if you get here you have connected to the WiFi + Serial.println("connected...yeey :)"); + } pinMode(TRIGGER_PIN, INPUT); } @@ -161,22 +139,8 @@ void loop() { // is configuration portal requested? if ( digitalRead(TRIGGER_PIN) == LOW ) { Serial.println("BUTTON PRESSED"); - //WiFiManager - //Local intialization. Once its business is done, there is no need to keep it around - //reset settings - for testing - //wm.resetSettings(); - - //sets timeout until configuration portal gets turned off - //useful to make it all retry or go to sleep, in seconds wm.setConfigPortalTimeout(120); - //it starts an access point with the specified name - //here "AutoConnectAP" - //and goes into a blocking loop awaiting configuration - - //WITHOUT THIS THE AP DOES NOT SEEM TO WORK PROPERLY WITH SDK 1.5 , update to at least 1.5.1 - //WiFi.mode(WIFI_STA); - // disable captive portal redirection // wm.setCaptivePortalEnable(false); @@ -186,9 +150,58 @@ void loop() { } else { //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); - } + getTime(); + } } + if(WiFi.status() == WL_CONNECTED) getTime(); // put your main code here, to run repeatedly: delay(5000); } + +void getTime() { + int tz = -5; + int dst = 0; + time_t now = time(nullptr); + unsigned timeout = 5000; + unsigned start = millis(); + configTime(tz * 3600, dst * 3600, "pool.ntp.org", "time.nist.gov"); + Serial.print("Waiting for NTP time sync: "); + while (now < 8 * 3600 * 2 ) { + delay(100); + Serial.print("."); + now = time(nullptr); + if((millis() - start) > timeout){ + Serial.println("[ERROR] Failed to get NTP time."); + return; + } + } + Serial.println(""); + struct tm timeinfo; + gmtime_r(&now, &timeinfo); + Serial.print("Current time: "); + Serial.print(asctime(&timeinfo)); +} + +void debugchipid(){ + // WiFi.mode(WIFI_STA); + // WiFi.printDiag(Serial); + // Serial.println(modes[WiFi.getMode()]); + + // ESP.eraseConfig(); + // wm.resetSettings(); + // wm.erase(true); + WiFi.mode(WIFI_AP); + // WiFi.softAP(); + WiFi.enableAP(true); + delay(500); + // esp_wifi_start(); + delay(1000); + WiFi.printDiag(Serial); + delay(60000); + ESP.restart(); + + // AP esp_267751 + // 507726A4AE30 + // ESP32 Chip ID = 507726A4AE30 +} \ No newline at end of file