Skip to content

Commit 1347cfb

Browse files
committed
ESP Now working. Fix Radio icons.
Added support for ESP Now Add WiFi RSSI to WiFi icon Add ESP Now RSSI to ESP Now Icon Add Up/Down arrow indication of RTCM to WiFi, BT, and ESP Now
1 parent 900eb53 commit 1347cfb

File tree

16 files changed

+524
-249
lines changed

16 files changed

+524
-249
lines changed

Firmware/RTK_Surveyor/Base.ino

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,6 @@ void SFE_UBLOX_GNSS::processRTCM(uint8_t incoming)
230230
ntripServerProcessRTCM(incoming);
231231

232232
#ifdef COMPILE_ESPNOW
233-
if (espnowState == ESPNOW_PAIRED)
234-
{
235-
//Move this byte into ESP NOW to send buffer
236-
espnowOutgoing[espnowOutgoingSpot++] = incoming;
237-
espnowLastAdd = millis();
238-
239-
if (espnowOutgoingSpot == sizeof(espnowOutgoing))
240-
{
241-
espnowOutgoingSpot = 0; //Wrap
242-
esp_now_send(0, (uint8_t *) &espnowOutgoing, sizeof(espnowOutgoing)); //Send packet to all peers
243-
delay(10); //We need a small delay between sending multiple packets
244-
log_d("ESPNOW: Sending %d bytes", sizeof(espnowOutgoing));
245-
}
246-
}
233+
espnowProcessRTCM(incoming);
247234
#endif
248235
}

Firmware/RTK_Surveyor/Bluetooth.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void bluetoothStop()
183183
reportHeapNow();
184184
}
185185
#endif //COMPILE_BT
186-
online.rxRtcmCorrectionData = false;
186+
bluetoothIncomingRTCM = false;
187187
}
188188

189189
//Write data to the Bluetooth device

Firmware/RTK_Surveyor/Display.ino

Lines changed: 450 additions & 217 deletions
Large diffs are not rendered by default.

Firmware/RTK_Surveyor/ESPNOW.ino

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void espnowOnDataRecieved(const uint8_t *mac, const uint8_t *incomingData, int l
6363
serialGNSS.write(incomingData, len);
6464
log_d("ESPNOW: Received %d bytes, RSSI: %d", len, espnowRSSI);
6565

66-
online.rxRtcmCorrectionData = true;
66+
espnowIncomingRTCM = true;
6767
lastEspnowRssiUpdate = millis();
6868
}
6969
}
@@ -327,4 +327,24 @@ void espnowSetState(ESPNOWState newState)
327327
}
328328
}
329329

330+
void espnowProcessRTCM(byte incoming)
331+
{
332+
if (espnowState == ESPNOW_PAIRED)
333+
{
334+
//Move this byte into ESP NOW to send buffer
335+
espnowOutgoing[espnowOutgoingSpot++] = incoming;
336+
espnowLastAdd = millis();
337+
338+
if (espnowOutgoingSpot == sizeof(espnowOutgoing))
339+
{
340+
espnowOutgoingSpot = 0; //Wrap
341+
esp_now_send(0, (uint8_t *) &espnowOutgoing, sizeof(espnowOutgoing)); //Send packet to all peers
342+
delay(10); //We need a small delay between sending multiple packets
343+
log_d("ESPNOW: Sending %d bytes", sizeof(espnowOutgoing));
344+
345+
espnowOutgoingRTCM = true;
346+
}
347+
}
348+
}
349+
330350
#endif //ifdef COMPILE_ESPNOW

Firmware/RTK_Surveyor/NtripClient.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void ntripClientStop(bool done)
290290
//Determine the next NTRIP client state
291291
ntripClientSetState((ntripClient && (!done)) ? NTRIP_CLIENT_ON : NTRIP_CLIENT_OFF);
292292
online.ntripClient = false;
293-
online.rxRtcmCorrectionData = false;
293+
wifiIncomingRTCM = false;
294294
#endif //COMPILE_WIFI
295295
}
296296

@@ -446,7 +446,7 @@ void ntripClientUpdate()
446446

447447
//Push RTCM to GNSS module over I2C
448448
i2cGNSS.pushRawData(rtcmData, rtcmCount);
449-
online.rxRtcmCorrectionData = true;
449+
wifiIncomingRTCM = true;
450450

451451
log_d("NTRIP Client pushed %d RTCM bytes to ZED", rtcmCount);
452452
}

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void ntripServerProcessRTCM(uint8_t incoming)
365365
ntripServer->write(incoming); //Send this byte to socket
366366
ntripServerBytesSent++;
367367
ntripServerTimer = millis();
368-
online.txNtripDataCasting = true;
368+
wifiOutgoingRTCM = true;
369369
}
370370
}
371371

@@ -445,7 +445,7 @@ void ntripServerUpdate()
445445
}
446446

447447
//If user turns off NTRIP Server via settings, stop server
448-
if (settings.enableNtripServer == false)
448+
if (settings.enableNtripServer == false && ntripServerState > NTRIP_SERVER_OFF)
449449
ntripServerStop(true); //Don't allocate new wifiClient
450450

451451
//Enable WiFi and the NTRIP server if requested

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const int FIRMWARE_VERSION_MINOR = 4;
2828
#define COMPILE_WIFI //Comment out to remove WiFi functionality
2929
#define COMPILE_BT //Comment out to remove Bluetooth functionality
3030
#define COMPILE_AP //Comment out to remove Access Point functionality
31-
//#define COMPILE_ESPNOW //Comment out to remove ESP-Now functionality
31+
#define COMPILE_ESPNOW //Comment out to remove ESP-Now functionality
3232
#define ENABLE_DEVELOPER //Uncomment this line to enable special developer modes (don't check power button at startup)
3333

3434
//Define the RTK board identifier:
@@ -151,6 +151,8 @@ LoggingType loggingType = LOGGING_UNKNOWN;
151151
#include <WiFiClientSecure.h> //Built-in.
152152
#include <PubSubClient.h> //Built-in. Used for MQTT obtaining of keys
153153

154+
#include "esp_wifi.h" //Needed for esp_wifi_set_protocol()
155+
154156
#include "base64.h" //Built-in. Needed for NTRIP Client credential encoding.
155157

156158
#endif
@@ -351,7 +353,6 @@ float lBandEBNO = 0.0; //Used on system status menu
351353
#ifdef COMPILE_ESPNOW
352354

353355
#include <esp_now.h>
354-
#include "esp_wifi.h" //Needed for esp_wifi_set_protocol()
355356

356357
uint8_t espnowOutgoing[250]; //ESP NOW has max of 250 characters
357358
unsigned long espnowLastAdd; //Tracks how long since last byte was added to the outgoing buffer
@@ -456,6 +457,20 @@ uint32_t max_idle_count = MAX_IDLE_TIME_COUNT;
456457

457458
unsigned long lastWifiRSSIUpdate = 0; //Print RSSI when connected every few seconds
458459

460+
bool firstRadioSpotBlink = false; //Controls when the shared icon space is toggled
461+
unsigned long firstRadioSpotTimer = 0;
462+
bool secondRadioSpotBlink = false; //Controls when the shared icon space is toggled
463+
unsigned long secondRadioSpotTimer = 0;
464+
bool thirdRadioSpotBlink = false; //Controls when the shared icon space is toggled
465+
unsigned long thirdRadioSpotTimer = 0;
466+
467+
bool bluetoothIncomingRTCM = false;
468+
bool bluetoothOutgoingRTCM = false;
469+
bool wifiIncomingRTCM = false;
470+
bool wifiOutgoingRTCM = false;
471+
bool espnowIncomingRTCM = false;
472+
bool espnowOutgoingRTCM = false;
473+
459474
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
460475
/*
461476
+---------------------------------------+ +----------+
@@ -552,7 +567,7 @@ void setup()
552567

553568
loadSettings(); //Attempt to load settings after SD is started so we can read the settings file if available
554569

555-
beginIdleTasks(); //Enable processor load calculations
570+
//beginIdleTasks(); //Enable processor load calculations
556571

557572
beginUART2(); //Start UART2 on core 0, used to receive serial from ZED and pass out over SPP
558573

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ void F9PSerialWriteTask(void *e)
1414
{
1515
//Pass bytes to GNSS receiver
1616
int s = bluetoothReadBytes(wBuffer, sizeof(wBuffer));
17+
18+
//TODO - control if this RTCM source should be listened to or not
1719
serialGNSS.write(wBuffer, s);
18-
online.rxRtcmCorrectionData = true;
20+
bluetoothIncomingRTCM = true;
1921

2022
if (settings.enableTaskReports == true)
2123
Serial.printf("SerialWriteTask High watermark: %d\n\r", uxTaskGetStackHighWaterMark(NULL));
@@ -172,7 +174,11 @@ void F9PSerialReadTask(void *e)
172174
//Push new data to BT SPP if not congested or not throttling
173175
btBytesToSend = bluetoothWriteBytes(&rBuffer[btTail], btBytesToSend);
174176
if (btBytesToSend > 0)
175-
online.txNtripDataCasting = true;
177+
{
178+
//If we are in base mode, assume part of the outgoing data is RTCM
179+
if(systemState >= STATE_BASE_NOT_STARTED && systemState <= STATE_BASE_FIXED_TRANSMITTING)
180+
bluetoothOutgoingRTCM = true;
181+
}
176182
else
177183
log_w("BT failed to send");
178184
}

Firmware/RTK_Surveyor/WiFi.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
WIFI_OFF
1818
| ^
19-
Use WiFi | |
19+
Use WiFi | |
2020
| | WL_CONNECT_FAILED (Bad password)
2121
| | WL_NO_SSID_AVAIL (Out of range)
2222
v |
@@ -219,7 +219,11 @@ void wifiStart(char* ssid, char* pw)
219219
{
220220
//Radio is off, turn it on
221221
WiFi.mode(WIFI_STA);
222+
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
222223
}
224+
#else
225+
//Be sure the standard protocols are turned on. ESP Now have have previously turned them off.
226+
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
223227
#endif
224228

225229
Serial.printf("Wi-Fi connecting to %s\r\n", ssid);

Firmware/RTK_Surveyor/icons.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,22 @@ int BT_Symbol_Width = 7;
4141
4242
*/
4343

44-
uint8_t WiFi_Symbol [] = {
44+
uint8_t WiFi_Symbol_3 [] = {
4545
0x08, 0x04, 0x12, 0x09, 0x25, 0x95, 0xD5, 0x95, 0x25, 0x09, 0x12, 0x04, 0x08, 0x00, 0x00, 0x00,
4646
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4747
};
48+
uint8_t WiFi_Symbol_2 [] = {
49+
0x00, 0x00, 0x10, 0x08, 0x24, 0x94, 0xD4, 0x94, 0x24, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
50+
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51+
};
52+
uint8_t WiFi_Symbol_1 [] = {
53+
0x00, 0x00, 0x00, 0x00, 0x20, 0x90, 0xD0, 0x90, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54+
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55+
};
56+
uint8_t WiFi_Symbol_0 [] = {
57+
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58+
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59+
};
4860
int WiFi_Symbol_Height = 9;
4961
int WiFi_Symbol_Width = 13;
5062

0 commit comments

Comments
 (0)