@@ -392,6 +392,7 @@ void ntripClientUpdate()
392392 {
393393 ntripClientLastConnectionAttempt = millis ();
394394 log_d (" NTRIP Client starting on Ethernet" );
395+ ntripClientTimer = millis ();
395396 ntripClientSetState (NTRIP_CLIENT_WIFI_ETHERNET_STARTED);
396397 }
397398 }
@@ -416,6 +417,7 @@ void ntripClientUpdate()
416417 ntripClientLastConnectionAttempt = millis ();
417418 log_d (" NTRIP Client starting WiFi" );
418419 wifiStart ();
420+ ntripClientTimer = millis ();
419421 ntripClientSetState (NTRIP_CLIENT_WIFI_ETHERNET_STARTED);
420422 }
421423 }
@@ -424,32 +426,18 @@ void ntripClientUpdate()
424426 break ;
425427
426428 case NTRIP_CLIENT_WIFI_ETHERNET_STARTED:
427- if (HAS_ETHERNET) // && !settings.ntripClientUseWiFiNotEthernet) //For future expansion
429+ if ((millis () - ntripClientTimer) > (1 * 60 * 1000 ))
430+ // Failed to connect to to the network, attempt to restart the network
431+ ntripClientStop (false );
432+ else if (HAS_ETHERNET) // && !settings.ntripClientUseWiFiNotEthernet) //For future expansion
428433 {
429434 if (online.ethernetStatus == ETH_CONNECTED)
430435 ntripClientSetState (NTRIP_CLIENT_WIFI_ETHERNET_CONNECTED);
431- else if (online.ethernetStatus == ETH_CAN_NOT_BEGIN) // Ethernet hardware failure or not available
432- ntripClientSetState (NTRIP_CLIENT_OFF);
433- else
434- {
435- // Wait for ethernet to connect
436- static unsigned long lastDebug = millis ();
437- if (millis () > (lastDebug + 5000 ))
438- {
439- lastDebug = millis ();
440- log_d (" NTRIP Client: Ethernet not connected. Waiting to retry." );
441- }
442- }
443436 }
444437 else
445438 {
446439 if (wifiIsConnected ())
447440 ntripClientSetState (NTRIP_CLIENT_WIFI_ETHERNET_CONNECTED);
448- else if (wifiState == WIFI_OFF)
449- {
450- // WiFi failed to connect. Restart Client which will restart WiFi.
451- ntripClientSetState (NTRIP_CLIENT_ON);
452- }
453441 }
454442 break ;
455443
@@ -492,7 +480,12 @@ void ntripClientUpdate()
492480 {
493481 // NTRIP web service did not respond
494482 if (ntripClientConnectLimitReached ()) // Updates ntripClientConnectionAttemptTimeout
483+ {
495484 systemPrintln (" NTRIP Caster failed to respond. Do you have your caster address and port correct?" );
485+
486+ // Stop WiFi operations
487+ ntripClientStop (true ); // Do not allocate new wifiClient
488+ }
496489 else
497490 {
498491 if (ntripClientConnectionAttemptTimeout / 1000 < 120 )
@@ -501,6 +494,9 @@ void ntripClientUpdate()
501494 else
502495 systemPrintf (" NTRIP Client failed to connect to caster. Trying again in %d minutes.\r\n " ,
503496 ntripClientConnectionAttemptTimeout / 1000 / 60 );
497+
498+ // Restart network operation after delay
499+ ntripClientStop (false );
504500 }
505501 }
506502 }
@@ -510,10 +506,40 @@ void ntripClientUpdate()
510506 char response[512 ];
511507 ntripClientResponse (&response[0 ], sizeof (response));
512508
513- log_d (" Caster Response: %s" , response);
509+ // log_d("Caster Response: %s", response);
514510
515511 // Look for various responses
516- if (strstr (response, " 401" ) != nullptr )
512+ if (strstr (response, " 200" ) != nullptr )
513+ {
514+ log_d (" NTRIP Client connected to caster" );
515+
516+ // Connection is now open, start the NTRIP receive data timer
517+ ntripClientTimer = millis ();
518+
519+ if (settings.ntripClient_TransmitGGA == true )
520+ {
521+ // Set the Main Talker ID to "GP". The NMEA GGA messages will be GPGGA instead of GNGGA
522+ theGNSS.setVal8 (UBLOX_CFG_NMEA_MAINTALKERID, 1 );
523+ theGNSS.setNMEAGPGGAcallbackPtr (&pushGPGGA); // Set up the callback for GPGGA
524+
525+ float measurementFrequency = (1000.0 / settings.measurementRate ) / settings.navigationRate ;
526+ if (measurementFrequency < 0.2 )
527+ measurementFrequency = 0.2 ; // 0.2Hz * 5 = 1 measurement every 5 seconds
528+ log_d (" Adjusting GGA setting to %f" , measurementFrequency);
529+ theGNSS.setVal8 (
530+ UBLOX_CFG_MSGOUT_NMEA_ID_GGA_I2C,
531+ measurementFrequency); // Enable GGA over I2C. Tell the module to output GGA every second
532+
533+ lastGGAPush = millis () - NTRIPCLIENT_MS_BETWEEN_GGA; // Force immediate transmission of GGA message
534+ }
535+
536+ // We don't use a task because we use I2C hardware (and don't have a semphore).
537+ online.ntripClient = true ;
538+ ntripClientStartTime = millis ();
539+ ntripClientConnectionAttempts = 0 ;
540+ ntripClientSetState (NTRIP_CLIENT_CONNECTED);
541+ }
542+ else if (strstr (response, " 401" ) != nullptr )
517543 {
518544 // Look for '401 Unauthorized'
519545 systemPrintf (
@@ -540,35 +566,33 @@ void ntripClientUpdate()
540566 // Stop WiFi operations
541567 ntripClientStop (true ); // Do not allocate new wifiClient
542568 }
543- else if (strstr (response, " 200" ) != nullptr )
569+ // Other errors returned by the caster
570+ else
544571 {
545- log_d (" NTRIP Client connected to caster" );
546-
547- // Connection is now open, start the NTRIP receive data timer
548- ntripClientTimer = millis ();
572+ systemPrintf (" NTRIP Client connected but caster responded with problem: %s\r\n " , response);
549573
550- if (settings.ntripClient_TransmitGGA == true )
574+ // Check for connection limit
575+ if (ntripClientConnectLimitReached ())
551576 {
552- // Set the Main Talker ID to "GP". The NMEA GGA messages will be GPGGA instead of GNGGA
553- theGNSS.setVal8 (UBLOX_CFG_NMEA_MAINTALKERID, 1 );
554- theGNSS.setNMEAGPGGAcallbackPtr (&pushGPGGA); // Set up the callback for GPGGA
555-
556- float measurementFrequency = (1000.0 / settings.measurementRate ) / settings.navigationRate ;
557- if (measurementFrequency < 0.2 )
558- measurementFrequency = 0.2 ; // 0.2Hz * 5 = 1 measurement every 5 seconds
559- log_d (" Adjusting GGA setting to %f" , measurementFrequency);
560- theGNSS.setVal8 (
561- UBLOX_CFG_MSGOUT_NMEA_ID_GGA_I2C,
562- measurementFrequency); // Enable GGA over I2C. Tell the module to output GGA every second
577+ systemPrintln (" NTRIP Client retry limit reached; do you have your caster address and port correct?" );
563578
564- lastGGAPush = millis () - NTRIPCLIENT_MS_BETWEEN_GGA; // Force immediate transmission of GGA message
579+ // Give up - Shutdown NTRIP client, no further retries
580+ ntripClientStop (true );
565581 }
566582
567- // We don't use a task because we use I2C hardware (and don't have a semphore).
568- online.ntripClient = true ;
569- ntripClientStartTime = millis ();
570- ntripClientConnectionAttempts = 0 ;
571- ntripClientSetState (NTRIP_CLIENT_CONNECTED);
583+ // Attempt to reconnect after throttle controlled timeout
584+ else
585+ {
586+ if (ntripClientConnectionAttemptTimeout / 1000 < 120 )
587+ systemPrintf (" NTRIP Client attempting connection in %d seconds.\r\n " ,
588+ ntripClientConnectionAttemptTimeout / 1000 );
589+ else
590+ systemPrintf (" NTRIP Client attempting connection in %d minutes.\r\n " ,
591+ ntripClientConnectionAttemptTimeout / 1000 / 60 );
592+
593+ // Restart network operation after delay
594+ ntripClientStop (false );
595+ }
572596 }
573597 }
574598#endif // COMPILE_WIFI || COMPILE_ETHERNET
0 commit comments