11/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2- NTRIP Client States:
3- NTRIP_CLIENT_OFF: Using Bluetooth or NTRIP server
2+ NTRIP Client States:
3+ NTRIP_CLIENT_OFF: WiFi off or or NTRIP server
44 NTRIP_CLIENT_ON: WIFI_ON state
55 NTRIP_CLIENT_WIFI_CONNECTING: Connecting to WiFi access point
66 NTRIP_CLIENT_WIFI_CONNECTED: WiFi connected to an access point
@@ -29,7 +29,7 @@ NTRIP Client States:
2929 v Fail |
3030 NTRIP_CLIENT_CONNECTED -----------'
3131
32- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
32+ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3333
3434// ----------------------------------------
3535// Constants - compiled out
@@ -44,7 +44,7 @@ static const int CREDENTIALS_BUFFER_SIZE = 512;
4444static const int MAX_NTRIP_CLIENT_CONNECTION_ATTEMPTS = 3 ;
4545
4646// NTRIP caster response timeout
47- static const uint32_t NTRIP_CLIENT_RESPONSE_TIMEOUT = 5 * 1000 ; // Milliseconds
47+ static const uint32_t NTRIP_CLIENT_RESPONSE_TIMEOUT = 10 * 1000 ; // Milliseconds
4848
4949// NTRIP client receive data timeout
5050static const uint32_t NTRIP_CLIENT_RECEIVE_DATA_TIMEOUT = 10 * 1000 ; // Milliseconds
@@ -73,6 +73,9 @@ static uint32_t ntripClientTimer;
7373// Last time the NTRIP client state was displayed
7474static uint32_t lastNtripClientState = 0 ;
7575
76+ // Throttle GGA transmission to Caster to 1 report every 5 seconds
77+ unsigned long lastGGAPush = 0 ;
78+
7679// ----------------------------------------
7780// NTRIP Client Routines - compiled out
7881// ----------------------------------------
@@ -85,7 +88,7 @@ void ntripClientAllowMoreConnections()
8588bool ntripClientConnect ()
8689{
8790 if ((!ntripClient)
88- || (!ntripClient->connect (settings.ntripClient_CasterHost , settings.ntripClient_CasterPort )))
91+ || (!ntripClient->connect (settings.ntripClient_CasterHost , settings.ntripClient_CasterPort )))
8992 return false ;
9093 Serial.printf (" NTRIP Client connected to %s:%d\n\r " , settings.ntripClient_CasterHost , settings.ntripClient_CasterPort );
9194
@@ -280,6 +283,10 @@ void ntripClientStop(bool done)
280283 if (ntripClientState > NTRIP_CLIENT_ON)
281284 wifiStop ();
282285
286+ // Return the Main Talker ID to "GN".
287+ i2cGNSS.setMainTalkerID (SFE_UBLOX_MAIN_TALKER_ID_GN);
288+ i2cGNSS.setNMEAGPGGAcallbackPtr (NULL ); // Remove callback
289+
283290 // Determine the next NTRIP client state
284291 ntripClientSetState ((ntripClient && (!done)) ? NTRIP_CLIENT_ON : NTRIP_CLIENT_OFF);
285292 online.ntripClient = false ;
@@ -320,6 +327,8 @@ void ntripClientUpdate()
320327 if (ntripClientConnectLimitReached ())
321328 // Display the WiFi failure
322329 paintNtripWiFiFail (4000 , true );
330+
331+ // TODO WiFi not available, give up, disable future attempts
323332 }
324333 }
325334 else
@@ -346,7 +355,7 @@ void ntripClientUpdate()
346355
347356 case NTRIP_CLIENT_CONNECTING:
348357 // Check for no response from the caster service
349- if (ntripClientReceiveDataAvailable () == 0 )
358+ if (ntripClientReceiveDataAvailable () < strlen ( " ICY 200 OK " )) // Wait until at least a few bytes have arrived
350359 {
351360 // Check for response timeout
352361 if (millis () - ntripClientTimer > NTRIP_CLIENT_RESPONSE_TIMEOUT)
@@ -362,6 +371,8 @@ void ntripClientUpdate()
362371 char response[512 ];
363372 ntripClientResponse (&response[0 ], sizeof (response));
364373
374+ // Serial.printf("Response: %s\n\r", response);
375+
365376 // Look for '200 OK'
366377 if (strstr (response, " 200" ) == NULL )
367378 {
@@ -378,6 +389,16 @@ void ntripClientUpdate()
378389 // Connection is now open, start the NTRIP receive data timer
379390 ntripClientTimer = millis ();
380391
392+ // Set the Main Talker ID to "GP". The NMEA GGA messages will be GPGGA instead of GNGGA
393+ i2cGNSS.setMainTalkerID (SFE_UBLOX_MAIN_TALKER_ID_GP);
394+ i2cGNSS.setNMEAGPGGAcallbackPtr (&pushGPGGA); // Set up the callback for GPGGA
395+
396+ float measurementFrequency = (1000.0 / settings.measurementRate ) / settings.navigationRate ;
397+ if (measurementFrequency < 0.2 ) measurementFrequency = 0.2 ; // 0.2Hz * 5 = 1 measurement every 5 seconds
398+ i2cGNSS.enableNMEAMessage (UBX_NMEA_GGA, COM_PORT_I2C, measurementFrequency * 5 ); // Enable GGA over I2C. Tell the module to output GGA every 5 seconds
399+
400+ lastGGAPush = millis ();
401+
381402 // We don't use a task because we use I2C hardware (and don't have a semphore).
382403 online.ntripClient = true ;
383404 ntripClientAllowMoreConnections ();
@@ -402,14 +423,13 @@ void ntripClientUpdate()
402423 if ((millis () - ntripClientTimer) > NTRIP_CLIENT_RECEIVE_DATA_TIMEOUT)
403424 {
404425 // Timeout receiving NTRIP data, retry the NTRIP client connection
405- Serial.println (" NTRIP Client timeout" );
426+ Serial.println (" NTRIP Client: No data received timeout" );
406427 ntripClientStop (false );
407428 }
408429 }
409430 else
410431 {
411- // Received data from the NTRIP server
412- // 5 RTCM messages take approximately ~300ms to arrive at 115200bps
432+ // Receive data from the NTRIP Caster
413433 uint8_t rtcmData[RTCM_DATA_SIZE];
414434 size_t rtcmCount = 0 ;
415435
@@ -428,10 +448,36 @@ void ntripClientUpdate()
428448 i2cGNSS.pushRawData (rtcmData, rtcmCount);
429449 online.rxRtcmCorrectionData = true ;
430450
431- // log_d("NTRIP Client pushed %d RTCM bytes to ZED", rtcmCount);
451+ log_d (" NTRIP Client pushed %d RTCM bytes to ZED" , rtcmCount);
432452 }
433453 }
454+
455+ if (millis () - lastRSSIUpdate > 5000 )
456+ {
457+ lastRSSIUpdate = millis ();
458+ Serial.printf (" WiFi RSSI: %d\n\r " , WiFi.RSSI ());
459+ }
460+
434461 break ;
435462 }
436- #endif // COMPILE_WIFI
463+ #endif // COMPILE_WIFI
464+ }
465+
466+ void pushGPGGA (NMEA_GGA_data_t *nmeaData)
467+ {
468+ #ifdef COMPILE_WIFI
469+ // Provide the caster with our current position as needed
470+ if ((ntripClient->connected () == true ) && (settings.ntripClient_TransmitGGA == true ))
471+ {
472+ if (millis () - lastGGAPush > 5000 )
473+ {
474+ lastGGAPush = millis ();
475+ // Serial.print(F("Pushing GGA to server: "));
476+ // Serial.print((const char *)nmeaData->nmea); // .nmea is printable (NULL-terminated) and already has \r\n on the end
477+
478+ // Push our current GGA sentence to caster
479+ ntripClient->print ((const char *)nmeaData->nmea );
480+ }
481+ }
482+ #endif
437483}
0 commit comments