Skip to content

Commit 459f543

Browse files
committed
Begin adding Pair submenu
1 parent fe7205c commit 459f543

File tree

6 files changed

+60
-49
lines changed

6 files changed

+60
-49
lines changed

Firmware/RTK_Surveyor/ESPNOW.ino

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void espnowStart()
149149
//If WiFi is off, stop the radio entirely
150150
void espnowStop()
151151
{
152-
if(espnowState == ESPNOW_OFF) return;
152+
if (espnowState == ESPNOW_OFF) return;
153153

154154
if (wifiState == WIFI_OFF)
155155
{
@@ -184,7 +184,7 @@ void espnowStop()
184184
Serial.println("ESP NOW Off");
185185
}
186186

187-
//Begin broadcasting our MAC and wait for remote unit to respond
187+
//Start ESP-Now if needed, put ESP-Now into broadcast state
188188
void espnowBeginPairing()
189189
{
190190
espnowStart();
@@ -194,55 +194,37 @@ void espnowBeginPairing()
194194
espnowAddPeer(broadcastMac, false); // Encryption is not supported for multicast addresses
195195

196196
espnowSetState(ESPNOW_PAIRING);
197+
}
197198

198-
//Begin sending our MAC every 250ms until a remote device sends us there info
199-
randomSeed(millis());
200-
201-
Serial.println("Begin pairing. Place other unit in pairing mode. Press any key to exit.");
202-
while (Serial.available()) Serial.read();
203-
204-
while (1)
199+
//Regularly call during pairing to see if we've received a Pairing message
200+
bool espnowIsPaired()
201+
{
202+
if (espnowState == ESPNOW_MAC_RECEIVED)
205203
{
206-
if (Serial.available()) break;
204+
//Remove broadcast peer
205+
espnowRemovePeer(broadcastMac);
207206

208-
int timeout = 1000 + random(0, 100); //Delay 1000 to 1100ms
209-
for (int x = 0 ; x < timeout ; x++)
207+
if (esp_now_is_peer_exist(receivedMAC) == true)
208+
log_d("Peer already exists");
209+
else
210210
{
211-
delay(1);
211+
//Add new peer to system
212+
espnowAddPeer(receivedMAC);
212213

213-
if (espnowState == ESPNOW_MAC_RECEIVED)
214-
{
215-
//Remove broadcast peer
216-
espnowRemovePeer(broadcastMac);
217-
218-
if (esp_now_is_peer_exist(receivedMAC) == true)
219-
log_d("Peer already exists");
220-
else
221-
{
222-
//Add new peer to system
223-
espnowAddPeer(receivedMAC);
224-
225-
//Record this MAC to peer list
226-
memcpy(settings.espnowPeers[settings.espnowPeerCount], receivedMAC, 6);
227-
settings.espnowPeerCount++;
228-
settings.espnowPeerCount %= ESPNOW_MAX_PEERS;
229-
}
230-
231-
//Send message directly to the received MAC (not unicast), then exit
232-
espnowSendPairMessage(receivedMAC);
233-
234-
espnowSetState(ESPNOW_PAIRED);
235-
Serial.println("Pairing compete");
236-
return;
237-
}
214+
//Record this MAC to peer list
215+
memcpy(settings.espnowPeers[settings.espnowPeerCount], receivedMAC, 6);
216+
settings.espnowPeerCount++;
217+
settings.espnowPeerCount %= ESPNOW_MAX_PEERS;
238218
}
239219

240-
espnowSendPairMessage(broadcastMac); //Send unit's MAC address over broadcast, no ack, no encryption
220+
//Send message directly to the received MAC (not unicast), then exit
221+
espnowSendPairMessage(receivedMAC);
241222

242-
Serial.println("Scanning for other radio...");
223+
espnowSetState(ESPNOW_PAIRED);
224+
Serial.println("Pairing compete");
225+
return(true);
243226
}
244-
245-
Serial.println("User pressed button. Pairing canceled.");
227+
return(false);
246228
}
247229

248230
//Create special pair packet to a given MAC

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ void ntripServerUpdate()
581581
Serial.println("NTRIP Server connection dropped");
582582
ntripServerStop(false); //Allocate new wifiClient
583583
}
584-
else if ((millis() - ntripServerTimer) > 1000)
584+
else if ((millis() - ntripServerTimer) > 3000)
585585
{
586586
//GNSS stopped sending RTCM correction data
587587
Serial.println("NTRIP Server breaking caster connection due to lack of RTCM data!");

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ bool espnowOutgoingRTCM = false;
467467
| RTCM |--->|-->| |--------->| |-->|----->|TXD, MISO | |
468468
| | | | Bluetooth | | UART 2 | | | UART1 | |
469469
| NMEA + RTCM |<---|<--| |<-------+-| |<--|<-----|RXD, MOSI |<----'
470-
+-------------+ | '-----------' | '--------' |28 42| |
470+
+-------------+ | '-----------' | '--------' |28 43| |
471471
| | | | |
472472
.---------+ | | | | |
473473
/ uSD Card | | | | | |

Firmware/RTK_Surveyor/States.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,8 @@ void updateSystemState()
902902

903903
case (STATE_ESPNOW_PAIR):
904904
{
905-
if(espnowState == ESPNOW_OFF)
906-
{
907-
espnowBeginPairing();
908-
}
905+
906+
espnowIsPaired()
909907

910908
//Display 'ESP-Now Pairing' while we wait
911909
}

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,11 @@ void ButtonCheckTask(void *e)
618618
}
619619
}
620620

621+
TODO once a user has selected 'Pair', send this once
622+
//Start ESP-Now if needed, put ESP-Now into broadcast state
623+
espnowBeginPairing();
624+
625+
621626
void idleTask(void *e)
622627
{
623628
int cpu = xPortGetCoreID();

Firmware/RTK_Surveyor/menuMain.ino

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void menuRadio()
334334
}
335335
else
336336
Serial.println(" No Paired Radios");
337-
337+
338338

339339
Serial.println("2) Pair radios");
340340
Serial.println("3) Forget all radios");
@@ -352,7 +352,33 @@ void menuRadio()
352352
else if (settings.radioType == RADIO_ESPNOW && incoming == 2)
353353
{
354354
Serial.println("Begin ESP NOW Pairing");
355+
356+
//Start ESP-Now if needed, put ESP-Now into broadcast state
355357
espnowBeginPairing();
358+
359+
//Begin sending our MAC every 250ms until a remote device sends us there info
360+
randomSeed(millis());
361+
362+
Serial.println("Begin pairing. Place other unit in pairing mode. Press any key to exit.");
363+
while (Serial.available()) Serial.read();
364+
365+
while (1)
366+
{
367+
if (Serial.available()) break;
368+
369+
int timeout = 1000 + random(0, 100); //Delay 1000 to 1100ms
370+
for (int x = 0 ; x < timeout ; x++)
371+
{
372+
delay(1);
373+
if (espnowIsPaired()) break; //Check if we've received a pairing message
374+
}
375+
376+
espnowSendPairMessage(broadcastMac); //Send unit's MAC address over broadcast, no ack, no encryption
377+
378+
Serial.println("Scanning for other radio...");
379+
}
380+
381+
Serial.println("User pressed button. Pairing canceled.");
356382
}
357383
else if (settings.radioType == RADIO_ESPNOW && incoming == 3)
358384
{

0 commit comments

Comments
 (0)