33#include < esp_wifi.h>
44
55// REPLACE WITH YOUR RECEIVER MAC Address
6- uint8_t broadcastAddress[] = {0xC8 , 0xF0 , 0x9E , 0x19 , 0x88 , 0x80 };
6+ uint8_t broadcastAddress[] = {0xFC , 0xE8 , 0xC0 , 0x4A , 0x01 , 0x64 };
7+ // uint8_t broadcastAddress[] = {0xC8, 0xF0, 0x9E, 0x19, 0x88, 0x80};
8+
79
810// Structure example to send data
911// Must match the receiver structure
@@ -31,6 +33,9 @@ uint8_t channel = 0;
3133bool isHubChannelFound = false ;
3234uint8_t failureCount = 0 ;
3335
36+ uint32_t totalSent = 0 ;
37+ uint32_t totalFailure = 0 ;
38+
3439// callback when data is sent
3540void OnDataSent (const uint8_t *mac_addr, esp_now_send_status_t status) {
3641 Serial.print (" \r\n Last Packet Send Status:\t " );
@@ -47,6 +52,7 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
4752 esp_wifi_set_channel (channel, WIFI_SECOND_CHAN_NONE);
4853 esp_wifi_set_promiscuous (false );
4954 } else {
55+ totalFailure++;
5056 // If the hub channel has been found before but we have failures now
5157 // we give the hub some time before we start searching the channel again
5258 // This might avoid all nodes starting the channel search immediatelly
@@ -58,8 +64,12 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
5864
5965 } else {
6066 failureCount = 0 ;
61- isHubChannelFound = true ;
67+ if (!isHubChannelFound) {
68+ isHubChannelFound = true ;
69+ log_i (" *** Channel locked at %d ***" , channel);
70+ }
6271 }
72+ totalSent++;
6373}
6474
6575void setup () {
@@ -124,16 +134,18 @@ void loop() {
124134 // Send message via ESP-NOW
125135 esp_err_t result = esp_now_send (broadcastAddress, (uint8_t *) &myData, sizeof (myData));
126136
127- if (result == ESP_OK) {
137+ /* if (result == ESP_OK) {
128138 log_i("Sent with success");
129139 } else {
130140 log_i("Error sending the data");
131- }
141+ }*/
142+
143+ log_i (" Total messages: %d, failures: %d, channel: %d" , totalSent, totalFailure, channel);
132144
133145 if (isHubChannelFound) {
134146 delay (2000 );
135147 } else {
136- delay (100 );
148+ delay (1000 );
137149 }
138150
139151}
0 commit comments