From 3f3af969375e5fb9079ba74f8ac8dc826f93403d Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Tue, 20 Jun 2023 11:28:22 -1000 Subject: [PATCH 1/5] NTRIP Server: Fix WiFi retry cases * Start ntripServerTimer when starting the network * Restart after 1 minute if network does not start * Reorder authorization failover cases to ensure that all are covered --- Firmware/RTK_Surveyor/NtripServer.ino | 88 ++++++++++++++------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/Firmware/RTK_Surveyor/NtripServer.ino b/Firmware/RTK_Surveyor/NtripServer.ino index 094a75621..359690ba0 100644 --- a/Firmware/RTK_Surveyor/NtripServer.ino +++ b/Firmware/RTK_Surveyor/NtripServer.ino @@ -415,6 +415,7 @@ void ntripServerUpdate() ntripServerLastConnectionAttempt = millis(); log_d("NTRIP Server starting WiFi"); wifiStart(); + ntripServerTimer = millis(); ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_STARTED); } } @@ -423,32 +424,18 @@ void ntripServerUpdate() // Wait for connection to an access point case NTRIP_SERVER_WIFI_ETHERNET_STARTED: - if (HAS_ETHERNET) // && !settings.ntripServerUseWiFiNotEthernet) //For future expansion + if ((millis() - ntripServerTimer) > (1 * 60 * 1000)) + // Failed to connect to to the network, attempt to restart the network + ntripServerStop(false); + else if (HAS_ETHERNET) // && !settings.ntripServerUseWiFiNotEthernet) //For future expansion { if (online.ethernetStatus == ETH_CONNECTED) ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_CONNECTED); - else if (online.ethernetStatus == ETH_CAN_NOT_BEGIN) // Ethernet hardware failure or not available - ntripServerSetState(NTRIP_SERVER_OFF); - else - { - // Wait for ethernet to connect - static unsigned long lastDebug = millis(); - if (millis() > (lastDebug + 5000)) - { - lastDebug = millis(); - log_d("NTRIP Server: Ethernet not connected. Waiting to retry."); - } - } } else { if (wifiIsConnected()) ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_CONNECTED); - else if (wifiState == WIFI_OFF) - { - // WiFi failed to connect. Restart Client which will restart WiFi. - ntripServerSetState(NTRIP_SERVER_ON); - } } break; @@ -528,48 +515,67 @@ void ntripServerUpdate() ntripServerResponse(response, sizeof(response)); // Look for various responses - if (strstr(response, "401") != nullptr) + if (strstr(response, "200") != nullptr) //'200' found + { + systemPrintf("NTRIP Server connected to %s:%d %s\r\n", settings.ntripServer_CasterHost, + settings.ntripServer_CasterPort, settings.ntripServer_MountPoint); + + // Connection is now open, start the RTCM correction data timer + ntripServerTimer = millis(); + + // We don't use a task because we use I2C hardware (and don't have a semphore). + online.ntripServer = true; + ntripServerConnectionAttempts = 0; + ntripServerSetState(NTRIP_SERVER_CASTING); + } + + // Look for '401 Unauthorized' + else if (strstr(response, "401") != nullptr) { - // Look for '401 Unauthorized' systemPrintf( "NTRIP Caster responded with bad news: %s. Are you sure your caster credentials are correct?\r\n", response); - // Give up - Stop WiFi operations - ntripServerStop(true); // Do not allocate new wifiClient + // Give up - Shutdown NTRIP server, no further retries + ntripServerStop(true); } + + // Look for banned IP information else if (strstr(response, "banned") != nullptr) //'Banned' found { - // Look for 'HTTP/1.1 200 OK' and banned IP information systemPrintf("NTRIP Server connected to caster but caster responded with problem: %s", response); - // Give up - Stop WiFi operations - ntripServerStop(true); // Do not allocate new wifiClient + // Give up - Shutdown NTRIP server, no further retries + ntripServerStop(true); } - else if (strstr(response, "200") == nullptr) //'200' not found + + // Other errors returned by the caster + else { - // Look for 'ERROR - Mountpoint taken' from Emlid. systemPrintf("NTRIP Server connected but caster responded with problem: %s", response); - // Attempt to reconnect after throttle controlled timeout + // Check for connection limit if (ntripServerConnectLimitReached()) { - systemPrintln("Caster failed to respond. Do you have your caster address and port correct?"); - } - } - else if (strstr(response, "200") != nullptr) //'200' found + systemPrintln("NTRIP Server retry limit reached; do you have your caster address and port correct?"); - { - systemPrintf("NTRIP Server connected to %s:%d %s\r\n", settings.ntripServer_CasterHost, - settings.ntripServer_CasterPort, settings.ntripServer_MountPoint); + // Give up - Shutdown NTRIP server, no further retries + ntripServerStop(true); + } - // Connection is now open, start the RTCM correction data timer - ntripServerTimer = millis(); + // Attempt to reconnect after throttle controlled timeout + else + { + if (ntripServerConnectionAttemptTimeout / 1000 < 120) + systemPrintf("NTRIP Server attempting connection in %d seconds.\r\n", + ntripServerConnectionAttemptTimeout / 1000); + else + systemPrintf("NTRIP Server attempting connection in %d minutes.\r\n", + ntripServerConnectionAttemptTimeout / 1000 / 60); - // We don't use a task because we use I2C hardware (and don't have a semphore). - online.ntripServer = true; - ntripServerConnectionAttempts = 0; - ntripServerSetState(NTRIP_SERVER_CASTING); + // Restart network operation after delay + ntripServerStop(false); + } } } #endif // COMPILE_WIFI || COMPILE_ETHERNET From f5207556bcb2cb16c28b9836d4101e6f02e86368 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 23 Jun 2023 14:26:43 +0100 Subject: [PATCH 2/5] Update ntripServerTimer - when using Ethernet --- Firmware/RTK_Surveyor/NtripServer.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Firmware/RTK_Surveyor/NtripServer.ino b/Firmware/RTK_Surveyor/NtripServer.ino index 359690ba0..a9e391dd0 100644 --- a/Firmware/RTK_Surveyor/NtripServer.ino +++ b/Firmware/RTK_Surveyor/NtripServer.ino @@ -249,7 +249,7 @@ void ntripServerProcessRTCM(uint8_t incoming) } // If we have not gotten new RTCM bytes for a period of time, assume end of frame - if (millis() - ntripServerTimer > 100 && ntripServerBytesSent > 0) + if (((millis() - ntripServerTimer) > 100) && (ntripServerBytesSent > 0)) { if ((!inMainMenu) && settings.enablePrintNtripServerState) systemPrintf("NTRIP Server transmitted %d RTCM bytes to Caster\r\n", ntripServerBytesSent); @@ -391,6 +391,7 @@ void ntripServerUpdate() { ntripServerLastConnectionAttempt = millis(); log_d("NTRIP Server starting on Ethernet"); + ntripServerTimer = millis(); ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_STARTED); } } @@ -543,7 +544,7 @@ void ntripServerUpdate() // Look for banned IP information else if (strstr(response, "banned") != nullptr) //'Banned' found { - systemPrintf("NTRIP Server connected to caster but caster responded with problem: %s", response); + systemPrintf("NTRIP Server connected to caster but caster responded with problem: %s\r\n", response); // Give up - Shutdown NTRIP server, no further retries ntripServerStop(true); @@ -552,7 +553,7 @@ void ntripServerUpdate() // Other errors returned by the caster else { - systemPrintf("NTRIP Server connected but caster responded with problem: %s", response); + systemPrintf("NTRIP Server connected but caster responded with problem: %s\r\n", response); // Check for connection limit if (ntripServerConnectLimitReached()) From a3d1632df9bdefab851d2f090d1424be1a445031 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 23 Jun 2023 15:54:00 +0100 Subject: [PATCH 3/5] Add missing ntripServerStop's for NTRIP_SERVER_AUTHORIZATION --- Firmware/RTK_Surveyor/NtripServer.ino | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Firmware/RTK_Surveyor/NtripServer.ino b/Firmware/RTK_Surveyor/NtripServer.ino index a9e391dd0..b0c6a1843 100644 --- a/Firmware/RTK_Surveyor/NtripServer.ino +++ b/Firmware/RTK_Surveyor/NtripServer.ino @@ -497,6 +497,9 @@ void ntripServerUpdate() if (ntripServerConnectLimitReached()) { systemPrintln("Caster failed to respond. Do you have your caster address and port correct?"); + + // Give up - Shutdown NTRIP server, no further retries + ntripServerStop(true); } else { @@ -506,6 +509,9 @@ void ntripServerUpdate() else systemPrintf("NTRIP caster failed to respond. Trying again in %d minutes.\r\n", ntripServerConnectionAttemptTimeout / 1000 / 60); + + // Restart network operation after delay + ntripServerStop(false); } } } From f9c79f4e9d0d6a612d1ab82c8f04fe328cce32cf Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 23 Jun 2023 15:56:11 +0100 Subject: [PATCH 4/5] Update ntripClientUpdate to match ntripServerUpdate --- Firmware/RTK_Surveyor/NtripClient.ino | 110 ++++++++++++++++---------- 1 file changed, 67 insertions(+), 43 deletions(-) diff --git a/Firmware/RTK_Surveyor/NtripClient.ino b/Firmware/RTK_Surveyor/NtripClient.ino index 6a674bdd0..c7c1ec002 100644 --- a/Firmware/RTK_Surveyor/NtripClient.ino +++ b/Firmware/RTK_Surveyor/NtripClient.ino @@ -392,6 +392,7 @@ void ntripClientUpdate() { ntripClientLastConnectionAttempt = millis(); log_d("NTRIP Client starting on Ethernet"); + ntripClientTimer = millis(); ntripClientSetState(NTRIP_CLIENT_WIFI_ETHERNET_STARTED); } } @@ -416,6 +417,7 @@ void ntripClientUpdate() ntripClientLastConnectionAttempt = millis(); log_d("NTRIP Client starting WiFi"); wifiStart(); + ntripClientTimer = millis(); ntripClientSetState(NTRIP_CLIENT_WIFI_ETHERNET_STARTED); } } @@ -424,32 +426,18 @@ void ntripClientUpdate() break; case NTRIP_CLIENT_WIFI_ETHERNET_STARTED: - if (HAS_ETHERNET) // && !settings.ntripClientUseWiFiNotEthernet) //For future expansion + if ((millis() - ntripClientTimer) > (1 * 60 * 1000)) + // Failed to connect to to the network, attempt to restart the network + ntripClientStop(false); + else if (HAS_ETHERNET) // && !settings.ntripClientUseWiFiNotEthernet) //For future expansion { if (online.ethernetStatus == ETH_CONNECTED) ntripClientSetState(NTRIP_CLIENT_WIFI_ETHERNET_CONNECTED); - else if (online.ethernetStatus == ETH_CAN_NOT_BEGIN) // Ethernet hardware failure or not available - ntripClientSetState(NTRIP_CLIENT_OFF); - else - { - // Wait for ethernet to connect - static unsigned long lastDebug = millis(); - if (millis() > (lastDebug + 5000)) - { - lastDebug = millis(); - log_d("NTRIP Client: Ethernet not connected. Waiting to retry."); - } - } } else { if (wifiIsConnected()) ntripClientSetState(NTRIP_CLIENT_WIFI_ETHERNET_CONNECTED); - else if (wifiState == WIFI_OFF) - { - // WiFi failed to connect. Restart Client which will restart WiFi. - ntripClientSetState(NTRIP_CLIENT_ON); - } } break; @@ -492,7 +480,12 @@ void ntripClientUpdate() { // NTRIP web service did not respond if (ntripClientConnectLimitReached()) // Updates ntripClientConnectionAttemptTimeout + { systemPrintln("NTRIP Caster failed to respond. Do you have your caster address and port correct?"); + + // Stop WiFi operations + ntripClientStop(true); // Do not allocate new wifiClient + } else { if (ntripClientConnectionAttemptTimeout / 1000 < 120) @@ -501,6 +494,9 @@ void ntripClientUpdate() else systemPrintf("NTRIP Client failed to connect to caster. Trying again in %d minutes.\r\n", ntripClientConnectionAttemptTimeout / 1000 / 60); + + // Restart network operation after delay + ntripClientStop(false); } } } @@ -510,10 +506,40 @@ void ntripClientUpdate() char response[512]; ntripClientResponse(&response[0], sizeof(response)); - log_d("Caster Response: %s", response); + //log_d("Caster Response: %s", response); // Look for various responses - if (strstr(response, "401") != nullptr) + if (strstr(response, "200") != nullptr) + { + log_d("NTRIP Client connected to caster"); + + // Connection is now open, start the NTRIP receive data timer + ntripClientTimer = millis(); + + if (settings.ntripClient_TransmitGGA == true) + { + // Set the Main Talker ID to "GP". The NMEA GGA messages will be GPGGA instead of GNGGA + theGNSS.setVal8(UBLOX_CFG_NMEA_MAINTALKERID, 1); + theGNSS.setNMEAGPGGAcallbackPtr(&pushGPGGA); // Set up the callback for GPGGA + + float measurementFrequency = (1000.0 / settings.measurementRate) / settings.navigationRate; + if (measurementFrequency < 0.2) + measurementFrequency = 0.2; // 0.2Hz * 5 = 1 measurement every 5 seconds + log_d("Adjusting GGA setting to %f", measurementFrequency); + theGNSS.setVal8( + UBLOX_CFG_MSGOUT_NMEA_ID_GGA_I2C, + measurementFrequency); // Enable GGA over I2C. Tell the module to output GGA every second + + lastGGAPush = millis() - NTRIPCLIENT_MS_BETWEEN_GGA; // Force immediate transmission of GGA message + } + + // We don't use a task because we use I2C hardware (and don't have a semphore). + online.ntripClient = true; + ntripClientStartTime = millis(); + ntripClientConnectionAttempts = 0; + ntripClientSetState(NTRIP_CLIENT_CONNECTED); + } + else if (strstr(response, "401") != nullptr) { // Look for '401 Unauthorized' systemPrintf( @@ -540,35 +566,33 @@ void ntripClientUpdate() // Stop WiFi operations ntripClientStop(true); // Do not allocate new wifiClient } - else if (strstr(response, "200") != nullptr) + // Other errors returned by the caster + else { - log_d("NTRIP Client connected to caster"); - - // Connection is now open, start the NTRIP receive data timer - ntripClientTimer = millis(); + systemPrintf("NTRIP Client connected but caster responded with problem: %s\r\n", response); - if (settings.ntripClient_TransmitGGA == true) + // Check for connection limit + if (ntripClientConnectLimitReached()) { - // Set the Main Talker ID to "GP". The NMEA GGA messages will be GPGGA instead of GNGGA - theGNSS.setVal8(UBLOX_CFG_NMEA_MAINTALKERID, 1); - theGNSS.setNMEAGPGGAcallbackPtr(&pushGPGGA); // Set up the callback for GPGGA - - float measurementFrequency = (1000.0 / settings.measurementRate) / settings.navigationRate; - if (measurementFrequency < 0.2) - measurementFrequency = 0.2; // 0.2Hz * 5 = 1 measurement every 5 seconds - log_d("Adjusting GGA setting to %f", measurementFrequency); - theGNSS.setVal8( - UBLOX_CFG_MSGOUT_NMEA_ID_GGA_I2C, - measurementFrequency); // Enable GGA over I2C. Tell the module to output GGA every second + systemPrintln("NTRIP Client retry limit reached; do you have your caster address and port correct?"); - lastGGAPush = millis() - NTRIPCLIENT_MS_BETWEEN_GGA; // Force immediate transmission of GGA message + // Give up - Shutdown NTRIP client, no further retries + ntripClientStop(true); } - // We don't use a task because we use I2C hardware (and don't have a semphore). - online.ntripClient = true; - ntripClientStartTime = millis(); - ntripClientConnectionAttempts = 0; - ntripClientSetState(NTRIP_CLIENT_CONNECTED); + // Attempt to reconnect after throttle controlled timeout + else + { + if (ntripClientConnectionAttemptTimeout / 1000 < 120) + systemPrintf("NTRIP Client attempting connection in %d seconds.\r\n", + ntripClientConnectionAttemptTimeout / 1000); + else + systemPrintf("NTRIP Client attempting connection in %d minutes.\r\n", + ntripClientConnectionAttemptTimeout / 1000 / 60); + + // Restart network operation after delay + ntripClientStop(false); + } } } #endif // COMPILE_WIFI || COMPILE_ETHERNET From cf5eeab326ee4613ebd6af8c3d81f26aaa000270 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 26 Jun 2023 15:18:39 +0100 Subject: [PATCH 5/5] Only call maintain when connected --- Firmware/RTK_Surveyor/menuEthernet.ino | 67 ++++++++++++++------------ 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/Firmware/RTK_Surveyor/menuEthernet.ino b/Firmware/RTK_Surveyor/menuEthernet.ino index 208f5f09a..1f1d8b8b1 100644 --- a/Firmware/RTK_Surveyor/menuEthernet.ino +++ b/Firmware/RTK_Surveyor/menuEthernet.ino @@ -183,42 +183,45 @@ void updateEthernet() w5500ClearSocketInterrupt(ntpSockIndex); // Clear the socket interrupt here // Maintain the ethernet connection - switch (Ethernet.maintain()) - { - case 1: - // renewed fail - if (settings.enablePrintEthernetDiag && (!inMainMenu)) - systemPrintln("Ethernet: Error: renewed fail"); - break; - - case 2: - // renewed success - if (settings.enablePrintEthernetDiag && (!inMainMenu)) + if ((online.ethernetStatus >= ETH_STARTED_CHECK_CABLE) && (online.ethernetStatus <= ETH_CONNECTED)) + switch (Ethernet.maintain()) { - systemPrint("Ethernet: Renewed success. IP address: "); - systemPrintln(Ethernet.localIP()); - } - break; + case 1: + // renewed fail + if (settings.enablePrintEthernetDiag && (!inMainMenu)) + systemPrintln("Ethernet: Error: renewed fail"); + ethernetRestart(); // Restart Ethernet + break; - case 3: - // rebind fail - if (settings.enablePrintEthernetDiag && (!inMainMenu)) - systemPrintln("Ethernet: Error: rebind fail"); - break; + case 2: + // renewed success + if (settings.enablePrintEthernetDiag && (!inMainMenu)) + { + systemPrint("Ethernet: Renewed success. IP address: "); + systemPrintln(Ethernet.localIP()); + } + break; - case 4: - // rebind success - if (settings.enablePrintEthernetDiag && (!inMainMenu)) - { - systemPrint("Ethernet: Rebind success. IP address: "); - systemPrintln(Ethernet.localIP()); - } - break; + case 3: + // rebind fail + if (settings.enablePrintEthernetDiag && (!inMainMenu)) + systemPrintln("Ethernet: Error: rebind fail"); + ethernetRestart(); // Restart Ethernet + break; - default: - // nothing happened - break; - } + case 4: + // rebind success + if (settings.enablePrintEthernetDiag && (!inMainMenu)) + { + systemPrint("Ethernet: Rebind success. IP address: "); + systemPrintln(Ethernet.localIP()); + } + break; + + default: + // nothing happened + break; + } #endif // COMPILE_ETHERNET }