Skip to content

Commit 3385a5d

Browse files
committed
Add compile guards for disabling WiFi/Bluetooth
This is handy for debugging other aspects of the system. Firmware is normally 1,501,618 bytes. With BT off: 888,850. With both BT and WiFi off: 454950. This helps reduce compile and upload times.
1 parent c9814e0 commit 3385a5d

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

Firmware/RTK_Surveyor/Base.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,12 @@ void SFE_UBLOX_GNSS::processRTCM(uint8_t incoming)
196196
if (rtcmPacketsSent > 9999) rtcmPacketsSent = 1;
197197
}
198198

199+
#ifdef COMPILE_WIFI
199200
if (caster.connected() == true)
200201
{
201202
caster.write(incoming); //Send this byte to socket
202203
casterBytesSent++;
203204
lastServerSent_ms = millis();
204205
}
206+
#endif
205207
}

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,15 @@ const TickType_t fatSemaphore_longWait_ms = 200 / portTICK_PERIOD_MS;
118118

119119
//Connection settings to NTRIP Caster
120120
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
121+
122+
//#define COMPILE_WIFI 1 //Comment out to remove all WiFi functionality
123+
124+
#ifdef COMPILE_WIFI
121125
#include <WiFi.h>
122126
#include "esp_wifi.h" //Needed for init/deinit of resources to free up RAM
123127

124128
WiFiClient caster;
129+
#endif
125130
const char * ntrip_server_name = "SparkFun_RTK_Surveyor";
126131

127132
unsigned long lastServerSent_ms = 0; //Time of last data pushed to caster
@@ -184,10 +189,15 @@ float battChangeRate = 0.0;
184189
//Hardware serial and BT buffers
185190
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
186191
//We use a local copy of the BluetoothSerial library so that we can increase the RX buffer. See issue: https://github.com/sparkfun/SparkFun_RTK_Surveyor/issues/18
192+
193+
//#define COMPILE_BT 1 //Comment out to disable all Bluetooth
194+
195+
#ifdef COMPILE_BT
187196
#include "src/BluetoothSerial/BluetoothSerial.h"
188197
BluetoothSerial SerialBT;
189198
#include "esp_bt.h" //Core access is needed for BT stop. See customBTstop() for more info.
190199
#include "esp_gap_bt_api.h" //Needed for setting of pin. See issue: https://github.com/sparkfun/SparkFun_RTK_Surveyor/issues/5
200+
#endif
191201

192202
char platformPrefix[40] = "Surveyor"; //Sets the prefix for broadcast names
193203

Firmware/RTK_Surveyor/States.ino

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ void updateSystemState()
225225
//Check to see if we have connected over WiFi
226226
case (STATE_BASE_TEMP_WIFI_STARTED):
227227
{
228+
#ifdef COMPILE_WIFI
228229
byte wifiStatus = WiFi.status();
229230
if (wifiStatus == WL_CONNECTED)
230231
{
@@ -249,6 +250,7 @@ void updateSystemState()
249250
}
250251
delay(1000);
251252
}
253+
#endif
252254
}
253255
break;
254256

@@ -264,6 +266,7 @@ void updateSystemState()
264266
if (settings.enableNtripServer == true)
265267
{
266268
//Open connection to caster service
269+
#ifdef COMPILE_WIFI
267270
if (caster.connect(settings.casterHost, settings.casterPort) == true) //Attempt connection
268271
{
269272
changeState(STATE_BASE_TEMP_CASTER_STARTED);
@@ -281,13 +284,15 @@ void updateSystemState()
281284

282285
casterResponseWaitStartTime = millis();
283286
}
287+
#endif
284288
}
285289
}
286290
break;
287291

288292
//Wait for response for caster service and make sure it's valid
289293
case (STATE_BASE_TEMP_CASTER_STARTED):
290294
{
295+
#ifdef COMPILE_WIFI
291296
//Check if caster service responded
292297
if (caster.available() == 0)
293298
{
@@ -335,6 +340,7 @@ void updateSystemState()
335340
changeState(STATE_BASE_TEMP_CASTER_CONNECTED);
336341
}
337342
}
343+
#endif
338344
}
339345
break;
340346

@@ -343,11 +349,13 @@ void updateSystemState()
343349
{
344350
cyclePositionLEDs();
345351

352+
#ifdef COMPILE_WIFI
346353
if (caster.connected() == false)
347354
{
348355
Serial.println(F("Caster no longer connected. Reconnecting..."));
349356
changeState(STATE_BASE_TEMP_WIFI_CONNECTED); //Return to 2 earlier states to try to reconnect
350357
}
358+
#endif
351359
}
352360
break;
353361

@@ -392,6 +400,7 @@ void updateSystemState()
392400
//Check to see if we have connected over WiFi
393401
case (STATE_BASE_FIXED_WIFI_STARTED):
394402
{
403+
#ifdef COMPILE_WIFI
395404
byte wifiStatus = WiFi.status();
396405
if (wifiStatus == WL_CONNECTED)
397406
{
@@ -416,6 +425,7 @@ void updateSystemState()
416425
}
417426
delay(1000);
418427
}
428+
#endif
419429
}
420430
break;
421431

@@ -429,6 +439,7 @@ void updateSystemState()
429439
}
430440
if (settings.enableNtripServer == true)
431441
{
442+
#ifdef COMPILE_WIFI
432443
//Open connection to caster service
433444
if (caster.connect(settings.casterHost, settings.casterPort) == true) //Attempt connection
434445
{
@@ -447,13 +458,15 @@ void updateSystemState()
447458

448459
casterResponseWaitStartTime = millis();
449460
}
461+
#endif
450462
}
451463
}
452464
break;
453465

454466
//Wait for response for caster service and make sure it's valid
455467
case (STATE_BASE_FIXED_CASTER_STARTED):
456468
{
469+
#ifdef COMPILE_WIFI
457470
//Check if caster service responded
458471
if (caster.available() < 10)
459472
{
@@ -502,6 +515,7 @@ void updateSystemState()
502515
changeState(STATE_BASE_FIXED_CASTER_CONNECTED);
503516
}
504517
}
518+
#endif
505519
}
506520
break;
507521

@@ -510,10 +524,12 @@ void updateSystemState()
510524
{
511525
cyclePositionLEDs();
512526

527+
#ifdef COMPILE_WIFI
513528
if (caster.connected() == false)
514529
{
515530
changeState(STATE_BASE_FIXED_WIFI_CONNECTED);
516531
}
532+
#endif
517533
}
518534
break;
519535

Firmware/RTK_Surveyor/System.ino

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//This allows multiple units to be on at same time
44
bool startBluetooth()
55
{
6+
#ifdef COMPILE_BT
7+
68
//Get unit MAC address
79
esp_read_mac(unitMACAddress, ESP_MAC_WIFI_STA);
810
unitMACAddress[5] += 2; //Convert MAC address to Bluetooth MAC (add 2): https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
@@ -78,6 +80,7 @@ bool startBluetooth()
7880
//Start task for controlling Bluetooth pair LED
7981
if (productVariant == RTK_SURVEYOR)
8082
btLEDTask.attach(btLEDTaskPace, updateBTled); //Rate in seconds, callback
83+
#endif
8184

8285
return (true);
8386
}
@@ -98,9 +101,11 @@ void endBluetooth()
98101
F9PSerialWriteTaskHandle = NULL;
99102
}
100103

104+
#ifdef COMPILE_BT
101105
SerialBT.flush(); //Complete any transfers
102106
SerialBT.disconnect(); //Drop any clients
103107
SerialBT.end(); //SerialBT.end() will release significant RAM (~100k!) but a SerialBT.start will crash.
108+
#endif
104109

105110
//The following code releases the BT hardware so that it can be restarted with a SerialBT.begin
106111
customBTstop();
@@ -113,7 +118,7 @@ void endBluetooth()
113118
//To work around the bug without modifying the core we create our own btStop() function with
114119
//the patch from github
115120
bool customBTstop() {
116-
121+
#ifdef COMPILE_BT
117122
if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE) {
118123
return true;
119124
}
@@ -137,18 +142,21 @@ bool customBTstop() {
137142
return true;
138143
}
139144
log_e("BT Stop failed");
145+
#endif
140146
return false;
141147
}
142148

143149
//Start WiFi assuming it was previously fully released
144150
//See WiFiBluetoothSwitch sketch for more info
145151
void startWiFi()
146152
{
153+
#ifdef COMPILE_WIFI
147154
wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
148155
esp_wifi_init(&wifi_init_config); //Restart WiFi resources
149156

150157
Serial.printf("Connecting to local WiFi: %s\n\r", settings.wifiSSID);
151158
WiFi.begin(settings.wifiSSID, settings.wifiPW);
159+
#endif
152160

153161
radioState = WIFI_ON_NOCONNECTION;
154162
}
@@ -157,9 +165,12 @@ void startWiFi()
157165
//See WiFiBluetoothSwitch sketch for more info
158166
void stopWiFi()
159167
{
168+
#ifdef COMPILE_WIFI
160169
caster.stop();
161170
WiFi.mode(WIFI_OFF);
162171
esp_wifi_deinit(); //Free all resources
172+
#endif
173+
163174
Serial.println("WiFi Stopped");
164175

165176
radioState = RADIO_OFF;
@@ -506,6 +517,7 @@ void danceLEDs()
506517

507518
//Call back for when BT connection event happens (connected/disconnect)
508519
//Used for updating the radioState state machine
520+
#ifdef COMPILE_BT
509521
void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
510522
if (event == ESP_SPP_SRV_OPEN_EVT) {
511523
Serial.println(F("Client Connected"));
@@ -521,6 +533,7 @@ void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
521533
digitalWrite(pin_bluetoothStatusLED, LOW);
522534
}
523535
}
536+
#endif
524537

525538
//Update Battery level LEDs every 5s
526539
void updateBattLEDs()

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ void F9PSerialWriteTask(void *e)
77
{
88
while (true)
99
{
10+
#ifdef COMPILE_BT
1011
//Receive RTCM corrections or UBX config messages over bluetooth and pass along to ZED
1112
while (SerialBT.available())
1213
{
@@ -27,6 +28,7 @@ void F9PSerialWriteTask(void *e)
2728
incomingBTTest = incoming; //Displayed during system test
2829
}
2930
}
31+
#endif
3032

3133
taskYIELD();
3234
}
@@ -48,6 +50,7 @@ void F9PSerialReadTask(void *e)
4850
//Do nothing
4951
taskYIELD();
5052
}
53+
#ifdef COMPILE_BT
5154
else if (SerialBT.connected())
5255
{
5356
if (SerialBT.isCongested() == false)
@@ -64,6 +67,7 @@ void F9PSerialReadTask(void *e)
6467
log_d("Dropped SPP Bytes: %d", s);
6568
}
6669
}
70+
#endif
6771

6872
if (settings.enableTaskReports == true)
6973
Serial.printf("SerialReadTask High watermark: %d\n\r", uxTaskGetStackHighWaterMark(NULL));

0 commit comments

Comments
 (0)