@@ -415,6 +415,7 @@ void ntripServerUpdate()
415415 ntripServerLastConnectionAttempt = millis ();
416416 log_d (" NTRIP Server starting WiFi" );
417417 wifiStart ();
418+ ntripServerTimer = millis ();
418419 ntripServerSetState (NTRIP_SERVER_WIFI_ETHERNET_STARTED);
419420 }
420421 }
@@ -423,32 +424,18 @@ void ntripServerUpdate()
423424
424425 // Wait for connection to an access point
425426 case NTRIP_SERVER_WIFI_ETHERNET_STARTED:
426- if (HAS_ETHERNET) // && !settings.ntripServerUseWiFiNotEthernet) //For future expansion
427+ if ((millis () - ntripServerTimer) > (1 * 60 * 1000 ))
428+ // Failed to connect to to the network, attempt to restart the network
429+ ntripServerStop (false );
430+ else if (HAS_ETHERNET) // && !settings.ntripServerUseWiFiNotEthernet) //For future expansion
427431 {
428432 if (online.ethernetStatus == ETH_CONNECTED)
429433 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- }
442434 }
443435 else
444436 {
445437 if (wifiIsConnected ())
446438 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- }
452439 }
453440 break ;
454441
@@ -528,48 +515,67 @@ void ntripServerUpdate()
528515 ntripServerResponse (response, sizeof (response));
529516
530517 // Look for various responses
531- if (strstr (response, " 401" ) != nullptr )
518+ if (strstr (response, " 200" ) != nullptr ) // '200' found
519+ {
520+ systemPrintf (" NTRIP Server connected to %s:%d %s\r\n " , settings.ntripServer_CasterHost ,
521+ settings.ntripServer_CasterPort , settings.ntripServer_MountPoint );
522+
523+ // Connection is now open, start the RTCM correction data timer
524+ ntripServerTimer = millis ();
525+
526+ // We don't use a task because we use I2C hardware (and don't have a semphore).
527+ online.ntripServer = true ;
528+ ntripServerConnectionAttempts = 0 ;
529+ ntripServerSetState (NTRIP_SERVER_CASTING);
530+ }
531+
532+ // Look for '401 Unauthorized'
533+ else if (strstr (response, " 401" ) != nullptr )
532534 {
533- // Look for '401 Unauthorized'
534535 systemPrintf (
535536 " NTRIP Caster responded with bad news: %s. Are you sure your caster credentials are correct?\r\n " ,
536537 response);
537538
538- // Give up - Stop WiFi operations
539- ntripServerStop (true ); // Do not allocate new wifiClient
539+ // Give up - Shutdown NTRIP server, no further retries
540+ ntripServerStop (true );
540541 }
542+
543+ // Look for banned IP information
541544 else if (strstr (response, " banned" ) != nullptr ) // 'Banned' found
542545 {
543- // Look for 'HTTP/1.1 200 OK' and banned IP information
544546 systemPrintf (" NTRIP Server connected to caster but caster responded with problem: %s" , response);
545547
546- // Give up - Stop WiFi operations
547- ntripServerStop (true ); // Do not allocate new wifiClient
548+ // Give up - Shutdown NTRIP server, no further retries
549+ ntripServerStop (true );
548550 }
549- else if (strstr (response, " 200" ) == nullptr ) // '200' not found
551+
552+ // Other errors returned by the caster
553+ else
550554 {
551- // Look for 'ERROR - Mountpoint taken' from Emlid.
552555 systemPrintf (" NTRIP Server connected but caster responded with problem: %s" , response);
553556
554- // Attempt to reconnect after throttle controlled timeout
557+ // Check for connection limit
555558 if (ntripServerConnectLimitReached ())
556559 {
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
560+ systemPrintln (" NTRIP Server retry limit reached; do you have your caster address and port correct?" );
561561
562- {
563- systemPrintf ( " NTRIP Server connected to %s:%d %s \r\n " , settings. ntripServer_CasterHost ,
564- settings. ntripServer_CasterPort , settings. ntripServer_MountPoint );
562+ // Give up - Shutdown NTRIP server, no further retries
563+ ntripServerStop ( true );
564+ }
565565
566- // Connection is now open, start the RTCM correction data timer
567- ntripServerTimer = millis ();
566+ // Attempt to reconnect after throttle controlled timeout
567+ else
568+ {
569+ if (ntripServerConnectionAttemptTimeout / 1000 < 120 )
570+ systemPrintf (" NTRIP Server attempting connection in %d seconds.\r\n " ,
571+ ntripServerConnectionAttemptTimeout / 1000 );
572+ else
573+ systemPrintf (" NTRIP Server attempting connection in %d minutes.\r\n " ,
574+ ntripServerConnectionAttemptTimeout / 1000 / 60 );
568575
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);
576+ // Restart network operation after delay
577+ ntripServerStop (false );
578+ }
573579 }
574580 }
575581#endif // COMPILE_WIFI || COMPILE_ETHERNET
0 commit comments