From 79a547d3e61dc8dbb290b66d9d47305827066e33 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Mon, 7 Jul 2025 12:33:27 -1000 Subject: [PATCH 1/9] HTTP_Client: Attempt to display the TLS error --- Firmware/RTK_Everywhere/HTTP_Client.ino | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Firmware/RTK_Everywhere/HTTP_Client.ino b/Firmware/RTK_Everywhere/HTTP_Client.ino index 55194e4d..7acb59f6 100644 --- a/Firmware/RTK_Everywhere/HTTP_Client.ino +++ b/Firmware/RTK_Everywhere/HTTP_Client.ino @@ -372,6 +372,17 @@ void httpClientUpdate() if (!httpSecureClient->connect(THINGSTREAM_SERVER, HTTPS_PORT)) { // Failed to connect to the server + int length = 1024; + char * errMessage = (char *)rtkMalloc(length, "HTTP error message"); + if (errMessage) + { + memset(errMessage, 0, length); + httpSecureClient->lastError(errMessage, length - 1); + systemPrintf("Get %s failed, %s\r\n", THINGSTREAM_SERVER, errMessage); + rtkFree(errMessage, "HTTP error message"); + } + else + systemPrintf("Get %s failed!\r\n", THINGSTREAM_SERVER); systemPrintln("ERROR: Failed to connect to the Thingstream server!"); httpClientRestart(); // I _think_ we want to restart here - i.e. retry after the timeout? break; From 46a752e78cfbf72cf40fbb86f0a9aca8a0b593c4 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Mon, 7 Jul 2025 12:33:47 -1000 Subject: [PATCH 2/9] MQTT_Client: Attempt to display the TLS error --- Firmware/RTK_Everywhere/MQTT_Client.ino | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Firmware/RTK_Everywhere/MQTT_Client.ino b/Firmware/RTK_Everywhere/MQTT_Client.ino index b5a6e905..879f53fb 100644 --- a/Firmware/RTK_Everywhere/MQTT_Client.ino +++ b/Firmware/RTK_Everywhere/MQTT_Client.ino @@ -952,6 +952,16 @@ void mqttClientUpdate() // Attempt connection to the MQTT broker if (!mqttClient->connect(settings.pointPerfectBrokerHost, 8883)) { + // Failed to connect to the server + int length = 1024; + char * errMessage = (char *)rtkMalloc(length, "HTTP error message"); + if (errMessage) + { + memset(errMessage, 0, length); + mqttSecureClient->lastError(errMessage, length - 1); + systemPrintf("MQTT Error: %s\r\n", errMessage); + rtkFree(errMessage, "HTTP error message"); + } systemPrintf("Failed to connect to MQTT broker %s\r\n", settings.pointPerfectBrokerHost); mqttClientRestart(); break; From 02ff4bdb4fc7ed92a49688f51ef1b241d49a5f98 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Mon, 7 Jul 2025 12:42:52 -1000 Subject: [PATCH 3/9] WiFi: Add channel get and set routines --- Firmware/RTK_Everywhere/Developer.ino | 2 +- Firmware/RTK_Everywhere/WiFi.ino | 76 ++++++++++++++++++++++++--- Firmware/RTK_Everywhere/menuMain.ino | 2 +- Firmware/RTK_Everywhere/settings.h | 33 ++++++++++-- 4 files changed, 100 insertions(+), 13 deletions(-) diff --git a/Firmware/RTK_Everywhere/Developer.ino b/Firmware/RTK_Everywhere/Developer.ino index 745d83b8..b9acb212 100644 --- a/Firmware/RTK_Everywhere/Developer.ino +++ b/Firmware/RTK_Everywhere/Developer.ino @@ -209,7 +209,7 @@ void wifiDisplayNetworkData() {} void wifiDisplaySoftApStatus() {} bool wifiEspNowOff(const char * fileName, uint32_t lineNumber) {return true;} bool wifiEspNowOn(const char * fileName, uint32_t lineNumber) {return false;} -void wifiEspNowSetChannel(WIFI_CHANNEL_t channel) {} +void wifiEspNowChannelSet(WIFI_CHANNEL_t channel) {} int wifiNetworkCount() {return 0;} void wifiResetTimeout() {} IPAddress wifiSoftApGetIpAddress() {return IPAddress((uint32_t)0);} diff --git a/Firmware/RTK_Everywhere/WiFi.ino b/Firmware/RTK_Everywhere/WiFi.ino index cd9713ea..5c0d8752 100644 --- a/Firmware/RTK_Everywhere/WiFi.ino +++ b/Firmware/RTK_Everywhere/WiFi.ino @@ -581,11 +581,18 @@ void wifiDisplayState() } } +//********************************************************************* +// Get the ESP-NOW channel +WIFI_CHANNEL_t wifiEspNowChannelGet() +{ + return wifi.espNowChannelGet(); +} + //********************************************************************* // Set the ESP-NOW channel -void wifiEspNowSetChannel(WIFI_CHANNEL_t channel) +void wifiEspNowChannelSet(WIFI_CHANNEL_t channel) { - wifi.espNowSetChannel(channel); + wifi.espNowChannelSet(channel); } //********************************************************************* @@ -684,6 +691,20 @@ void wifiPromiscuousRxHandler(void *buf, wifi_promiscuous_pkt_type_t type) packetRSSI = ppkt->rx_ctrl.rssi; } +//********************************************************************* +// Get the soft AP channel +WIFI_CHANNEL_t wifiSoftApChannelGet() +{ + return wifi.softApChannelGet(); +} + +//********************************************************************* +// Set the soft AP channel +void wifiSoftApChannelSet(WIFI_CHANNEL_t channel) +{ + wifi.softApChannelSet(channel); +} + //********************************************************************* // Get the IP address being used for the software access point (AP) // Outputs: @@ -1361,23 +1382,32 @@ bool RTK_WIFI::enable(bool enableESPNow, bool enableSoftAP, bool enableStation, } //********************************************************************* -// Get the ESP-NOW status +// Get the ESP-NOW channel // Outputs: -// Returns true when ESP-NOW is online and ready for use -bool RTK_WIFI::espNowOnline() +// Returns the requested ESP-NOW channel +WIFI_CHANNEL_t RTK_WIFI::espNowChannelGet() { - return (_started & WIFI_EN_ESP_NOW_ONLINE) ? true : false; + return _espNowChannel; } //********************************************************************* // Set the ESP-NOW channel // Inputs: // channel: New ESP-NOW channel number -void RTK_WIFI::espNowSetChannel(WIFI_CHANNEL_t channel) +void RTK_WIFI::espNowChannelSet(WIFI_CHANNEL_t channel) { _espNowChannel = channel; } +//********************************************************************* +// Get the ESP-NOW status +// Outputs: +// Returns true when ESP-NOW is online and ready for use +bool RTK_WIFI::espNowOnline() +{ + return (_started & WIFI_EN_ESP_NOW_ONLINE) ? true : false; +} + //********************************************************************* // Handle the WiFi event void RTK_WIFI::eventHandler(arduino_event_id_t event, arduino_event_info_t info) @@ -1609,6 +1639,24 @@ bool RTK_WIFI::setWiFiProtocols(wifi_interface_t interface, bool enableWiFiProto return started; } +//********************************************************************* +// Get the soft AP channel +// Outputs: +// Returns the requested soft AP channel +WIFI_CHANNEL_t RTK_WIFI::softApChannelGet() +{ + return _apChannel; +} + +//********************************************************************* +// Set the soft AP channel +// Inputs: +// channel: Request the channel for WiFi soft AP +void RTK_WIFI::softApChannelSet(WIFI_CHANNEL_t channel) +{ + _apChannel = channel; +} + //********************************************************************* // Configure the soft AP // Inputs: @@ -1856,6 +1904,20 @@ bool RTK_WIFI::startAp(bool forceAP) return enable(wifiEspNowRunning, forceAP | settings.wifiConfigOverAP, wifiStationRunning, __FILE__, __LINE__); } +//********************************************************************* +// Get the station channel +WIFI_CHANNEL_t RTK_WIFI::stationChannelGet() +{ + return _stationChannel; +} + +//********************************************************************* +// Set the station channel +void RTK_WIFI::stationChannelSet(WIFI_CHANNEL_t channel) +{ + _stationChannel = channel; +} + //********************************************************************* // Connect the station to a remote AP // Return true if the connection was successful and false upon failure. diff --git a/Firmware/RTK_Everywhere/menuMain.ino b/Firmware/RTK_Everywhere/menuMain.ino index e6174f9d..1a93a755 100644 --- a/Firmware/RTK_Everywhere/menuMain.ino +++ b/Firmware/RTK_Everywhere/menuMain.ino @@ -706,7 +706,7 @@ void menuRadio() if (getNewSetting("Enter the WiFi channel to use for ESP-NOW communication", 1, 14, &settings.wifiChannel) == INPUT_RESPONSE_VALID) { - wifiEspNowSetChannel(settings.wifiChannel); + wifiEspNowChannelSet(settings.wifiChannel); if (settings.wifiChannel) { if (settings.wifiChannel == wifiChannel) diff --git a/Firmware/RTK_Everywhere/settings.h b/Firmware/RTK_Everywhere/settings.h index 15dc57e6..bd74490e 100644 --- a/Firmware/RTK_Everywhere/settings.h +++ b/Firmware/RTK_Everywhere/settings.h @@ -2194,15 +2194,20 @@ class RTK_WIFI const char * fileName, int lineNumber); - // Get the ESP-NOW status + // Get the ESP-NOW channel // Outputs: - // Returns true when ESP-NOW is online and ready for use - bool espNowOnline(); + // Returns the requested ESP-NOW channel + WIFI_CHANNEL_t espNowChannelGet(); // Set the ESP-NOW channel // Inputs: // channel: New ESP-NOW channel number - void espNowSetChannel(WIFI_CHANNEL_t channel); + void espNowChannelSet(WIFI_CHANNEL_t channel); + + // Get the ESP-NOW status + // Outputs: + // Returns true when ESP-NOW is online and ready for use + bool espNowOnline(); // Handle the WiFi event // Inputs: @@ -2217,6 +2222,16 @@ class RTK_WIFI // Returns the current WiFi channel number WIFI_CHANNEL_t getChannel(); + // Get the soft AP channel + // Outputs: + // Returns the requested soft AP channel + WIFI_CHANNEL_t softApChannelGet(); + + // Set the soft AP channel + // Inputs: + // channel: Request the channel for WiFi soft AP + void softApChannelSet(WIFI_CHANNEL_t channel); + // Configure the soft AP // Inputs: // ipAddress: IP address of the soft AP @@ -2255,6 +2270,16 @@ class RTK_WIFI // otherwise bool startAp(bool forceAP); + // Get the station channel + // Outputs: + // Returns the requested station channel + WIFI_CHANNEL_t stationChannelGet(); + + // Set the station channel + // Inputs: + // channel: Request the channel for WiFi station + void stationChannelSet(WIFI_CHANNEL_t channel); + // Get the WiFi station IP address // Returns the IP address of the WiFi station IPAddress stationIpAddress(); From 4a20ea389ca21c1be0f7bd154d684442b20ceea8 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Tue, 8 Jul 2025 07:19:39 -1000 Subject: [PATCH 4/9] WiFi: Fix wifiStationEnabled reasons --- Firmware/RTK_Everywhere/WiFi.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Firmware/RTK_Everywhere/WiFi.ino b/Firmware/RTK_Everywhere/WiFi.ino index 5c0d8752..3fcdcfff 100644 --- a/Firmware/RTK_Everywhere/WiFi.ino +++ b/Firmware/RTK_Everywhere/WiFi.ino @@ -811,6 +811,7 @@ bool wifiStationEnabled(const char **reason) // Is WiFi the highest priority if (networkIsHighestPriority(NETWORK_WIFI_STATION) == false) { + // Another network has higher priority // Allocate the reason buffer once if (reasonBuffer == nullptr) reasonBuffer = (char *)rtkMalloc(64, "WiFi reasonBuffer"); @@ -830,7 +831,7 @@ bool wifiStationEnabled(const char **reason) // WiFi should start and continue running enabled = true; - *reason = ", is enabled"; + *reason = ""; } while (0); return enabled; } From 0edda4643f32fb936643e68c25d9019d7096b0e8 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Mon, 7 Jul 2025 06:58:43 -1000 Subject: [PATCH 5/9] WiFi: Fix WiFi startup Remove the chicken and egg issue where WiFi needs to be running to be the highest priority, but has not started yet because it is not enabled! The new routine, networkInterfaceRunning, allows any interface to poll the network and determine if the interface should be running. This routine provides the missing feedback between the network and the interface layers to when the network layer wants to stop the interface and a stop sequence does not exist. --- Firmware/RTK_Everywhere/WiFi.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/RTK_Everywhere/WiFi.ino b/Firmware/RTK_Everywhere/WiFi.ino index 3fcdcfff..79f615ba 100644 --- a/Firmware/RTK_Everywhere/WiFi.ino +++ b/Firmware/RTK_Everywhere/WiFi.ino @@ -808,8 +808,8 @@ bool wifiStationEnabled(const char **reason) break; } - // Is WiFi the highest priority - if (networkIsHighestPriority(NETWORK_WIFI_STATION) == false) + // Determine if WiFi should be running (is the highest priority) + if (networkInterfaceRunning(NETWORK_WIFI_STATION) == false) { // Another network has higher priority // Allocate the reason buffer once From ad547c29557b7e92066f3ca37938b99a5b5f38e7 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Mon, 7 Jul 2025 07:22:38 -1000 Subject: [PATCH 6/9] WiFi: Add WiFi station state diagram --- Firmware/RTK_Everywhere/WiFi.ino | 70 +++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/Firmware/RTK_Everywhere/WiFi.ino b/Firmware/RTK_Everywhere/WiFi.ino index 79f615ba..83fad1b0 100644 --- a/Firmware/RTK_Everywhere/WiFi.ino +++ b/Firmware/RTK_Everywhere/WiFi.ino @@ -927,7 +927,75 @@ void wifiStationUpdate() static uint32_t timer; int users; - // Determine if WiFi station should stop +/* + WiFi Station States: + + WIFI_STATION_STATE_OFF <--------------+<---. + | ^ | + | enabled | | + | | | + V !enabled | | + WIFI_STATION_STATE_RESTART_DELAY ----------' | + | | + | Timeout | + | Complete | + V !enabled | + .----> WIFI_STATION_STATE_STARTING -------------. | + | | | | + | | WiFi connected | | + | V !enabled | | + | WIFI_STATION_STATE_ONLINE ------------->+ | + | | ^ | + | | Long delay | | + | V | | + | WIFI_STATION_STATE_STABLE | | + | | | | + | | !enabled | | + | V | | + | +<--------------------------' | + | | | + | V | + | WIFI_STATION_STATE_WAIT_NO_USERS | + | | | + | | No Users | + | V !enabled | + | +--------------------------------' + | Display | + | delay | enabled + | V + '------ WIFI_STATION_STATE_RESTART + + Network Loss Handling: + + ARDUINO_EVENT_WIFI_STA_LOST_IP + | + | + V + networkInterfaceEventInternetLost + | + | Set internet lost event flag + V + networkUpdate + | + | Clear internet lost event flag + V + +<------- Fake connection loss + | + V + networkInterfaceInternetConnectionLost + | + | Notify Interface of connection loss + V + .----------------+----------------. + | | + | | + V V + networkInterfaceRunning Interface stop sequence + in wifiStationEnabled + +*/ + + // Determine if WiFi station should start or stop enabled = wifiStationEnabled(&reason); online = wifiStationOnline; if ((enabled == false) && (wifiStationState >= WIFI_STATION_STATE_STARTING)) From f2ffaceeb68d25748d5e55dd44145a4492641ebf Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Sun, 6 Jul 2025 10:49:14 -1000 Subject: [PATCH 7/9] WiFi: Rename WIFI_STATION_STATE_RESTART to WIFI_STATION_STATE_RESTART_DELAY Move startup delay from WIFI_STATION_STATE_STARTING into WIFI_STATION_STATE_RESTART_DELAY --- Firmware/RTK_Everywhere/WiFi.ino | 154 +++++++++++++++++-------------- 1 file changed, 84 insertions(+), 70 deletions(-) diff --git a/Firmware/RTK_Everywhere/WiFi.ino b/Firmware/RTK_Everywhere/WiFi.ino index 83fad1b0..13a3acdc 100644 --- a/Firmware/RTK_Everywhere/WiFi.ino +++ b/Firmware/RTK_Everywhere/WiFi.ino @@ -42,7 +42,7 @@ enum WIFI_STATION_STATES { WIFI_STATION_STATE_OFF, WIFI_STATION_STATE_WAIT_NO_USERS, - WIFI_STATION_STATE_RESTART, + WIFI_STATION_STATE_RESTART_DELAY, WIFI_STATION_STATE_STARTING, WIFI_STATION_STATE_ONLINE, WIFI_STATION_STATE_STABLE, @@ -51,9 +51,14 @@ enum WIFI_STATION_STATES }; uint8_t wifiStationState; -const char *wifiStationStateName[] = { - "WIFI_STATION_STATE_OFF", "WIFI_STATION_STATE_WAIT_NO_USERS", "WIFI_STATION_STATE_RESTART", - "WIFI_STATION_STATE_STARTING", "WIFI_STATION_STATE_ONLINE", "WIFI_STATION_STATE_STABLE", +const char * wifiStationStateName[] = +{ + "WIFI_STATION_STATE_OFF", + "WIFI_STATION_STATE_WAIT_NO_USERS", + "WIFI_STATION_STATE_RESTART_DELAY", + "WIFI_STATION_STATE_STARTING", + "WIFI_STATION_STATE_ONLINE", + "WIFI_STATION_STATE_STABLE", }; const int wifiStationStateNameEntries = sizeof(wifiStationStateName) / sizeof(wifiStationStateName[0]); @@ -935,12 +940,12 @@ void wifiStationUpdate() | enabled | | | | | V !enabled | | - WIFI_STATION_STATE_RESTART_DELAY ----------' | - | | - | Timeout | - | Complete | - V !enabled | - .----> WIFI_STATION_STATE_STARTING -------------. | + .--> WIFI_STATION_STATE_RESTART_DELAY ----------' | + | | | + | | Timeout | + | | Complete | + | V !enabled | + | WIFI_STATION_STATE_STARTING -------------. | | | | | | | WiFi connected | | | V !enabled | | @@ -952,18 +957,14 @@ void wifiStationUpdate() | | | | | | !enabled | | | V | | - | +<--------------------------' | - | | | + | Display +<--------------------------' | + | delay | | | V | | WIFI_STATION_STATE_WAIT_NO_USERS | | | | | | No Users | - | V !enabled | - | +--------------------------------' - | Display | - | delay | enabled - | V - '------ WIFI_STATION_STATE_RESTART + | enabled V !enabled | + '-------------------+--------------------------------' Network Loss Handling: @@ -1032,13 +1033,8 @@ void wifiStationUpdate() timer = millis(); startTimeout = 0; - // Display the major state transition - if (settings.debugWifiState) - systemPrintf("--------------- %s Starting ---------------\r\n", - networkInterfaceTable[NETWORK_WIFI_STATION].name); - // Start WiFi station - wifiStationSetState(WIFI_STATION_STATE_STARTING); + wifiStationSetState(WIFI_STATION_STATE_RESTART_DELAY); } break; @@ -1075,6 +1071,8 @@ void wifiStationUpdate() networkInterfaceTable[NETWORK_WIFI_STATION].name); wifiStationOff(__FILE__, __LINE__); } + + // Reset the start timeout wifiStationSetState(WIFI_STATION_STATE_OFF); } @@ -1083,67 +1081,83 @@ void wifiStationUpdate() { // Clear the bits to perform the restart operation wifi.clearStarted(WIFI_STA_RECONNECT); - wifiStationSetState(WIFI_STATION_STATE_RESTART); + + // Display the restart delay and then start WiFi station + if (startTimeout && settings.debugWifiState) + { + // Display the delay + uint32_t seconds = startTimeout / MILLISECONDS_IN_A_SECOND; + uint32_t minutes = seconds / SECONDS_IN_A_MINUTE; + seconds -= minutes * SECONDS_IN_A_MINUTE; + systemPrintf("WiFi: Delaying %2d:%02d before restarting WiFi\r\n", minutes, seconds); + } + timer = millis(); + wifiStationSetState(WIFI_STATION_STATE_RESTART_DELAY); } } break; - // Display the restart delay and then start WiFi station - case WIFI_STATION_STATE_RESTART: - if (startTimeout && settings.debugWifiState) + // Perform the restart delay + case WIFI_STATION_STATE_RESTART_DELAY: + // Stop WiFi station if necessary + if (enabled == false) { - // Display the delay - uint32_t seconds = startTimeout / MILLISECONDS_IN_A_SECOND; - uint32_t minutes = seconds / SECONDS_IN_A_MINUTE; - seconds -= minutes * SECONDS_IN_A_MINUTE; - systemPrintf("WiFi: Delaying %2d:%02d before restarting WiFi\r\n", minutes, seconds); + wifiStationSetState(WIFI_STATION_STATE_OFF); + break; } - timer = millis(); + + // Delay before starting WiFi + if ((millis() - timer) < startTimeout) + break; + + // Display the major state transition + if (settings.debugWifiState) + systemPrintf("--------------- %s Starting ---------------\r\n", + networkInterfaceTable[NETWORK_WIFI_STATION].name); + + // Timeout complete wifiStationSetState(WIFI_STATION_STATE_STARTING); - break; + + // | + // | Fall through + // V // At least one consumer is requesting a network case WIFI_STATION_STATE_STARTING: - // Delay before starting WiFi - if ((millis() - timer) >= startTimeout) - { - timer = millis(); - - // Increase the timeout - startTimeout <<= 1; - if (!startTimeout) - startTimeout = WIFI_MIN_TIMEOUT; - else if (startTimeout > WIFI_MAX_TIMEOUT) - startTimeout = WIFI_MAX_TIMEOUT; + // Increase the timeout + startTimeout <<= 1; + if (!startTimeout) + startTimeout = WIFI_MIN_TIMEOUT; + else if (startTimeout > WIFI_MAX_TIMEOUT) + startTimeout = WIFI_MAX_TIMEOUT; - // Account for this connection attempt - connectionAttempts++; + // Account for this connection attempt + connectionAttempts++; - // Attempt to start WiFi station - if (wifiStationOn(__FILE__, __LINE__)) - { - // Successfully connected to a remote AP - if (settings.debugWifiState) - systemPrintf("WiFi: WiFi station successfully started\r\n"); + // Attempt to start WiFi station + if (wifiStationOn(__FILE__, __LINE__) == false) + { + // Failed to connect to a remote AP + if (settings.debugWifiState) + systemPrintf("WiFi: WiFi station failed to start!\r\n"); - // WiFi station is now available - wifiStationSetState(WIFI_STATION_STATE_ONLINE); - } - else - { - // Failed to connect to a remote AP - if (settings.debugWifiState) - systemPrintf("WiFi: WiFi station failed to start!\r\n"); + // Start the next network interface if necessary + if (connectionAttempts >= 2) + networkStartNextInterface(NETWORK_WIFI_STATION); - // Restart WiFi after delay - // Clear the bits to perform the restart operation - wifi.clearStarted(WIFI_STA_RECONNECT); - wifiStationSetState(WIFI_STATION_STATE_RESTART); + // Perform the restart delay + timer = millis(); + wifiStationSetState(WIFI_STATION_STATE_RESTART_DELAY); + } + else + { + // Successfully connected to a remote AP + if (settings.debugWifiState) + systemPrintf("WiFi: WiFi station successfully started\r\n"); - // Start the next network interface if necessary - if (connectionAttempts >= 2) - networkStartNextInterface(NETWORK_WIFI_STATION); - } + // WiFi station is now available + timer = millis(); + wifiStationSetState(WIFI_STATION_STATE_ONLINE); } break; From d62ed2b48db7a48e401e4027f62d2942d5a1f774 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Tue, 8 Jul 2025 07:40:18 -1000 Subject: [PATCH 8/9] WiFi: Move WIFI_STATION_STATE_OFF state --- Firmware/RTK_Everywhere/WiFi.ino | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Firmware/RTK_Everywhere/WiFi.ino b/Firmware/RTK_Everywhere/WiFi.ino index 13a3acdc..f6646b54 100644 --- a/Firmware/RTK_Everywhere/WiFi.ino +++ b/Firmware/RTK_Everywhere/WiFi.ino @@ -1025,19 +1025,6 @@ void wifiStationUpdate() // Update the WiFi station state switch (wifiStationState) { - // There are no WiFi station consumers - case WIFI_STATION_STATE_OFF: - if (enabled) - { - connectionAttempts = 0; - timer = millis(); - startTimeout = 0; - - // Start WiFi station - wifiStationSetState(WIFI_STATION_STATE_RESTART_DELAY); - } - break; - // Wait for WiFi station users to release resources before shutting // down WiFi station case WIFI_STATION_STATE_WAIT_NO_USERS: @@ -1097,6 +1084,27 @@ void wifiStationUpdate() } break; + // There are no WiFi station consumers + case WIFI_STATION_STATE_OFF: + // Check for disabled + if (!enabled) + break; + + // Reset the restart timeout when off + if (wifiStationState == WIFI_STATION_STATE_OFF) + { + connectionAttempts = 0; + timer = millis(); + startTimeout = 0; + } + + // Wait for the delay to complete + wifiStationSetState(WIFI_STATION_STATE_RESTART_DELAY); + + // | + // | Fall through + // V + // Perform the restart delay case WIFI_STATION_STATE_RESTART_DELAY: // Stop WiFi station if necessary From bd8b15ffea9469bf2f386ff5637ea978bebf90a6 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Tue, 8 Jul 2025 07:57:10 -1000 Subject: [PATCH 9/9] WiFi: Always stop WiFi station in WIFI_STATION_STATE_WAIT_NO_USERS --- Firmware/RTK_Everywhere/WiFi.ino | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Firmware/RTK_Everywhere/WiFi.ino b/Firmware/RTK_Everywhere/WiFi.ino index f6646b54..163a4b6f 100644 --- a/Firmware/RTK_Everywhere/WiFi.ino +++ b/Firmware/RTK_Everywhere/WiFi.ino @@ -1047,28 +1047,23 @@ void wifiStationUpdate() // No more network users else { - // Stop WiFi station if necessary - if (enabled == false) + // Display the major state transition + if (wifiStationRunning) { - // Display the major state transition - if (wifiStationRunning) - { - if (settings.debugWifiState) - systemPrintf("--------------- %s Stopping ---------------\r\n", - networkInterfaceTable[NETWORK_WIFI_STATION].name); - wifiStationOff(__FILE__, __LINE__); - } + if (settings.debugWifiState) + systemPrintf("--------------- %s Stopping ---------------\r\n", + networkInterfaceTable[NETWORK_WIFI_STATION].name); + wifiStationOff(__FILE__, __LINE__); + } + // Stop WiFi station if necessary + if (enabled == false) // Reset the start timeout wifiStationSetState(WIFI_STATION_STATE_OFF); - } // Restart WiFi after delay else { - // Clear the bits to perform the restart operation - wifi.clearStarted(WIFI_STA_RECONNECT); - // Display the restart delay and then start WiFi station if (startTimeout && settings.debugWifiState) { @@ -1174,6 +1169,7 @@ void wifiStationUpdate() // Wait until the WiFi link is stable if ((millis() - timer) >= WIFI_CONNECTION_STABLE_MSEC) { + // Reset restart timeout and the connection attempts connectionAttempts = 0; startTimeout = 0; wifiStationSetState(WIFI_STATION_STATE_STABLE);