updated drd
This commit is contained in:
@@ -21,7 +21,7 @@ void printDateTime(time_t t, const char *tz)
|
||||
strcpy(m, monthShortStr(month(t)));
|
||||
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);
|
||||
Serial.println(buf);
|
||||
log_v("localtime: %s", buf);
|
||||
}
|
||||
|
||||
time_t getLocalTime()
|
||||
@@ -44,9 +44,11 @@ void initClock()
|
||||
|
||||
void loopClock()
|
||||
{
|
||||
if(getWifiStatus())
|
||||
if(getWifiStatus())
|
||||
{
|
||||
if(getWifiStatus() & !provider_Set)
|
||||
setLEDWifiState(false);
|
||||
setRTCState(true);
|
||||
if(!provider_Set)
|
||||
{
|
||||
setSyncProvider(getLocalTime);
|
||||
setSyncInterval(10);
|
||||
@@ -55,9 +57,12 @@ void loopClock()
|
||||
}
|
||||
|
||||
RTC_present = timeStatus ? timeSet: true, false;
|
||||
setRTCState(!RTC_present);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
setLEDWifiState(true);
|
||||
RTC_present = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <Arduino.h>
|
||||
#include "connection.h"
|
||||
#include "util.h"
|
||||
#include "led.h"
|
||||
#include <Timezone.h> // https://github.com/JChristensen/Timezone
|
||||
|
||||
void initClock();
|
||||
|
||||
@@ -9,7 +9,7 @@ bool getWifiStatus()
|
||||
|
||||
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;
|
||||
}
|
||||
return wifiConnected;
|
||||
|
||||
62
FW/NCM107-ESP32C3/src/led.cpp
Normal file
62
FW/NCM107-ESP32C3/src/led.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
12
FW/NCM107-ESP32C3/src/led.h
Normal file
12
FW/NCM107-ESP32C3/src/led.h
Normal 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);
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "wifimanager.h"
|
||||
#include "tubes.h"
|
||||
#include "ota.h"
|
||||
#include "led.h"
|
||||
|
||||
/*******************************************************************************************************
|
||||
Init Programm
|
||||
@@ -14,26 +15,30 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
|
||||
log_i("init hardware");
|
||||
initLeds();
|
||||
setLedRaw(true, true, true);
|
||||
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");
|
||||
setupwifiman();
|
||||
setLedRaw(true, true, false);
|
||||
initClock();
|
||||
setLedRaw(true, false, false);
|
||||
initOTA();
|
||||
|
||||
while(!timeIsSet())
|
||||
{
|
||||
doTest();
|
||||
setLedRawToggle(true, false, false);
|
||||
//doTest();
|
||||
loopClock();
|
||||
loopTubes();
|
||||
|
||||
}
|
||||
setLedRaw(false, true, false);
|
||||
delay(2000);
|
||||
setLedRaw(false, false, false);
|
||||
|
||||
log_i("init done, GO!");
|
||||
}
|
||||
|
||||
@@ -44,4 +49,5 @@ MAIN Programm
|
||||
void loop() {
|
||||
loopTubes();
|
||||
loopOTA();
|
||||
loopwifiman();
|
||||
}
|
||||
@@ -3,11 +3,8 @@
|
||||
|
||||
void initOTA() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Booting");
|
||||
// WiFi.mode(WIFI_STA);
|
||||
// WiFi.begin(ssid, password);
|
||||
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.println("Connection Failed! Rebooting...");
|
||||
log_i("Connection Failed! Rebooting...");
|
||||
delay(5000);
|
||||
ESP.restart();
|
||||
}
|
||||
@@ -34,28 +31,26 @@ void initOTA() {
|
||||
type = "filesystem";
|
||||
|
||||
// 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([]() {
|
||||
Serial.println("\nEnd");
|
||||
log_i("End");
|
||||
})
|
||||
.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
})
|
||||
.onError([](ota_error_t error) {
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
||||
log_e("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) log_e("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) log_e("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) log_e("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) log_e("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) log_e("End Failed");
|
||||
});
|
||||
|
||||
ArduinoOTA.begin();
|
||||
|
||||
Serial.println("Ready");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
log_i("Ready, IP address: %s ", WiFi.localIP().toString().c_str());
|
||||
}
|
||||
|
||||
void loopOTA() {
|
||||
|
||||
@@ -47,10 +47,10 @@ bool doTest()
|
||||
|
||||
if(teststate == -1)
|
||||
{
|
||||
Serial.println(F("Start Test"));
|
||||
log_i("Start Test");
|
||||
startOfTest=millis();
|
||||
teststate = 0;
|
||||
Serial.println(testStringArray[10]);
|
||||
log_i("testpattern: %s", testStringArray[10]);
|
||||
}
|
||||
|
||||
// byte b=1;
|
||||
@@ -60,14 +60,6 @@ bool doTest()
|
||||
startOfTest=millis();
|
||||
strIndex=strIndex+1;
|
||||
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;
|
||||
|
||||
@@ -136,7 +128,6 @@ void modesChanger()
|
||||
if (menuPosition==TimeIndex)
|
||||
stringToDisplay=antiPoisoning2(updateDateString(), getTimeNow());
|
||||
else stringToDisplay=antiPoisoning2(getTimeNow(), updateDateString());
|
||||
// Serial.println("StrTDInToModeChng="+stringToDisplay);
|
||||
}
|
||||
} else transactionInProgress=false;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
DoubleResetDetector* drd;//////
|
||||
|
||||
// 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
|
||||
@@ -133,10 +133,10 @@ void initSTAIPConfigStruct(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);
|
||||
LOGERROR1(F("netMask ="), in_WM_STA_IPconfig._sta_static_sn);
|
||||
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());
|
||||
log_e("netMask = %s", in_WM_STA_IPconfig._sta_static_sn.toString().c_str());
|
||||
#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
|
||||
}
|
||||
|
||||
@@ -175,12 +175,12 @@ uint8_t connectMultiWiFi()
|
||||
|
||||
//WiFi.mode(WIFI_STA);
|
||||
|
||||
LOGERROR(F("ConnectMultiWiFi with :"));
|
||||
log_i("ConnectMultiWiFi with :");
|
||||
|
||||
if ( (Router_SSID != "") && (Router_Pass != "") )
|
||||
{
|
||||
LOGERROR3(F("* Flash-stored Router_SSID = "), Router_SSID, F(", Router_Pass = "), Router_Pass );
|
||||
LOGERROR3(F("* Add SSID = "), Router_SSID, F(", PW = "), Router_Pass );
|
||||
log_i("* Flash-stored Router_SSID = %s , Router_Pass = %s", Router_SSID, Router_Pass );
|
||||
log_i("* Add SSID = %s, PW = %s", Router_SSID, Router_Pass );
|
||||
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)
|
||||
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);
|
||||
|
||||
@@ -220,13 +220,13 @@ uint8_t connectMultiWiFi()
|
||||
|
||||
if ( status == WL_CONNECTED )
|
||||
{
|
||||
LOGERROR1(F("WiFi connected after time: "), i);
|
||||
LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI());
|
||||
LOGERROR3(F("Channel:"), WiFi.channel(), F(",IP address:"), WiFi.localIP() );
|
||||
log_i("WiFi connected after time: %i", i);
|
||||
log_i("SSID: %s,RSSI= %i", WiFi.SSID(), WiFi.RSSI());
|
||||
log_i("Channel: %i ,IP address: %s", WiFi.channel(), WiFi.localIP().toString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR(F("WiFi not connected"));
|
||||
log_e("WiFi not connected");
|
||||
|
||||
// To avoid unnecessary DRD
|
||||
drd->loop();
|
||||
@@ -245,17 +245,6 @@ uint8_t connectMultiWiFi()
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
if (timeinfo.tm_year > 100 )
|
||||
{
|
||||
Serial.print("Local Date/Time: ");
|
||||
Serial.print( asctime( &timeinfo ) );
|
||||
log_i("Local Date/Time: %s", asctime( &timeinfo ));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void heartBeatPrint()
|
||||
{
|
||||
#if USE_ESP_WIFIMANAGER_NTP
|
||||
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()
|
||||
{
|
||||
if ( (WiFi.status() != WL_CONNECTED) )
|
||||
{
|
||||
Serial.println(F("\nWiFi lost. Call connectMultiWiFi in loop"));
|
||||
log_e("WiFi lost. Call connectMultiWiFi in loop");
|
||||
connectMultiWiFi();
|
||||
}
|
||||
}
|
||||
@@ -352,7 +320,7 @@ int calcChecksum(uint8_t* address, uint16_t sizeToCalc)
|
||||
bool loadConfigData()
|
||||
{
|
||||
File file = FileFS.open(CONFIG_FILENAME, "r");
|
||||
LOGERROR(F("LoadWiFiCfgFile "));
|
||||
log_e("LoadWiFiCfgFile ");
|
||||
|
||||
memset((void*) &WM_config, 0, sizeof(WM_config));
|
||||
|
||||
@@ -369,11 +337,11 @@ bool loadConfigData()
|
||||
//////
|
||||
|
||||
file.close();
|
||||
LOGERROR(F("OK"));
|
||||
log_i("OK");
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -410,11 +378,11 @@ void saveConfigData()
|
||||
//////
|
||||
|
||||
file.close();
|
||||
LOGERROR(F("OK"));
|
||||
log_i("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR(F("failed"));
|
||||
log_e("failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,27 +393,26 @@ void setupwifiman()
|
||||
{
|
||||
// put your setup code here, to run once:
|
||||
// initialize the LED digital pin as an output.
|
||||
pinMode(PIN_LED, OUTPUT);
|
||||
//pinMode(PIN_LED, OUTPUT);
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
// Serial.begin(115200);
|
||||
// while (!Serial);
|
||||
|
||||
delay(200);
|
||||
//delay(200);
|
||||
|
||||
Serial.print(F("\nStarting ConfigOnDoubleReset with DoubleResetDetect using ")); Serial.print(FS_Name);
|
||||
Serial.print(F(" on ")); Serial.println(ARDUINO_BOARD);
|
||||
Serial.println(ESP_WIFIMANAGER_VERSION);
|
||||
Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION);
|
||||
log_i("Starting ConfigOnDoubleReset with DoubleResetDetect using %s",FS_Name);
|
||||
log_i(" on %s", ARDUINO_BOARD);
|
||||
log_i(ESP_WIFIMANAGER_VERSION);
|
||||
log_i(ESP_DOUBLE_RESET_DETECTOR_VERSION);
|
||||
|
||||
#if defined(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 : ");
|
||||
Serial.println(ESP_WIFIMANAGER_VERSION_MIN_TARGET);
|
||||
log_i("Warning. Must use this example on Version equal or later than : %s", ESP_WIFIMANAGER_VERSION_MIN_TARGET);
|
||||
}
|
||||
#endif
|
||||
|
||||
Serial.setDebugOutput(false);
|
||||
//Serial.setDebugOutput(false);
|
||||
|
||||
if (FORMAT_FILESYSTEM)
|
||||
FileFS.format();
|
||||
@@ -461,7 +428,7 @@ void setupwifiman()
|
||||
FileFS.format();
|
||||
#endif
|
||||
|
||||
Serial.println(F("SPIFFS/LittleFS failed! Already tried formatting."));
|
||||
log_w("SPIFFS/LittleFS failed! Already tried formatting.");
|
||||
|
||||
if (!FileFS.begin())
|
||||
{
|
||||
@@ -469,14 +436,15 @@ void setupwifiman()
|
||||
delay(100);
|
||||
|
||||
#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
|
||||
Serial.println(F("SPIFFS failed!. Please use LittleFS or EEPROM. Stay forever"));
|
||||
log_w("SPIFFS failed!. Please use SPIFFS or EEPROM. Stay forever");
|
||||
#endif
|
||||
|
||||
while (true)
|
||||
{
|
||||
delay(1);
|
||||
setLedRaw(true,false,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -529,7 +497,7 @@ void setupwifiman()
|
||||
Router_Pass = ESP_wifiManager.WiFi_Pass();
|
||||
|
||||
//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.toUpperCase();
|
||||
@@ -544,7 +512,7 @@ void setupwifiman()
|
||||
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.
|
||||
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())
|
||||
@@ -552,7 +520,7 @@ void setupwifiman()
|
||||
configDataLoaded = true;
|
||||
|
||||
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 ( strlen(WM_config.TZ_Name) > 0 )
|
||||
@@ -568,51 +536,42 @@ void setupwifiman()
|
||||
}
|
||||
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
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
if (drd->detectDoubleReset())
|
||||
{
|
||||
// DRD, disable timeout.
|
||||
ESP_wifiManager.setConfigPortalTimeout(0);
|
||||
// if (drd->detectDoubleReset())
|
||||
// {
|
||||
// // DRD, disable timeout.
|
||||
// ESP_wifiManager.setConfigPortalTimeout(0);
|
||||
|
||||
Serial.println(F("Open Config Portal without Timeout: Double Reset Detected"));
|
||||
initialConfig = true;
|
||||
}
|
||||
// log_w("Open Config Portal without Timeout: Double Reset Detected");
|
||||
// initialConfig = true;
|
||||
// }
|
||||
|
||||
if (initialConfig)
|
||||
{
|
||||
Serial.print(F("Starting configuration portal @ "));
|
||||
|
||||
#if USE_CUSTOM_AP_IP
|
||||
Serial.print(APStaticIP);
|
||||
log_i("%s",APStaticIP);
|
||||
#else
|
||||
Serial.print(F("192.168.4.1"));
|
||||
log_i("Starting configuration portal @ 192.168.4.1");
|
||||
#endif
|
||||
|
||||
#if defined(HTTP_PORT_TO_USE)
|
||||
Serial.print(F(":")); Serial.print(HTTP_PORT_TO_USE);
|
||||
log_i("portnr: %i", HTTP_PORT_TO_USE);
|
||||
#endif
|
||||
|
||||
Serial.print(F(", SSID = "));
|
||||
Serial.print(ssid);
|
||||
Serial.print(F(", PWD = "));
|
||||
Serial.println(password);
|
||||
log_i("SSID = %s, PWD = ", ssid, 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
|
||||
// New. Update Credentials, got from loadConfigData(), to display on CP
|
||||
@@ -622,10 +581,10 @@ void setupwifiman()
|
||||
|
||||
// Starts an access point
|
||||
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
|
||||
{
|
||||
Serial.println(F("WiFi connected...yeey :)"));
|
||||
log_i("WiFi connected...yeey :)");
|
||||
}
|
||||
|
||||
// Stored for later usage, from v1.1.0, but clear first
|
||||
@@ -693,7 +652,7 @@ void setupwifiman()
|
||||
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();
|
||||
|
||||
@@ -715,30 +674,27 @@ void setupwifiman()
|
||||
|
||||
if ( WiFi.status() != WL_CONNECTED )
|
||||
{
|
||||
Serial.println(F("ConnectMultiWiFi in setup"));
|
||||
log_i("ConnectMultiWiFi in setup");
|
||||
|
||||
connectMultiWiFi();
|
||||
}
|
||||
}
|
||||
|
||||
Serial.print(F("After waiting "));
|
||||
Serial.print((float) (millis() - startedAt) / 1000);
|
||||
Serial.print(F(" secs more in setup(), connection result is "));
|
||||
log_i("After waiting %0.2f secs more in setup(), connection result is ", ((float) (millis() - startedAt) / 1000));
|
||||
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
Serial.print(F("connected. Local IP: "));
|
||||
Serial.println(WiFi.localIP());
|
||||
log_i("connected. Local IP: %s", WiFi.localIP().toString().c_str());
|
||||
}
|
||||
else
|
||||
Serial.println(ESP_wifiManager.getStatus(WiFi.status()));
|
||||
log_w("wifistatus: %s", ESP_wifiManager.getStatus(WiFi.status()));
|
||||
|
||||
drdtimeout=millis();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loopwifiman()
|
||||
{
|
||||
// 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
|
||||
// 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
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "led.h"
|
||||
|
||||
void loopwifiman();
|
||||
void setupwifiman();
|
||||
|
||||
@@ -117,7 +118,7 @@ void setupwifiman();
|
||||
#endif
|
||||
//////
|
||||
|
||||
#define LED_BUILTIN 2
|
||||
//#define LED_BUILTIN 2
|
||||
#define LED_ON HIGH
|
||||
#define LED_OFF LOW
|
||||
|
||||
|
||||
Reference in New Issue
Block a user