Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 67 additions & 43 deletions Firmware/RTK_Surveyor/NtripClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ void ntripClientUpdate()
{
ntripClientLastConnectionAttempt = millis();
log_d("NTRIP Client starting on Ethernet");
ntripClientTimer = millis();
ntripClientSetState(NTRIP_CLIENT_WIFI_ETHERNET_STARTED);
}
}
Expand All @@ -416,6 +417,7 @@ void ntripClientUpdate()
ntripClientLastConnectionAttempt = millis();
log_d("NTRIP Client starting WiFi");
wifiStart();
ntripClientTimer = millis();
ntripClientSetState(NTRIP_CLIENT_WIFI_ETHERNET_STARTED);
}
}
Expand All @@ -424,32 +426,18 @@ void ntripClientUpdate()
break;

case NTRIP_CLIENT_WIFI_ETHERNET_STARTED:
if (HAS_ETHERNET) // && !settings.ntripClientUseWiFiNotEthernet) //For future expansion
if ((millis() - ntripClientTimer) > (1 * 60 * 1000))
// Failed to connect to to the network, attempt to restart the network
ntripClientStop(false);
else if (HAS_ETHERNET) // && !settings.ntripClientUseWiFiNotEthernet) //For future expansion
{
if (online.ethernetStatus == ETH_CONNECTED)
ntripClientSetState(NTRIP_CLIENT_WIFI_ETHERNET_CONNECTED);
else if (online.ethernetStatus == ETH_CAN_NOT_BEGIN) // Ethernet hardware failure or not available
ntripClientSetState(NTRIP_CLIENT_OFF);
else
{
// Wait for ethernet to connect
static unsigned long lastDebug = millis();
if (millis() > (lastDebug + 5000))
{
lastDebug = millis();
log_d("NTRIP Client: Ethernet not connected. Waiting to retry.");
}
}
}
else
{
if (wifiIsConnected())
ntripClientSetState(NTRIP_CLIENT_WIFI_ETHERNET_CONNECTED);
else if (wifiState == WIFI_OFF)
{
// WiFi failed to connect. Restart Client which will restart WiFi.
ntripClientSetState(NTRIP_CLIENT_ON);
}
}
break;

Expand Down Expand Up @@ -492,7 +480,12 @@ void ntripClientUpdate()
{
// NTRIP web service did not respond
if (ntripClientConnectLimitReached()) // Updates ntripClientConnectionAttemptTimeout
{
systemPrintln("NTRIP Caster failed to respond. Do you have your caster address and port correct?");

// Stop WiFi operations
ntripClientStop(true); // Do not allocate new wifiClient
}
else
{
if (ntripClientConnectionAttemptTimeout / 1000 < 120)
Expand All @@ -501,6 +494,9 @@ void ntripClientUpdate()
else
systemPrintf("NTRIP Client failed to connect to caster. Trying again in %d minutes.\r\n",
ntripClientConnectionAttemptTimeout / 1000 / 60);

// Restart network operation after delay
ntripClientStop(false);
}
}
}
Expand All @@ -510,10 +506,40 @@ void ntripClientUpdate()
char response[512];
ntripClientResponse(&response[0], sizeof(response));

log_d("Caster Response: %s", response);
//log_d("Caster Response: %s", response);

// Look for various responses
if (strstr(response, "401") != nullptr)
if (strstr(response, "200") != nullptr)
{
log_d("NTRIP Client connected to caster");

// Connection is now open, start the NTRIP receive data timer
ntripClientTimer = millis();

if (settings.ntripClient_TransmitGGA == true)
{
// Set the Main Talker ID to "GP". The NMEA GGA messages will be GPGGA instead of GNGGA
theGNSS.setVal8(UBLOX_CFG_NMEA_MAINTALKERID, 1);
theGNSS.setNMEAGPGGAcallbackPtr(&pushGPGGA); // Set up the callback for GPGGA

float measurementFrequency = (1000.0 / settings.measurementRate) / settings.navigationRate;
if (measurementFrequency < 0.2)
measurementFrequency = 0.2; // 0.2Hz * 5 = 1 measurement every 5 seconds
log_d("Adjusting GGA setting to %f", measurementFrequency);
theGNSS.setVal8(
UBLOX_CFG_MSGOUT_NMEA_ID_GGA_I2C,
measurementFrequency); // Enable GGA over I2C. Tell the module to output GGA every second

lastGGAPush = millis() - NTRIPCLIENT_MS_BETWEEN_GGA; // Force immediate transmission of GGA message
}

// We don't use a task because we use I2C hardware (and don't have a semphore).
online.ntripClient = true;
ntripClientStartTime = millis();
ntripClientConnectionAttempts = 0;
ntripClientSetState(NTRIP_CLIENT_CONNECTED);
}
else if (strstr(response, "401") != nullptr)
{
// Look for '401 Unauthorized'
systemPrintf(
Expand All @@ -540,35 +566,33 @@ void ntripClientUpdate()
// Stop WiFi operations
ntripClientStop(true); // Do not allocate new wifiClient
}
else if (strstr(response, "200") != nullptr)
// Other errors returned by the caster
else
{
log_d("NTRIP Client connected to caster");

// Connection is now open, start the NTRIP receive data timer
ntripClientTimer = millis();
systemPrintf("NTRIP Client connected but caster responded with problem: %s\r\n", response);

if (settings.ntripClient_TransmitGGA == true)
// Check for connection limit
if (ntripClientConnectLimitReached())
{
// Set the Main Talker ID to "GP". The NMEA GGA messages will be GPGGA instead of GNGGA
theGNSS.setVal8(UBLOX_CFG_NMEA_MAINTALKERID, 1);
theGNSS.setNMEAGPGGAcallbackPtr(&pushGPGGA); // Set up the callback for GPGGA

float measurementFrequency = (1000.0 / settings.measurementRate) / settings.navigationRate;
if (measurementFrequency < 0.2)
measurementFrequency = 0.2; // 0.2Hz * 5 = 1 measurement every 5 seconds
log_d("Adjusting GGA setting to %f", measurementFrequency);
theGNSS.setVal8(
UBLOX_CFG_MSGOUT_NMEA_ID_GGA_I2C,
measurementFrequency); // Enable GGA over I2C. Tell the module to output GGA every second
systemPrintln("NTRIP Client retry limit reached; do you have your caster address and port correct?");

lastGGAPush = millis() - NTRIPCLIENT_MS_BETWEEN_GGA; // Force immediate transmission of GGA message
// Give up - Shutdown NTRIP client, no further retries
ntripClientStop(true);
}

// We don't use a task because we use I2C hardware (and don't have a semphore).
online.ntripClient = true;
ntripClientStartTime = millis();
ntripClientConnectionAttempts = 0;
ntripClientSetState(NTRIP_CLIENT_CONNECTED);
// Attempt to reconnect after throttle controlled timeout
else
{
if (ntripClientConnectionAttemptTimeout / 1000 < 120)
systemPrintf("NTRIP Client attempting connection in %d seconds.\r\n",
ntripClientConnectionAttemptTimeout / 1000);
else
systemPrintf("NTRIP Client attempting connection in %d minutes.\r\n",
ntripClientConnectionAttemptTimeout / 1000 / 60);

// Restart network operation after delay
ntripClientStop(false);
}
}
}
#endif // COMPILE_WIFI || COMPILE_ETHERNET
Expand Down
101 changes: 57 additions & 44 deletions Firmware/RTK_Surveyor/NtripServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void ntripServerProcessRTCM(uint8_t incoming)
}

// If we have not gotten new RTCM bytes for a period of time, assume end of frame
if (millis() - ntripServerTimer > 100 && ntripServerBytesSent > 0)
if (((millis() - ntripServerTimer) > 100) && (ntripServerBytesSent > 0))
{
if ((!inMainMenu) && settings.enablePrintNtripServerState)
systemPrintf("NTRIP Server transmitted %d RTCM bytes to Caster\r\n", ntripServerBytesSent);
Expand Down Expand Up @@ -391,6 +391,7 @@ void ntripServerUpdate()
{
ntripServerLastConnectionAttempt = millis();
log_d("NTRIP Server starting on Ethernet");
ntripServerTimer = millis();
ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_STARTED);
}
}
Expand All @@ -415,6 +416,7 @@ void ntripServerUpdate()
ntripServerLastConnectionAttempt = millis();
log_d("NTRIP Server starting WiFi");
wifiStart();
ntripServerTimer = millis();
ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_STARTED);
}
}
Expand All @@ -423,32 +425,18 @@ void ntripServerUpdate()

// Wait for connection to an access point
case NTRIP_SERVER_WIFI_ETHERNET_STARTED:
if (HAS_ETHERNET) // && !settings.ntripServerUseWiFiNotEthernet) //For future expansion
if ((millis() - ntripServerTimer) > (1 * 60 * 1000))
// Failed to connect to to the network, attempt to restart the network
ntripServerStop(false);
else if (HAS_ETHERNET) // && !settings.ntripServerUseWiFiNotEthernet) //For future expansion
{
if (online.ethernetStatus == ETH_CONNECTED)
ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_CONNECTED);
else if (online.ethernetStatus == ETH_CAN_NOT_BEGIN) // Ethernet hardware failure or not available
ntripServerSetState(NTRIP_SERVER_OFF);
else
{
// Wait for ethernet to connect
static unsigned long lastDebug = millis();
if (millis() > (lastDebug + 5000))
{
lastDebug = millis();
log_d("NTRIP Server: Ethernet not connected. Waiting to retry.");
}
}
}
else
{
if (wifiIsConnected())
ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_CONNECTED);
else if (wifiState == WIFI_OFF)
{
// WiFi failed to connect. Restart Client which will restart WiFi.
ntripServerSetState(NTRIP_SERVER_ON);
}
}
break;

Expand Down Expand Up @@ -509,6 +497,9 @@ void ntripServerUpdate()
if (ntripServerConnectLimitReached())
{
systemPrintln("Caster failed to respond. Do you have your caster address and port correct?");

// Give up - Shutdown NTRIP server, no further retries
ntripServerStop(true);
}
else
{
Expand All @@ -518,6 +509,9 @@ void ntripServerUpdate()
else
systemPrintf("NTRIP caster failed to respond. Trying again in %d minutes.\r\n",
ntripServerConnectionAttemptTimeout / 1000 / 60);

// Restart network operation after delay
ntripServerStop(false);
}
}
}
Expand All @@ -528,48 +522,67 @@ void ntripServerUpdate()
ntripServerResponse(response, sizeof(response));

// Look for various responses
if (strstr(response, "401") != nullptr)
if (strstr(response, "200") != nullptr) //'200' found
{
systemPrintf("NTRIP Server connected to %s:%d %s\r\n", settings.ntripServer_CasterHost,
settings.ntripServer_CasterPort, settings.ntripServer_MountPoint);

// Connection is now open, start the RTCM correction data timer
ntripServerTimer = millis();

// We don't use a task because we use I2C hardware (and don't have a semphore).
online.ntripServer = true;
ntripServerConnectionAttempts = 0;
ntripServerSetState(NTRIP_SERVER_CASTING);
}

// Look for '401 Unauthorized'
else if (strstr(response, "401") != nullptr)
{
// Look for '401 Unauthorized'
systemPrintf(
"NTRIP Caster responded with bad news: %s. Are you sure your caster credentials are correct?\r\n",
response);

// Give up - Stop WiFi operations
ntripServerStop(true); // Do not allocate new wifiClient
// Give up - Shutdown NTRIP server, no further retries
ntripServerStop(true);
}

// Look for banned IP information
else if (strstr(response, "banned") != nullptr) //'Banned' found
{
// Look for 'HTTP/1.1 200 OK' and banned IP information
systemPrintf("NTRIP Server connected to caster but caster responded with problem: %s", response);
systemPrintf("NTRIP Server connected to caster but caster responded with problem: %s\r\n", response);

// Give up - Stop WiFi operations
ntripServerStop(true); // Do not allocate new wifiClient
// Give up - Shutdown NTRIP server, no further retries
ntripServerStop(true);
}
else if (strstr(response, "200") == nullptr) //'200' not found

// Other errors returned by the caster
else
{
// Look for 'ERROR - Mountpoint taken' from Emlid.
systemPrintf("NTRIP Server connected but caster responded with problem: %s", response);
systemPrintf("NTRIP Server connected but caster responded with problem: %s\r\n", response);

// Attempt to reconnect after throttle controlled timeout
// Check for connection limit
if (ntripServerConnectLimitReached())
{
systemPrintln("Caster failed to respond. Do you have your caster address and port correct?");
}
}
else if (strstr(response, "200") != nullptr) //'200' found
systemPrintln("NTRIP Server retry limit reached; do you have your caster address and port correct?");

{
systemPrintf("NTRIP Server connected to %s:%d %s\r\n", settings.ntripServer_CasterHost,
settings.ntripServer_CasterPort, settings.ntripServer_MountPoint);
// Give up - Shutdown NTRIP server, no further retries
ntripServerStop(true);
}

// Connection is now open, start the RTCM correction data timer
ntripServerTimer = millis();
// Attempt to reconnect after throttle controlled timeout
else
{
if (ntripServerConnectionAttemptTimeout / 1000 < 120)
systemPrintf("NTRIP Server attempting connection in %d seconds.\r\n",
ntripServerConnectionAttemptTimeout / 1000);
else
systemPrintf("NTRIP Server attempting connection in %d minutes.\r\n",
ntripServerConnectionAttemptTimeout / 1000 / 60);

// We don't use a task because we use I2C hardware (and don't have a semphore).
online.ntripServer = true;
ntripServerConnectionAttempts = 0;
ntripServerSetState(NTRIP_SERVER_CASTING);
// Restart network operation after delay
ntripServerStop(false);
}
}
}
#endif // COMPILE_WIFI || COMPILE_ETHERNET
Expand Down
Loading