Skip to content

Commit 7643497

Browse files
committed
NTRIP Client bug fixes and GGA add
Add min bytes received before reading response. Add GGA sending. Add WiFi RSSI printing. Fix comments I believe the client was parsing a partial response from the server when ntripClientReceiveDataAvailable() returned something less than strlen("ICY 200 OK"). Also, the coffee shop AP seems to be blocking or throttling port 2101. When in doubt, test with a cell phone hotspot or other device that guarantees 2101.
1 parent 262ab2f commit 7643497

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

Firmware/RTK_Surveyor/NtripClient.ino

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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;
4444
static 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
5050
static 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
7474
static 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()
8588
bool 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
}

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ unsigned long rtcWaitTime = 0; //At poweron, we give the RTC a few seconds to up
454454
TaskHandle_t idleTaskHandle[MAX_CPU_CORES];
455455
uint32_t max_idle_count = MAX_IDLE_TIME_COUNT;
456456

457+
unsigned long lastRSSIUpdate = 0; //Print RSSI when connected every few seconds
458+
457459
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
458460
/*
459461
+---------------------------------------+ +----------+

0 commit comments

Comments
 (0)