@@ -249,7 +249,7 @@ void ntripServerProcessRTCM(uint8_t incoming)
249249 }
250250
251251 // If we have not gotten new RTCM bytes for a period of time, assume end of frame
252- if (millis () - ntripServerTimer > 100 && ntripServerBytesSent > 0 )
252+ if ((( millis () - ntripServerTimer) > 100 ) && ( ntripServerBytesSent > 0 ) )
253253 {
254254 if ((!inMainMenu) && settings.enablePrintNtripServerState )
255255 systemPrintf (" NTRIP Server transmitted %d RTCM bytes to Caster\r\n " , ntripServerBytesSent);
@@ -391,6 +391,7 @@ void ntripServerUpdate()
391391 {
392392 ntripServerLastConnectionAttempt = millis ();
393393 log_d (" NTRIP Server starting on Ethernet" );
394+ ntripServerTimer = millis ();
394395 ntripServerSetState (NTRIP_SERVER_WIFI_ETHERNET_STARTED);
395396 }
396397 }
@@ -415,6 +416,7 @@ void ntripServerUpdate()
415416 ntripServerLastConnectionAttempt = millis ();
416417 log_d (" NTRIP Server starting WiFi" );
417418 wifiStart ();
419+ ntripServerTimer = millis ();
418420 ntripServerSetState (NTRIP_SERVER_WIFI_ETHERNET_STARTED);
419421 }
420422 }
@@ -423,32 +425,18 @@ void ntripServerUpdate()
423425
424426 // Wait for connection to an access point
425427 case NTRIP_SERVER_WIFI_ETHERNET_STARTED:
426- if (HAS_ETHERNET) // && !settings.ntripServerUseWiFiNotEthernet) //For future expansion
428+ if ((millis () - ntripServerTimer) > (1 * 60 * 1000 ))
429+ // Failed to connect to to the network, attempt to restart the network
430+ ntripServerStop (false );
431+ else if (HAS_ETHERNET) // && !settings.ntripServerUseWiFiNotEthernet) //For future expansion
427432 {
428433 if (online.ethernetStatus == ETH_CONNECTED)
429434 ntripServerSetState (NTRIP_SERVER_WIFI_ETHERNET_CONNECTED);
430- else if (online.ethernetStatus == ETH_CAN_NOT_BEGIN) // Ethernet hardware failure or not available
431- ntripServerSetState (NTRIP_SERVER_OFF);
432- else
433- {
434- // Wait for ethernet to connect
435- static unsigned long lastDebug = millis ();
436- if (millis () > (lastDebug + 5000 ))
437- {
438- lastDebug = millis ();
439- log_d (" NTRIP Server: Ethernet not connected. Waiting to retry." );
440- }
441- }
442435 }
443436 else
444437 {
445438 if (wifiIsConnected ())
446439 ntripServerSetState (NTRIP_SERVER_WIFI_ETHERNET_CONNECTED);
447- else if (wifiState == WIFI_OFF)
448- {
449- // WiFi failed to connect. Restart Client which will restart WiFi.
450- ntripServerSetState (NTRIP_SERVER_ON);
451- }
452440 }
453441 break ;
454442
@@ -509,6 +497,9 @@ void ntripServerUpdate()
509497 if (ntripServerConnectLimitReached ())
510498 {
511499 systemPrintln (" Caster failed to respond. Do you have your caster address and port correct?" );
500+
501+ // Give up - Shutdown NTRIP server, no further retries
502+ ntripServerStop (true );
512503 }
513504 else
514505 {
@@ -518,6 +509,9 @@ void ntripServerUpdate()
518509 else
519510 systemPrintf (" NTRIP caster failed to respond. Trying again in %d minutes.\r\n " ,
520511 ntripServerConnectionAttemptTimeout / 1000 / 60 );
512+
513+ // Restart network operation after delay
514+ ntripServerStop (false );
521515 }
522516 }
523517 }
@@ -528,48 +522,67 @@ void ntripServerUpdate()
528522 ntripServerResponse (response, sizeof (response));
529523
530524 // Look for various responses
531- if (strstr (response, " 401" ) != nullptr )
525+ if (strstr (response, " 200" ) != nullptr ) // '200' found
526+ {
527+ systemPrintf (" NTRIP Server connected to %s:%d %s\r\n " , settings.ntripServer_CasterHost ,
528+ settings.ntripServer_CasterPort , settings.ntripServer_MountPoint );
529+
530+ // Connection is now open, start the RTCM correction data timer
531+ ntripServerTimer = millis ();
532+
533+ // We don't use a task because we use I2C hardware (and don't have a semphore).
534+ online.ntripServer = true ;
535+ ntripServerConnectionAttempts = 0 ;
536+ ntripServerSetState (NTRIP_SERVER_CASTING);
537+ }
538+
539+ // Look for '401 Unauthorized'
540+ else if (strstr (response, " 401" ) != nullptr )
532541 {
533- // Look for '401 Unauthorized'
534542 systemPrintf (
535543 " NTRIP Caster responded with bad news: %s. Are you sure your caster credentials are correct?\r\n " ,
536544 response);
537545
538- // Give up - Stop WiFi operations
539- ntripServerStop (true ); // Do not allocate new wifiClient
546+ // Give up - Shutdown NTRIP server, no further retries
547+ ntripServerStop (true );
540548 }
549+
550+ // Look for banned IP information
541551 else if (strstr (response, " banned" ) != nullptr ) // 'Banned' found
542552 {
543- // Look for 'HTTP/1.1 200 OK' and banned IP information
544- systemPrintf (" NTRIP Server connected to caster but caster responded with problem: %s" , response);
553+ systemPrintf (" NTRIP Server connected to caster but caster responded with problem: %s\r\n " , response);
545554
546- // Give up - Stop WiFi operations
547- ntripServerStop (true ); // Do not allocate new wifiClient
555+ // Give up - Shutdown NTRIP server, no further retries
556+ ntripServerStop (true );
548557 }
549- else if (strstr (response, " 200" ) == nullptr ) // '200' not found
558+
559+ // Other errors returned by the caster
560+ else
550561 {
551- // Look for 'ERROR - Mountpoint taken' from Emlid.
552- systemPrintf (" NTRIP Server connected but caster responded with problem: %s" , response);
562+ systemPrintf (" NTRIP Server connected but caster responded with problem: %s\r\n " , response);
553563
554- // Attempt to reconnect after throttle controlled timeout
564+ // Check for connection limit
555565 if (ntripServerConnectLimitReached ())
556566 {
557- systemPrintln (" Caster failed to respond. Do you have your caster address and port correct?" );
558- }
559- }
560- else if (strstr (response, " 200" ) != nullptr ) // '200' found
567+ systemPrintln (" NTRIP Server retry limit reached; do you have your caster address and port correct?" );
561568
562- {
563- systemPrintf ( " NTRIP Server connected to %s:%d %s \r\n " , settings. ntripServer_CasterHost ,
564- settings. ntripServer_CasterPort , settings. ntripServer_MountPoint );
569+ // Give up - Shutdown NTRIP server, no further retries
570+ ntripServerStop ( true );
571+ }
565572
566- // Connection is now open, start the RTCM correction data timer
567- ntripServerTimer = millis ();
573+ // Attempt to reconnect after throttle controlled timeout
574+ else
575+ {
576+ if (ntripServerConnectionAttemptTimeout / 1000 < 120 )
577+ systemPrintf (" NTRIP Server attempting connection in %d seconds.\r\n " ,
578+ ntripServerConnectionAttemptTimeout / 1000 );
579+ else
580+ systemPrintf (" NTRIP Server attempting connection in %d minutes.\r\n " ,
581+ ntripServerConnectionAttemptTimeout / 1000 / 60 );
568582
569- // We don't use a task because we use I2C hardware (and don't have a semphore).
570- online.ntripServer = true ;
571- ntripServerConnectionAttempts = 0 ;
572- ntripServerSetState (NTRIP_SERVER_CASTING);
583+ // Restart network operation after delay
584+ ntripServerStop (false );
585+ }
573586 }
574587 }
575588#endif // COMPILE_WIFI || COMPILE_ETHERNET
0 commit comments