@@ -21,15 +21,15 @@ void updateEspnow()
21
21
#ifdef COMPILE_ESPNOW
22
22
if (settings.enableEspNow == true )
23
23
{
24
- if (espnowState == ESPNOW_PAIRED)
24
+ if (espnowState == ESPNOW_PAIRED || espnowState == ESPNOW_BROADCASTING )
25
25
{
26
26
// If it's been longer than a few ms since we last added a byte to the buffer
27
27
// then we've reached the end of the RTCM stream. Send partial buffer.
28
28
if (espnowOutgoingSpot > 0 && (millis () - espnowLastAdd) > 50 )
29
29
{
30
- if (settings. espnowBroadcast == false )
30
+ if (espnowState == ESPNOW_PAIRED )
31
31
esp_now_send (0 , (uint8_t *)&espnowOutgoing, espnowOutgoingSpot); // Send partial packet to all peers
32
- else
32
+ else // if (espnowState == ESPNOW_BROADCASTING)
33
33
{
34
34
uint8_t broadcastMac[6 ] = {0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
35
35
esp_now_send (broadcastMac, (uint8_t *)&espnowOutgoing,
@@ -189,8 +189,8 @@ void espnowStart()
189
189
// If WiFi is on but ESP NOW is off, then enable LR protocol
190
190
else if (wifiState > WIFI_STATE_OFF && espnowState == ESPNOW_OFF)
191
191
{
192
- // // Enable WiFi + ESP-Now
193
- // // Enable long range, PHY rate of ESP32 will be 512Kbps or 256Kbps
192
+ // Enable WiFi + ESP-Now
193
+ // Enable long range, PHY rate of ESP32 will be 512Kbps or 256Kbps
194
194
if (protocols != (WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR))
195
195
{
196
196
response = esp_wifi_set_protocol (WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N |
@@ -244,11 +244,35 @@ void espnowStart()
244
244
245
245
if (settings.espnowPeerCount == 0 )
246
246
{
247
- espnowSetState (ESPNOW_ON);
247
+ // Enter broadcast mode
248
+
249
+ uint8_t broadcastMac[6 ] = {0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
250
+
251
+ if (esp_now_is_peer_exist (broadcastMac) == true )
252
+ {
253
+ if (settings.debugEspNow == true )
254
+ systemPrintln (" Broadcast peer already exists" );
255
+ }
256
+ else
257
+ {
258
+ esp_err_t result = espnowAddPeer (broadcastMac, false ); // Encryption not support for broadcast MAC
259
+ if (result != ESP_OK)
260
+ {
261
+ if (settings.debugEspNow == true )
262
+ systemPrintln (" Failed to add broadcast peer" );
263
+ }
264
+ else
265
+ {
266
+ if (settings.debugEspNow == true )
267
+ systemPrintln (" Broadcast peer added" );
268
+ }
269
+ }
270
+
271
+ espnowSetState (ESPNOW_BROADCASTING);
248
272
}
249
273
else
250
274
{
251
- // If we already have peers, move to paired state
275
+ // If we have peers, move to paired state
252
276
espnowSetState (ESPNOW_PAIRED);
253
277
254
278
if (settings.debugEspNow == true )
@@ -273,32 +297,6 @@ void espnowStart()
273
297
}
274
298
}
275
299
276
- if (settings.espnowBroadcast == true )
277
- {
278
- // Add broadcast peer if override is turned on
279
- uint8_t broadcastMac[6 ] = {0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
280
-
281
- if (esp_now_is_peer_exist (broadcastMac) == true )
282
- {
283
- if (settings.debugEspNow == true )
284
- systemPrintln (" Broadcast peer already exists" );
285
- }
286
- else
287
- {
288
- esp_err_t result = espnowAddPeer (broadcastMac, false ); // Encryption not support for broadcast MAC
289
- if (result != ESP_OK)
290
- {
291
- if (settings.debugEspNow == true )
292
- systemPrintln (" Failed to add broadcast peer" );
293
- }
294
- else
295
- {
296
- if (settings.debugEspNow == true )
297
- systemPrintln (" Broadcast peer added" );
298
- }
299
- }
300
- }
301
-
302
300
systemPrintln (" ESP-Now Started" );
303
301
#endif // COMPILE_ESPNOW
304
302
}
@@ -401,13 +399,9 @@ bool espnowIsPaired()
401
399
#ifdef COMPILE_ESPNOW
402
400
if (espnowState == ESPNOW_MAC_RECEIVED)
403
401
{
404
-
405
- if (settings.espnowBroadcast == false )
406
- {
407
- // Remove broadcast peer
408
- uint8_t broadcastMac[6 ] = {0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
409
- espnowRemovePeer (broadcastMac);
410
- }
402
+ // Remove broadcast peer
403
+ uint8_t broadcastMac[6 ] = {0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
404
+ espnowRemovePeer (broadcastMac);
411
405
412
406
if (esp_now_is_peer_exist (receivedMAC) == true )
413
407
{
@@ -525,8 +519,8 @@ void espnowSetState(ESPNOWState newState)
525
519
case ESPNOW_OFF:
526
520
systemPrintln (" ESPNOW_OFF" );
527
521
break ;
528
- case ESPNOW_ON :
529
- systemPrintln (" ESPNOW_ON " );
522
+ case ESPNOW_BROADCASTING :
523
+ systemPrintln (" ESPNOW_BROADCASTING " );
530
524
break ;
531
525
case ESPNOW_PAIRING:
532
526
systemPrintln (" ESPNOW_PAIRING" );
@@ -547,31 +541,35 @@ void espnowSetState(ESPNOWState newState)
547
541
void espnowProcessRTCM (byte incoming)
548
542
{
549
543
#ifdef COMPILE_ESPNOW
550
- if (espnowState == ESPNOW_PAIRED)
544
+ // If we are paired,
545
+ // Or if the radio is broadcasting
546
+ // Then add bytes to the outgoing buffer
547
+ if (espnowState == ESPNOW_PAIRED || espnowState == ESPNOW_BROADCASTING)
551
548
{
552
549
// Move this byte into ESP NOW to send buffer
553
550
espnowOutgoing[espnowOutgoingSpot++] = incoming;
554
551
espnowLastAdd = millis ();
552
+ }
555
553
556
- if (espnowOutgoingSpot == sizeof (espnowOutgoing))
557
- {
558
- espnowOutgoingSpot = 0 ; // Wrap
554
+ // Send buffer when full
555
+ if (espnowOutgoingSpot == sizeof (espnowOutgoing))
556
+ {
557
+ espnowOutgoingSpot = 0 ; // Wrap
559
558
560
- if (settings. espnowBroadcast == false )
561
- esp_now_send (0 , (uint8_t *)&espnowOutgoing, sizeof (espnowOutgoing)); // Send packet to all peers
562
- else
563
- {
564
- uint8_t broadcastMac[6 ] = {0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
565
- esp_now_send (broadcastMac, (uint8_t *)&espnowOutgoing,
566
- sizeof (espnowOutgoing)); // Send packet via broadcast
567
- }
559
+ if (espnowState == ESPNOW_PAIRED )
560
+ esp_now_send (0 , (uint8_t *)&espnowOutgoing, sizeof (espnowOutgoing)); // Send packet to all peers
561
+ else // if (espnowState == ESPNOW_BROADCASTING)
562
+ {
563
+ uint8_t broadcastMac[6 ] = {0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
564
+ esp_now_send (broadcastMac, (uint8_t *)&espnowOutgoing,
565
+ sizeof (espnowOutgoing)); // Send packet via broadcast
566
+ }
568
567
569
- delay (10 ); // We need a small delay between sending multiple packets
568
+ delay (10 ); // We need a small delay between sending multiple packets
570
569
571
- espnowBytesSent += sizeof (espnowOutgoing);
570
+ espnowBytesSent += sizeof (espnowOutgoing);
572
571
573
- espnowOutgoingRTCM = true ;
574
- }
572
+ espnowOutgoingRTCM = true ;
575
573
}
576
574
#endif // COMPILE_ESPNOW
577
575
}
0 commit comments