Skip to content
Merged
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
88 changes: 47 additions & 41 deletions Firmware/RTK_Surveyor/NtripServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ void ntripServerUpdate()
ntripServerLastConnectionAttempt = millis();
log_d("NTRIP Server starting WiFi");
wifiStart();
ntripServerTimer = millis();
ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_STARTED);
}
}
Expand All @@ -423,32 +424,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 @@ -528,48 +515,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);

// 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);

// 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