updated drd

This commit is contained in:
2024-01-31 16:20:00 +01:00
parent 31fea83a3a
commit 6eddf7b518
10 changed files with 177 additions and 144 deletions

View File

@@ -21,7 +21,7 @@ void printDateTime(time_t t, const char *tz)
strcpy(m, monthShortStr(month(t))); strcpy(m, monthShortStr(month(t)));
sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s", sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz); hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);
Serial.println(buf); log_v("localtime: %s", buf);
} }
time_t getLocalTime() time_t getLocalTime()
@@ -44,9 +44,11 @@ void initClock()
void loopClock() void loopClock()
{ {
if(getWifiStatus()) if(getWifiStatus())
{ {
if(getWifiStatus() & !provider_Set) setLEDWifiState(false);
setRTCState(true);
if(!provider_Set)
{ {
setSyncProvider(getLocalTime); setSyncProvider(getLocalTime);
setSyncInterval(10); setSyncInterval(10);
@@ -55,9 +57,12 @@ void loopClock()
} }
RTC_present = timeStatus ? timeSet: true, false; RTC_present = timeStatus ? timeSet: true, false;
setRTCState(!RTC_present);
} }
else else
{ {
setLEDWifiState(true);
RTC_present = false; RTC_present = false;
} }
} }

View File

@@ -3,6 +3,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "connection.h" #include "connection.h"
#include "util.h" #include "util.h"
#include "led.h"
#include <Timezone.h> // https://github.com/JChristensen/Timezone #include <Timezone.h> // https://github.com/JChristensen/Timezone
void initClock(); void initClock();

View File

@@ -9,7 +9,7 @@ bool getWifiStatus()
if(!printed && wifiConnected) if(!printed && wifiConnected)
{ {
log_i("IP number assigned by DHCP is %s",WiFi.localIP()); log_i("IP number assigned by DHCP is %s",WiFi.localIP().toString().c_str());
printed = true; printed = true;
} }
return wifiConnected; return wifiConnected;

View File

@@ -0,0 +1,62 @@
#include "led.h"
bool toggleState;
void initLeds()
{
log_i("init leds");
pinMode(ledRPin, OUTPUT);
pinMode(ledGPin, OUTPUT);
pinMode(ledBPin, OUTPUT);
digitalWrite(ledRPin, 0);
digitalWrite(ledGPin, 0);
digitalWrite(ledBPin, 0);
toggleState = false;
}
void setLEDWifiState(bool state)
{
digitalWrite(ledBPin, state);
}
void setRTCState(bool state)
{
digitalWrite(ledRPin, state);
}
void setOKState(bool state)
{
digitalWrite(ledGPin, state);
if (state)
{
setLEDWifiState(false);
setRTCState(false);
}
}
void setLedRaw(bool R, bool G, bool B)
{
digitalWrite(ledRPin, R);
digitalWrite(ledGPin, G);
digitalWrite(ledBPin, B);
}
void setLedRawToggle(bool R, bool G, bool B)
{
if(toggleState)
{
digitalWrite(ledRPin, !R);
digitalWrite(ledGPin, !G);
digitalWrite(ledBPin, !B);
toggleState = false;
}
else
{
digitalWrite(ledRPin, R);
digitalWrite(ledGPin, G);
digitalWrite(ledBPin, B);
toggleState = true;
}
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include <Arduino.h>
#include "defines.h"
void initLeds();
void setLEDWifiState(bool state);
void setRTCState(bool state);
void setOKState(bool state);
void setLedRaw(bool R, bool G, bool B);
void setLedRawToggle(bool R, bool G, bool B);

View File

@@ -4,6 +4,7 @@
#include "wifimanager.h" #include "wifimanager.h"
#include "tubes.h" #include "tubes.h"
#include "ota.h" #include "ota.h"
#include "led.h"
/******************************************************************************************************* /*******************************************************************************************************
Init Programm Init Programm
@@ -14,26 +15,30 @@ void setup()
Serial.begin(115200); Serial.begin(115200);
log_i("init hardware"); log_i("init hardware");
initLeds();
setLedRaw(true, true, true);
initTubes(); initTubes();
setLedRaw(true, false, true);
pinMode(ledRPin, OUTPUT);
pinMode(ledGPin, OUTPUT);
pinMode(ledBPin, OUTPUT);
digitalWrite(ledRPin, 0);
digitalWrite(ledGPin, 0);
digitalWrite(ledBPin, 0);
log_i("init clock"); log_i("init clock");
setupwifiman(); setupwifiman();
setLedRaw(true, true, false);
initClock(); initClock();
setLedRaw(true, false, false);
initOTA(); initOTA();
while(!timeIsSet()) while(!timeIsSet())
{ {
doTest(); setLedRawToggle(true, false, false);
//doTest();
loopClock(); loopClock();
loopTubes();
} }
setLedRaw(false, true, false);
delay(2000);
setLedRaw(false, false, false);
log_i("init done, GO!"); log_i("init done, GO!");
} }
@@ -44,4 +49,5 @@ MAIN Programm
void loop() { void loop() {
loopTubes(); loopTubes();
loopOTA(); loopOTA();
loopwifiman();
} }

View File

@@ -3,11 +3,8 @@
void initOTA() { void initOTA() {
Serial.begin(115200); Serial.begin(115200);
Serial.println("Booting");
// WiFi.mode(WIFI_STA);
// WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) { while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting..."); log_i("Connection Failed! Rebooting...");
delay(5000); delay(5000);
ESP.restart(); ESP.restart();
} }
@@ -34,28 +31,26 @@ void initOTA() {
type = "filesystem"; type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type); log_i("Start updating %s", type);
}) })
.onEnd([]() { .onEnd([]() {
Serial.println("\nEnd"); log_i("End");
}) })
.onProgress([](unsigned int progress, unsigned int total) { .onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100))); Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
}) })
.onError([](ota_error_t error) { .onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error); log_e("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); if (error == OTA_AUTH_ERROR) log_e("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); else if (error == OTA_BEGIN_ERROR) log_e("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); else if (error == OTA_CONNECT_ERROR) log_e("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); else if (error == OTA_RECEIVE_ERROR) log_e("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed"); else if (error == OTA_END_ERROR) log_e("End Failed");
}); });
ArduinoOTA.begin(); ArduinoOTA.begin();
Serial.println("Ready"); log_i("Ready, IP address: %s ", WiFi.localIP().toString().c_str());
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
} }
void loopOTA() { void loopOTA() {

View File

@@ -47,10 +47,10 @@ bool doTest()
if(teststate == -1) if(teststate == -1)
{ {
Serial.println(F("Start Test")); log_i("Start Test");
startOfTest=millis(); startOfTest=millis();
teststate = 0; teststate = 0;
Serial.println(testStringArray[10]); log_i("testpattern: %s", testStringArray[10]);
} }
// byte b=1; // byte b=1;
@@ -60,14 +60,6 @@ bool doTest()
startOfTest=millis(); startOfTest=millis();
strIndex=strIndex+1; strIndex=strIndex+1;
if (strIndex==10) dlay=3000; if (strIndex==10) dlay=3000;
stringToDisplay=testStringArray[strIndex];
Serial.print("stringToDisplay=");
Serial.println(stringToDisplay);
Serial.print("strIndex=");
Serial.println(strIndex);
Serial.print("i=");
Serial.println(teststate);
if (strIndex==11) strIndex = -1; if (strIndex==11) strIndex = -1;
@@ -136,7 +128,6 @@ void modesChanger()
if (menuPosition==TimeIndex) if (menuPosition==TimeIndex)
stringToDisplay=antiPoisoning2(updateDateString(), getTimeNow()); stringToDisplay=antiPoisoning2(updateDateString(), getTimeNow());
else stringToDisplay=antiPoisoning2(getTimeNow(), updateDateString()); else stringToDisplay=antiPoisoning2(getTimeNow(), updateDateString());
// Serial.println("StrTDInToModeChng="+stringToDisplay);
} }
} else transactionInProgress=false; } else transactionInProgress=false;
} }

View File

@@ -17,7 +17,7 @@
DoubleResetDetector* drd;////// DoubleResetDetector* drd;//////
// Onboard LED I/O pin on NodeMCU board // Onboard LED I/O pin on NodeMCU board
const int PIN_LED = 2; // D4 on NodeMCU and WeMos. GPIO2/ADC12 of ESP32. Controls the onboard LED. //const int PIN_LED = 2; // D4 on NodeMCU and WeMos. GPIO2/ADC12 of ESP32. Controls the onboard LED.
// Indicates whether ESP has WiFi credentials saved from previous session, or double reset detected // Indicates whether ESP has WiFi credentials saved from previous session, or double reset detected
@@ -133,10 +133,10 @@ void initSTAIPConfigStruct(WiFi_STA_IPConfig &in_WM_STA_IPconfig)
void displayIPConfigStruct(WiFi_STA_IPConfig in_WM_STA_IPconfig) void displayIPConfigStruct(WiFi_STA_IPConfig in_WM_STA_IPconfig)
{ {
LOGERROR3(F("stationIP ="), in_WM_STA_IPconfig._sta_static_ip, ", gatewayIP =", in_WM_STA_IPconfig._sta_static_gw); log_e("stationIP = %s , gatewayIP = %s", in_WM_STA_IPconfig._sta_static_ip.toString().c_str(), in_WM_STA_IPconfig._sta_static_gw.toString().c_str());
LOGERROR1(F("netMask ="), in_WM_STA_IPconfig._sta_static_sn); log_e("netMask = %s", in_WM_STA_IPconfig._sta_static_sn.toString().c_str());
#if USE_CONFIGURABLE_DNS #if USE_CONFIGURABLE_DNS
LOGERROR3(F("dns1IP ="), in_WM_STA_IPconfig._sta_static_dns1, ", dns2IP =", in_WM_STA_IPconfig._sta_static_dns2); log_e("dns1IP = %s, dns2IP = %s ", in_WM_STA_IPconfig._sta_static_dns1.toString().c_str(), in_WM_STA_IPconfig._sta_static_dns2.toString().c_str());
#endif #endif
} }
@@ -175,12 +175,12 @@ uint8_t connectMultiWiFi()
//WiFi.mode(WIFI_STA); //WiFi.mode(WIFI_STA);
LOGERROR(F("ConnectMultiWiFi with :")); log_i("ConnectMultiWiFi with :");
if ( (Router_SSID != "") && (Router_Pass != "") ) if ( (Router_SSID != "") && (Router_Pass != "") )
{ {
LOGERROR3(F("* Flash-stored Router_SSID = "), Router_SSID, F(", Router_Pass = "), Router_Pass ); log_i("* Flash-stored Router_SSID = %s , Router_Pass = %s", Router_SSID, Router_Pass );
LOGERROR3(F("* Add SSID = "), Router_SSID, F(", PW = "), Router_Pass ); log_i("* Add SSID = %s, PW = %s", Router_SSID, Router_Pass );
wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str());
} }
@@ -189,11 +189,11 @@ uint8_t connectMultiWiFi()
// Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8)
if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
{ {
LOGERROR3(F("* Additional SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw ); log_i("* Additional SSID = %s , PW = ", WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw );
} }
} }
LOGERROR(F("Connecting MultiWifi...")); log_i("Connecting MultiWifi...");
//WiFi.mode(WIFI_STA); //WiFi.mode(WIFI_STA);
@@ -220,13 +220,13 @@ uint8_t connectMultiWiFi()
if ( status == WL_CONNECTED ) if ( status == WL_CONNECTED )
{ {
LOGERROR1(F("WiFi connected after time: "), i); log_i("WiFi connected after time: %i", i);
LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI()); log_i("SSID: %s,RSSI= %i", WiFi.SSID(), WiFi.RSSI());
LOGERROR3(F("Channel:"), WiFi.channel(), F(",IP address:"), WiFi.localIP() ); log_i("Channel: %i ,IP address: %s", WiFi.channel(), WiFi.localIP().toString().c_str());
} }
else else
{ {
LOGERROR(F("WiFi not connected")); log_e("WiFi not connected");
// To avoid unnecessary DRD // To avoid unnecessary DRD
drd->loop(); drd->loop();
@@ -245,17 +245,6 @@ uint8_t connectMultiWiFi()
void printLocalTime() void printLocalTime()
{ {
#if ESP8266
static time_t now;
now = time(nullptr);
if ( now > 1451602800 )
{
Serial.print("Local Date/Time: ");
Serial.print(ctime(&now));
}
#else
struct tm timeinfo; struct tm timeinfo;
getLocalTime( &timeinfo ); getLocalTime( &timeinfo );
@@ -264,43 +253,22 @@ void printLocalTime()
// You can get from timeinfo : tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec // You can get from timeinfo : tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec
if (timeinfo.tm_year > 100 ) if (timeinfo.tm_year > 100 )
{ {
Serial.print("Local Date/Time: "); log_i("Local Date/Time: %s", asctime( &timeinfo ));
Serial.print( asctime( &timeinfo ) );
} }
#endif
} }
#endif #endif
void heartBeatPrint() void heartBeatPrint()
{ {
#if USE_ESP_WIFIMANAGER_NTP
printLocalTime(); printLocalTime();
#else
static int num = 1;
if (WiFi.status() == WL_CONNECTED)
Serial.print(F("H")); // H means connected to WiFi
else
Serial.print(F("F")); // F means not connected to WiFi
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
#endif
} }
void check_WiFi() void check_WiFi()
{ {
if ( (WiFi.status() != WL_CONNECTED) ) if ( (WiFi.status() != WL_CONNECTED) )
{ {
Serial.println(F("\nWiFi lost. Call connectMultiWiFi in loop")); log_e("WiFi lost. Call connectMultiWiFi in loop");
connectMultiWiFi(); connectMultiWiFi();
} }
} }
@@ -352,7 +320,7 @@ int calcChecksum(uint8_t* address, uint16_t sizeToCalc)
bool loadConfigData() bool loadConfigData()
{ {
File file = FileFS.open(CONFIG_FILENAME, "r"); File file = FileFS.open(CONFIG_FILENAME, "r");
LOGERROR(F("LoadWiFiCfgFile ")); log_e("LoadWiFiCfgFile ");
memset((void*) &WM_config, 0, sizeof(WM_config)); memset((void*) &WM_config, 0, sizeof(WM_config));
@@ -369,11 +337,11 @@ bool loadConfigData()
////// //////
file.close(); file.close();
LOGERROR(F("OK")); log_i("OK");
if ( WM_config.checksum != calcChecksum( (uint8_t*) &WM_config, sizeof(WM_config) - sizeof(WM_config.checksum) ) ) if ( WM_config.checksum != calcChecksum( (uint8_t*) &WM_config, sizeof(WM_config) - sizeof(WM_config.checksum) ) )
{ {
LOGERROR(F("WM_config checksum wrong")); log_e("WM_config checksum wrong");
return false; return false;
} }
@@ -410,11 +378,11 @@ void saveConfigData()
////// //////
file.close(); file.close();
LOGERROR(F("OK")); log_i("OK");
} }
else else
{ {
LOGERROR(F("failed")); log_e("failed");
} }
} }
@@ -425,27 +393,26 @@ void setupwifiman()
{ {
// put your setup code here, to run once: // put your setup code here, to run once:
// initialize the LED digital pin as an output. // initialize the LED digital pin as an output.
pinMode(PIN_LED, OUTPUT); //pinMode(PIN_LED, OUTPUT);
Serial.begin(115200); // Serial.begin(115200);
while (!Serial); // while (!Serial);
delay(200); //delay(200);
Serial.print(F("\nStarting ConfigOnDoubleReset with DoubleResetDetect using ")); Serial.print(FS_Name); log_i("Starting ConfigOnDoubleReset with DoubleResetDetect using %s",FS_Name);
Serial.print(F(" on ")); Serial.println(ARDUINO_BOARD); log_i(" on %s", ARDUINO_BOARD);
Serial.println(ESP_WIFIMANAGER_VERSION); log_i(ESP_WIFIMANAGER_VERSION);
Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); log_i(ESP_DOUBLE_RESET_DETECTOR_VERSION);
#if defined(ESP_WIFIMANAGER_VERSION_MIN) #if defined(ESP_WIFIMANAGER_VERSION_MIN)
if (ESP_WIFIMANAGER_VERSION_INT < ESP_WIFIMANAGER_VERSION_MIN) if (ESP_WIFIMANAGER_VERSION_INT < ESP_WIFIMANAGER_VERSION_MIN)
{ {
Serial.print("Warning. Must use this example on Version equal or later than : "); log_i("Warning. Must use this example on Version equal or later than : %s", ESP_WIFIMANAGER_VERSION_MIN_TARGET);
Serial.println(ESP_WIFIMANAGER_VERSION_MIN_TARGET);
} }
#endif #endif
Serial.setDebugOutput(false); //Serial.setDebugOutput(false);
if (FORMAT_FILESYSTEM) if (FORMAT_FILESYSTEM)
FileFS.format(); FileFS.format();
@@ -461,7 +428,7 @@ void setupwifiman()
FileFS.format(); FileFS.format();
#endif #endif
Serial.println(F("SPIFFS/LittleFS failed! Already tried formatting.")); log_w("SPIFFS/LittleFS failed! Already tried formatting.");
if (!FileFS.begin()) if (!FileFS.begin())
{ {
@@ -469,14 +436,15 @@ void setupwifiman()
delay(100); delay(100);
#if USE_LITTLEFS #if USE_LITTLEFS
Serial.println(F("LittleFS failed!. Please use SPIFFS or EEPROM. Stay forever")); log_w("LittleFS failed!. Please use SPIFFS or EEPROM. Stay forever");
#else #else
Serial.println(F("SPIFFS failed!. Please use LittleFS or EEPROM. Stay forever")); log_w("SPIFFS failed!. Please use SPIFFS or EEPROM. Stay forever");
#endif #endif
while (true) while (true)
{ {
delay(1); delay(1);
setLedRaw(true,false,false);
} }
} }
} }
@@ -529,7 +497,7 @@ void setupwifiman()
Router_Pass = ESP_wifiManager.WiFi_Pass(); Router_Pass = ESP_wifiManager.WiFi_Pass();
//Remove this line if you do not want to see WiFi password printed //Remove this line if you do not want to see WiFi password printed
Serial.println("ESP Self-Stored: SSID = " + Router_SSID + ", Pass = " + Router_Pass); log_i("ESP Self-Stored: SSID = %s, Pass = %s", Router_SSID, Router_Pass);
// SSID/PWD to uppercase // SSID/PWD to uppercase
ssid.toUpperCase(); ssid.toUpperCase();
@@ -544,7 +512,7 @@ void setupwifiman()
wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str());
ESP_wifiManager.setConfigPortalTimeout(240); //If no access point name has been previously entered disable timeout. ESP_wifiManager.setConfigPortalTimeout(240); //If no access point name has been previously entered disable timeout.
Serial.println(F("Got ESP Self-Stored Credentials. Timeout 120s for Config Portal")); log_i("Got ESP Self-Stored Credentials. Timeout 120s for Config Portal");
} }
if (loadConfigData()) if (loadConfigData())
@@ -552,7 +520,7 @@ void setupwifiman()
configDataLoaded = true; configDataLoaded = true;
ESP_wifiManager.setConfigPortalTimeout(240); //If no access point name has been previously entered disable timeout. ESP_wifiManager.setConfigPortalTimeout(240); //If no access point name has been previously entered disable timeout.
Serial.println(F("Got stored Credentials. Timeout 120s for Config Portal")); log_i("Got stored Credentials. Timeout 120s for Config Portal");
#if USE_ESP_WIFIMANAGER_NTP #if USE_ESP_WIFIMANAGER_NTP
if ( strlen(WM_config.TZ_Name) > 0 ) if ( strlen(WM_config.TZ_Name) > 0 )
@@ -568,51 +536,42 @@ void setupwifiman()
} }
else else
{ {
Serial.println(F("Current Timezone is not set. Enter Config Portal to set.")); log_w("Current Timezone is not set. Enter Config Portal to set.");
} }
#endif #endif
} }
else else
{ {
// Enter CP only if no stored SSID on flash and file // Enter CP only if no stored SSID on flash and file
Serial.println(F("Open Config Portal without Timeout: No stored Credentials.")); log_w("Open Config Portal without Timeout: No stored Credentials.");
initialConfig = true; initialConfig = true;
} }
if (drd->detectDoubleReset()) // if (drd->detectDoubleReset())
{ // {
// DRD, disable timeout. // // DRD, disable timeout.
ESP_wifiManager.setConfigPortalTimeout(0); // ESP_wifiManager.setConfigPortalTimeout(0);
Serial.println(F("Open Config Portal without Timeout: Double Reset Detected")); // log_w("Open Config Portal without Timeout: Double Reset Detected");
initialConfig = true; // initialConfig = true;
} // }
if (initialConfig) if (initialConfig)
{ {
Serial.print(F("Starting configuration portal @ "));
#if USE_CUSTOM_AP_IP #if USE_CUSTOM_AP_IP
Serial.print(APStaticIP); log_i("%s",APStaticIP);
#else #else
Serial.print(F("192.168.4.1")); log_i("Starting configuration portal @ 192.168.4.1");
#endif #endif
#if defined(HTTP_PORT_TO_USE) #if defined(HTTP_PORT_TO_USE)
Serial.print(F(":")); Serial.print(HTTP_PORT_TO_USE); log_i("portnr: %i", HTTP_PORT_TO_USE);
#endif #endif
Serial.print(F(", SSID = ")); log_i("SSID = %s, PWD = ", ssid, password);
Serial.print(ssid);
Serial.print(F(", PWD = "));
Serial.println(password);
digitalWrite(PIN_LED, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode.
//sets timeout in seconds until configuration portal gets turned off.
//If not specified device will remain in configuration mode until
//switched off via webserver or device is restarted.
//ESP_wifiManager.setConfigPortalTimeout(600);
#if DISPLAY_STORED_CREDENTIALS_IN_CP #if DISPLAY_STORED_CREDENTIALS_IN_CP
// New. Update Credentials, got from loadConfigData(), to display on CP // New. Update Credentials, got from loadConfigData(), to display on CP
@@ -622,10 +581,10 @@ void setupwifiman()
// Starts an access point // Starts an access point
if (!ESP_wifiManager.startConfigPortal((const char *) ssid.c_str(), (const char *) password.c_str())) if (!ESP_wifiManager.startConfigPortal((const char *) ssid.c_str(), (const char *) password.c_str()))
Serial.println(F("Not connected to WiFi but continuing anyway.")); log_e("Not connected to WiFi but continuing anyway.");
else else
{ {
Serial.println(F("WiFi connected...yeey :)")); log_i("WiFi connected...yeey :)");
} }
// Stored for later usage, from v1.1.0, but clear first // Stored for later usage, from v1.1.0, but clear first
@@ -693,7 +652,7 @@ void setupwifiman()
saveConfigData(); saveConfigData();
} }
digitalWrite(PIN_LED, LED_OFF); // Turn led off as we are not in configuration mode. //digitalWrite(PIN_LED, LED_OFF); // Turn led off as we are not in configuration mode.
startedAt = millis(); startedAt = millis();
@@ -715,30 +674,27 @@ void setupwifiman()
if ( WiFi.status() != WL_CONNECTED ) if ( WiFi.status() != WL_CONNECTED )
{ {
Serial.println(F("ConnectMultiWiFi in setup")); log_i("ConnectMultiWiFi in setup");
connectMultiWiFi(); connectMultiWiFi();
} }
} }
Serial.print(F("After waiting ")); log_i("After waiting %0.2f secs more in setup(), connection result is ", ((float) (millis() - startedAt) / 1000));
Serial.print((float) (millis() - startedAt) / 1000);
Serial.print(F(" secs more in setup(), connection result is "));
if (WiFi.status() == WL_CONNECTED) if (WiFi.status() == WL_CONNECTED)
{ {
Serial.print(F("connected. Local IP: ")); log_i("connected. Local IP: %s", WiFi.localIP().toString().c_str());
Serial.println(WiFi.localIP());
} }
else else
Serial.println(ESP_wifiManager.getStatus(WiFi.status())); log_w("wifistatus: %s", ESP_wifiManager.getStatus(WiFi.status()));
drdtimeout=millis(); drdtimeout=millis();
} }
void loopwifiman() void loopwifiman()
{ {
// Call the double reset detector loop method every so often, // Call the double reset detector loop method every so often,
@@ -746,8 +702,12 @@ void loopwifiman()
// You can also call drd.stop() when you wish to no longer // You can also call drd.stop() when you wish to no longer
// consider the next reset as a double reset. // consider the next reset as a double reset.
if(drdtimeout - millis() < (DRD_TIMEOUT+5)*1000)
{
drd->loop();
}
drd->loop();
// put your main code here, to run repeatedly // put your main code here, to run repeatedly

View File

@@ -39,7 +39,8 @@
This example, originally relied on the Double Reset Detector library from https://github.com/datacute/DoubleResetDetector This example, originally relied on the Double Reset Detector library from https://github.com/datacute/DoubleResetDetector
To support ESP32, use ESP_DoubleResetDetector library from //https://github.com/khoih-prog/ESP_DoubleResetDetector To support ESP32, use ESP_DoubleResetDetector library from //https://github.com/khoih-prog/ESP_DoubleResetDetector
*****************************************************************************************************************************/ *****************************************************************************************************************************/
#include "led.h"
void loopwifiman(); void loopwifiman();
void setupwifiman(); void setupwifiman();
@@ -117,7 +118,7 @@ void setupwifiman();
#endif #endif
////// //////
#define LED_BUILTIN 2 //#define LED_BUILTIN 2
#define LED_ON HIGH #define LED_ON HIGH
#define LED_OFF LOW #define LED_OFF LOW