Skip to content

Commit 41da2e9

Browse files
committed
Stop NTRIP Client/Server if SSID is blank
1 parent 2d74e27 commit 41da2e9

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

Firmware/RTK_Surveyor/NtripClient.ino

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static int ntripClientConnectionAttempts;
7171
// * Measure the connection response time
7272
// * Receive NTRIP data timeout
7373
static uint32_t ntripClientTimer;
74+
static uint32_t ntripClientStartTime; //For calculating uptime
7475

7576
//Last time the NTRIP client state was displayed
7677
static uint32_t lastNtripClientState = 0;
@@ -99,7 +100,7 @@ bool ntripClientConnect()
99100
if (token != NULL)
100101
{
101102
token = strtok(NULL, "//"); //Advance to data after //
102-
if(token != NULL)
103+
if (token != NULL)
103104
strcpy(settings.ntripClient_CasterHost, token);
104105
}
105106

@@ -324,8 +325,16 @@ void ntripClientUpdate()
324325

325326
//Start WiFi
326327
case NTRIP_CLIENT_ON:
327-
wifiStart(settings.ntripClient_wifiSSID, settings.ntripClient_wifiPW);
328-
ntripClientSetState(NTRIP_CLIENT_WIFI_CONNECTING);
328+
if (strlen(settings.ntripClient_wifiSSID) == 0)
329+
{
330+
Serial.println("Error: Please enter SSID before starting NTRIP Client");
331+
ntripClientSetState(NTRIP_CLIENT_OFF);
332+
}
333+
else
334+
{
335+
wifiStart(settings.ntripClient_wifiSSID, settings.ntripClient_wifiPW);
336+
ntripClientSetState(NTRIP_CLIENT_WIFI_CONNECTING);
337+
}
329338
break;
330339

331340
case NTRIP_CLIENT_WIFI_CONNECTING:
@@ -446,6 +455,7 @@ void ntripClientUpdate()
446455

447456
//We don't use a task because we use I2C hardware (and don't have a semphore).
448457
online.ntripClient = true;
458+
ntripClientStartTime = millis();
449459
ntripClientAllowMoreConnections();
450460
ntripClientSetState(NTRIP_CLIENT_CONNECTED);
451461
}

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ bool ntripServerConnectCaster()
101101
if (token != NULL)
102102
{
103103
token = strtok(NULL, "//"); //Advance to data after //
104-
if(token != NULL)
104+
if (token != NULL)
105105
strcpy(settings.ntripServer_CasterHost, token);
106106
}
107107

@@ -358,22 +358,30 @@ void ntripServerUpdate()
358358

359359
//Start WiFi
360360
case NTRIP_SERVER_ON:
361-
//Pause until connection timeout has passed
362-
if (millis() - ntripServerLastConnectionAttempt > ntripServerConnectionAttemptTimeout)
361+
if (strlen(settings.ntripServer_wifiSSID) == 0)
363362
{
364-
ntripServerLastConnectionAttempt = millis();
365-
wifiStart(settings.ntripServer_wifiSSID, settings.ntripServer_wifiPW);
366-
ntripServerSetState(NTRIP_SERVER_WIFI_CONNECTING);
363+
Serial.println("Error: Please enter SSID before starting NTRIP Server");
364+
ntripClientSetState(NTRIP_SERVER_OFF);
367365
}
368366
else
369367
{
370-
if (millis() - ntripServerTimeoutPrint > 1000)
368+
//Pause until connection timeout has passed
369+
if (millis() - ntripServerLastConnectionAttempt > ntripServerConnectionAttemptTimeout)
371370
{
372-
ntripServerTimeoutPrint = millis();
373-
Serial.printf("NTRIP Server connection timeout wait: %d of %d seconds \n\r",
374-
(millis() - ntripServerLastConnectionAttempt) / 1000,
375-
ntripServerConnectionAttemptTimeout / 1000
376-
);
371+
ntripServerLastConnectionAttempt = millis();
372+
wifiStart(settings.ntripServer_wifiSSID, settings.ntripServer_wifiPW);
373+
ntripServerSetState(NTRIP_SERVER_WIFI_CONNECTING);
374+
}
375+
else
376+
{
377+
if (millis() - ntripServerTimeoutPrint > 1000)
378+
{
379+
ntripServerTimeoutPrint = millis();
380+
Serial.printf("NTRIP Server connection timeout wait: %d of %d seconds \n\r",
381+
(millis() - ntripServerLastConnectionAttempt) / 1000,
382+
ntripServerConnectionAttemptTimeout / 1000
383+
);
384+
}
377385
}
378386
}
379387
break;

0 commit comments

Comments
 (0)