mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
ESP Wifi auto-restore connect for wifi manager
FIX Ethernet for ESP
This commit is contained in:
@@ -722,6 +722,7 @@ void setupOTA(void)
|
|||||||
|
|
||||||
void onInitialStateInitLAN() {
|
void onInitialStateInitLAN() {
|
||||||
#if defined(WIFI_ENABLE)
|
#if defined(WIFI_ENABLE)
|
||||||
|
|
||||||
#if defined(WIFI_MANAGER_DISABLE)
|
#if defined(WIFI_MANAGER_DISABLE)
|
||||||
if(WiFi.status() != WL_CONNECTED) {
|
if(WiFi.status() != WL_CONNECTED) {
|
||||||
WiFi.mode(WIFI_STA); // ESP 32 - WiFi.disconnect(); instead
|
WiFi.mode(WIFI_STA); // ESP 32 - WiFi.disconnect(); instead
|
||||||
@@ -739,59 +740,29 @@ void onInitialStateInitLAN() {
|
|||||||
}
|
}
|
||||||
wifiInitialized = true; //???
|
wifiInitialized = true; //???
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
// Wifi Manager
|
|
||||||
if (WiFi.status() != WL_CONNECTED)
|
|
||||||
{
|
|
||||||
wifiManager.setTimeout(30);
|
|
||||||
#if defined(ESP_WIFI_AP) and defined(ESP_WIFI_PWD)
|
|
||||||
wifiInitialized = wifiManager.autoConnect(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
|
||||||
#else
|
|
||||||
wifiInitialized = wifiManager.autoConnect();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32) and defined(WIFI_MANAGER_DISABLE)
|
|
||||||
if(!wifiInitialized) {
|
|
||||||
// WiFi.mode(WIFI_STA);
|
|
||||||
WiFi.disconnect();
|
|
||||||
debugSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD)<<endl;
|
|
||||||
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
|
||||||
|
|
||||||
int wifi_connection_wait = 10000;
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
while (WiFi.status() != WL_CONNECTED && wifi_connection_wait > 0) {
|
|
||||||
delay(500);
|
|
||||||
wifi_connection_wait -= 500;
|
|
||||||
debugSerial<<".";
|
|
||||||
}
|
|
||||||
wifiInitialized = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(WIFI_ENABLE)
|
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
|
||||||
infoSerial<<F("WiFi connected. IP address: ")<<WiFi.localIP()<<endl;
|
infoSerial<<F("WiFi connected. IP address: ")<<WiFi.localIP()<<endl;
|
||||||
|
wifiInitialized = true;
|
||||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||||
setupOTA();
|
setupOTA();
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
errorSerial<<F("Problem with WiFi!");
|
errorSerial<<F("\nProblem with WiFi!");
|
||||||
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)||defined(ARDUINO_ARCH_STM32) || defined (NRF5)
|
#else // Ethernet connection
|
||||||
|
|
||||||
#ifdef W5500_CS_PIN
|
#ifdef W5500_CS_PIN
|
||||||
#ifndef Wiz5500
|
#ifndef Wiz5500
|
||||||
Ethernet.init(W5500_CS_PIN);
|
Ethernet.init(W5500_CS_PIN);
|
||||||
#else
|
#else
|
||||||
Ethernet.w5500_cspin = W5500_CS_PIN;
|
Ethernet.w5500_cspin = W5500_CS_PIN;
|
||||||
#endif
|
#endif
|
||||||
infoSerial<<F("Use W5500 pin: ");
|
infoSerial<<F("Use W5500 pin: ");
|
||||||
infoSerial<<QUOTE(W5500_CS_PIN)<<endl;
|
infoSerial<<QUOTE(W5500_CS_PIN)<<endl;
|
||||||
#endif
|
#endif
|
||||||
@@ -824,12 +795,12 @@ setupOTA();
|
|||||||
else {
|
else {
|
||||||
infoSerial<<"\nNo IP data found in flash\n";
|
infoSerial<<"\nNo IP data found in flash\n";
|
||||||
wdt_dis();
|
wdt_dis();
|
||||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined (NRF5)
|
|
||||||
res = Ethernet.begin(mac, 12000);
|
#if defined(ARDUINO_ARCH_STM32)
|
||||||
#endif
|
res = Ethernet.begin(mac);
|
||||||
#if defined(ARDUINO_ARCH_STM32)
|
#else
|
||||||
res = Ethernet.begin(mac);
|
res = Ethernet.begin(mac, 12000);
|
||||||
#endif
|
#endif
|
||||||
wdt_en();
|
wdt_en();
|
||||||
wdt_res();
|
wdt_res();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user