WiFi reconnect improvement

This commit is contained in:
Djuri Baars 2023-11-20 18:59:33 +01:00
parent 43b0e9718d
commit efed8bee5c
5 changed files with 29 additions and 15 deletions

2
data

@ -1 +1 @@
Subproject commit 3eaf897dbb6d1597ec71b4323ae0d68a02dee9c9
Subproject commit d25284e3a47a9efe6c0a8877e8abeac098ced8af

View file

@ -49,7 +49,7 @@ void setup()
void tryImprovSetup()
{
//WiFi.onEvent(WiFiEvent);
WiFi.onEvent(WiFiEvent);
if (!preferences.getBool("wifiConfigured", false))
{
@ -228,7 +228,8 @@ void setupHardware()
{
Serial.println(F("An Error has occurred while mounting LittleFS"));
}
if(!LittleFS.open("/index.html", "r")) {
if(!LittleFS.open("/index.html.gz", "r")) {
Serial.println("Error loading WebUI");
}
@ -474,8 +475,10 @@ void improv_set_error(improv::Error error)
Serial.write(data.data(), data.size());
}
void WiFiEvent(WiFiEvent_t event)
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info)
{
static bool first_connect = true;
Serial.printf("[WiFi-event] event: %d\n", event);
switch (event)
@ -496,19 +499,32 @@ void WiFiEvent(WiFiEvent_t event)
Serial.println("Connected to access point");
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
Serial.println("Disconnected from WiFi access point");
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
break;
{
if (!first_connect) {
Serial.println("Disconnected from WiFi access point");
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
uint8_t reason = info.wifi_sta_disconnected.reason;
if(reason)
Serial.printf("Disconnect reason: %s, ", WiFi.disconnectReasonName((wifi_err_reason_t)reason));
}
break;
}
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
Serial.println("Authentication mode of access point has changed");
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
{
Serial.print("Obtained IP address: ");
Serial.println(WiFi.localIP());
if (!first_connect)
queueLedEffect(LED_EFFECT_WIFI_CONNECT_SUCCESS);
first_connect = false;
break;
}
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
Serial.println("Lost IP address and IP address is reset to 0");
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
WiFi.reconnect();
break;
case ARDUINO_EVENT_WIFI_AP_START:
Serial.println("WiFi access point started");

View file

@ -22,7 +22,6 @@
#include "lib/button_handler.hpp"
#include "lib/led_handler.hpp"
#define NTP_SERVER "pool.ntp.org"
#define DEFAULT_MEMPOOL_INSTANCE "mempool.space"
#define TIME_OFFSET_SECONDS 3600
@ -34,11 +33,6 @@
#define DEFAULT_FG_COLOR GxEPD_WHITE
#define DEFAULT_BG_COLOR GxEPD_BLACK
#define BITCOIND_HOST ""
#define BITCOIND_PORT 8332
#define BITCOIND_RPC_USER ""
#define BITCOIND_RPC_PASS ""
void setup();
void setupTime();
void setupPreferences();
@ -58,4 +52,4 @@ void improv_set_state(improv::State state);
void improv_send_response(std::vector<uint8_t> &response);
void improv_set_error(improv::Error error);
void WiFiEvent(WiFiEvent_t event);
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);

View file

@ -28,7 +28,7 @@ void ledTask(void *parameter)
pixels.clear();
break;
case LED_EFFECT_WIFI_CONNECT_ERROR:
blinkDelayTwoColor(100, 1, pixels.Color(8, 161, 236), pixels.Color(255, 0, 0));
blinkDelayTwoColor(100, 3, pixels.Color(8, 161, 236), pixels.Color(255, 0, 0));
break;
case LED_FLASH_ERROR:
blinkDelayColor(250, 3, 255, 0, 0);

View file

@ -26,6 +26,10 @@ extern "C" void app_main()
if (eventSourceTaskHandle != NULL)
xTaskNotifyGive(eventSourceTaskHandle);
if (!WiFi.isConnected()) {
WiFi.begin();
}
vTaskDelay(pdMS_TO_TICKS(5000));
}
}