Skip to content

Commit ba5fa40

Browse files
committed
Add stop if NTRIP Server is disabled. Separate Bluetooth start/stop from WiFi and ntripServer.
1 parent 0011f99 commit ba5fa40

File tree

3 files changed

+29
-43
lines changed

3 files changed

+29
-43
lines changed

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22
NTRIP Server States:
3-
NTRIP_SERVER_OFF: Using Bluetooth or NTRIP server
3+
NTRIP_SERVER_OFF: WiFi OFF or using NTRIP Client
44
NTRIP_SERVER_ON: WIFI_ON state
55
NTRIP_SERVER_WIFI_CONNECTING: Connecting to WiFi access point
66
NTRIP_SERVER_WIFI_CONNECTED: WiFi connected to an access point
@@ -80,12 +80,6 @@ static uint32_t ntripServerTimer;
8080
// NTRIP Server Routines - compiled out
8181
//----------------------------------------
8282

83-
//Determine if more connections are allowed
84-
void ntripServerAllowMoreConnections()
85-
{
86-
ntripServerConnectionAttempts = 0;
87-
}
88-
8983
//Initiate a connection to the NTRIP caster
9084
bool ntripServerConnectCaster()
9185
{
@@ -122,18 +116,20 @@ bool ntripServerConnectCaster()
122116
bool ntripServerConnectLimitReached()
123117
{
124118
//Shutdown the NTRIP server
125-
ntripServerStop(false);
119+
ntripServerStop(false); //Allocate new wifiClient
126120

127121
//Retry the connection a few times
128-
bool limitReached = (ntripServerConnectionAttempts++ >= MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS);
122+
bool limitReached = false;
123+
if (ntripServerConnectionAttempts++ >= MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS) limitReached = true;
124+
129125
if (!limitReached)
130126
//Display the heap state
131127
reportHeapNow();
132128
else
133129
{
134-
//No more connection attempts, switching to Bluetooth
130+
//No more connection attempts
135131
Serial.println("NTRIP Server connection attempts exceeded!");
136-
ntripServerSwitchToBluetooth();
132+
ntripServerStop(true); //Don't allocate new wifiClient
137133
}
138134
return limitReached;
139135
}
@@ -308,19 +304,6 @@ void ntripServerSetState(byte newState)
308304
break;
309305
}
310306
}
311-
312-
//Switch to Bluetooth operation
313-
void ntripServerSwitchToBluetooth()
314-
{
315-
Serial.println("NTRIP Server failure, switching to Bluetooth!");
316-
317-
//Stop WiFi operations
318-
ntripServerStop(true);
319-
320-
//Turn on Bluetooth with 'Rover' name
321-
bluetoothStart();
322-
}
323-
324307
#endif // COMPILE_WIFI
325308

326309
//----------------------------------------
@@ -370,7 +353,7 @@ void ntripServerProcessRTCM(uint8_t incoming)
370353

371354
//Pass this message to the RTCM checker
372355
bool passAlongIncomingByte = true;
373-
356+
374357
//Check this byte with RTCM checker if enabled
375358
if (settings.enableNtripServerMessageParsing == true)
376359
passAlongIncomingByte &= ntripServerRtcmMessage(incoming);
@@ -400,15 +383,14 @@ void ntripServerStart()
400383
{
401384
#ifdef COMPILE_WIFI
402385
//Stop NTRIP server and WiFi
403-
ntripServerStop(true);
386+
ntripServerStop(true); //Don't allocate new wifiClient
404387

405388
//Start the NTRIP server if enabled
406389
if ((settings.ntripServer_StartAtSurveyIn == true)
407390
|| (settings.enableNtripServer == true))
408391
{
409392
//Display the heap state
410393
reportHeapNow();
411-
Serial.println("NTRIP Server start");
412394

413395
//Allocate the ntripServer structure
414396
ntripServer = new WiFiClient();
@@ -418,14 +400,12 @@ void ntripServerStart()
418400
ntripServerSetState(NTRIP_SERVER_ON);
419401
}
420402

421-
//Only fallback to Bluetooth once, then try WiFi again. This enables changes
422-
//to the WiFi SSID and password to properly restart the WiFi.
423-
ntripServerAllowMoreConnections();
403+
ntripServerConnectionAttempts = 0;
424404
#endif //COMPILE_WIFI
425405
}
426406

427407
//Stop the NTRIP server
428-
void ntripServerStop(bool done)
408+
void ntripServerStop(bool wifiClientAllocated)
429409
{
430410
#ifdef COMPILE_WIFI
431411
if (ntripServer)
@@ -439,7 +419,7 @@ void ntripServerStop(bool done)
439419
ntripServer = NULL;
440420

441421
//Allocate the NTRIP server structure if not done
442-
if (!done)
422+
if (wifiClientAllocated == false)
443423
ntripServer = new WiFiClient();
444424
}
445425

@@ -448,7 +428,7 @@ void ntripServerStop(bool done)
448428
wifiStop();
449429

450430
//Determine the next NTRIP server state
451-
ntripServerSetState((ntripServer && (!done)) ? NTRIP_SERVER_ON : NTRIP_SERVER_OFF);
431+
ntripServerSetState((ntripServer && (wifiClientAllocated == false)) ? NTRIP_SERVER_ON : NTRIP_SERVER_OFF);
452432
online.ntripServer = false;
453433
#endif //COMPILE_WIFI
454434
}
@@ -464,10 +444,13 @@ void ntripServerUpdate()
464444
ntripServerStateLastDisplayed = millis();
465445
}
466446

447+
//If user turns off NTRIP Server via settings, stop server
448+
if (settings.enableNtripServer == false)
449+
ntripServerStop(true); //Don't allocate new wifiClient
450+
467451
//Enable WiFi and the NTRIP server if requested
468452
switch (ntripServerState)
469453
{
470-
//Bluetooth enabled
471454
case NTRIP_SERVER_OFF:
472455
break;
473456

@@ -485,8 +468,10 @@ void ntripServerUpdate()
485468
{
486469
//Assume AP weak signal, the AP is unable to respond successfully
487470
if (ntripServerConnectLimitReached())
471+
{
488472
//Display the WiFi failure
489473
paintNtripWiFiFail(4000, false);
474+
}
490475
}
491476
}
492477
else
@@ -560,8 +545,7 @@ void ntripServerUpdate()
560545
//Look for '401 Unauthorized'
561546
Serial.printf("NTRIP Server caster responded with bad news: %s. Are you sure your caster credentials are correct?\n\r", response);
562547

563-
//Switch to Bluetooth operation
564-
ntripServerSwitchToBluetooth();
548+
ntripServerStop(true); //Don't allocate new wifiClient
565549
}
566550
else
567551
{
@@ -575,7 +559,7 @@ void ntripServerUpdate()
575559

576560
//We don't use a task because we use I2C hardware (and don't have a semphore).
577561
online.ntripServer = true;
578-
ntripServerAllowMoreConnections();
562+
ntripServerConnectionAttempts = 0;
579563
ntripServerSetState(NTRIP_SERVER_CASTING);
580564
}
581565
}
@@ -588,13 +572,13 @@ void ntripServerUpdate()
588572
{
589573
//Broken connection, retry the NTRIP server connection
590574
Serial.println("NTRIP Server connection dropped");
591-
ntripServerStop(false);
575+
ntripServerStop(false); //Allocate new wifiClient
592576
}
593577
else if ((millis() - ntripServerTimer) > 1000)
594578
{
595579
//GNSS stopped sending RTCM correction data
596580
Serial.println("NTRIP Server breaking caster connection due to lack of RTCM data!");
597-
ntripServerStop(false);
581+
ntripServerStop(false); //Allocate new wifiClient
598582
}
599583
else
600584
cyclePositionLEDs();

Firmware/RTK_Surveyor/States.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,11 @@ void updateSystemState()
236236

237237
displayBaseStart(0); //Show 'Base'
238238

239-
//Stop all WiFi and BT. Re-enable in each specific base start state.
240-
wifiStop();
239+
wifiStop(); //Stop WiFi. Re-enable in each specific base start state.
240+
241241
bluetoothStop();
242+
bluetoothStart(); //Restart Bluetooth with 'Base' identifier
243+
242244
startUART2Tasks(); //Start monitoring the UART1 from ZED for NMEA and UBX data (enables logging)
243245

244246
if (configureUbloxModuleBase() == true)

Firmware/RTK_Surveyor/WiFi.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
1515
WiFi Station States:
1616
17-
WIFI_OFF (Using Bluetooth)
17+
WIFI_OFF
1818
| ^
19-
Use WiFi | | Use Bluetooth
19+
Use WiFi | |
2020
| | WL_CONNECT_FAILED (Bad password)
2121
| | WL_NO_SSID_AVAIL (Out of range)
2222
v |

0 commit comments

Comments
 (0)