Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP-NOW strategy support for esp8266 #361

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Re-enabling error logging, updating readme
  • Loading branch information
Strix-CZ committed Aug 9, 2020
commit 94e5b67a60e191a1982c4d33779a121af6490cba
26 changes: 16 additions & 10 deletions src/strategies/ESPNOW/ESPNOW.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class ESPNOW {
PJONTools::parse_header(message, packet_info);
uint8_t sender_id = packet_info.tx.id;
if(sender_id == 0) {
//ESP_LOGE("ESPNOW", "AutoRegister parsing failed");
#if defined(ESP32)
ESP_LOGE("ESPNOW", "AutoRegister parsing failed");
#endif
return; // If parsing fails, it will be 0
}

Expand All @@ -87,19 +89,23 @@ class ESPNOW {
// See if PJON id is already registered, add if not
int16_t pos = find_remote_node(sender_id);
if(pos == -1) {
//ESP_LOGI("ESPNOW", "Autoregister new sender %d",sender_id);
#if defined(ESP32)
ESP_LOGI("ESPNOW", "Autoregister new sender %d",sender_id);
#endif
add_node(sender_id, sender_mac);
}
else if(memcmp(_remote_mac[pos], sender_mac, ESP_NOW_ETH_ALEN) != 0) {
// Update mac of existing node
/*ESP_LOGI(
"ESPNOW",
"Update sender mac %d %d:%d:%d",
sender_id,
sender_mac[1],
sender_mac[2],
sender_mac[3]
);*/
#if defined(ESP32)
ESP_LOGI(
"ESPNOW",
"Update sender mac %d %d:%d:%d",
sender_id,
sender_mac[1],
sender_mac[2],
sender_mac[3]
);
#endif
memcpy(_remote_mac[pos], sender_mac, ESP_NOW_ETH_ALEN);
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/strategies/ESPNOW/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
|--------|-----------|--------------------|
| ESPNOW over WiFi | NA | `#include <PJONESPNOW.h>` |

With the `ESPNOW` PJON strategy, up to 10 ESP32 devices can use PJON to communicate with each other over
With the `ESPNOW` PJON strategy, up to 10 ESP32 or ESP8266 devices can use PJON to communicate with each other over
the [Espressif ESPNOW protocol](https://www.espressif.com/en/products/software/esp-now/overview) (peer-to-peer 802.11).

PJON over ESPNOW has the following benefits:
Expand Down Expand Up @@ -38,6 +38,13 @@ void setup() {
}
```

You can also choose between Access Point and Station mode. To switch to Station mode, define CONFIG_STATION_MODE before
including PJONESPNOW.h.
```cpp
#define CONFIG_STATION_MODE
#include <PJONESPNOW.h>
```

The ESPNOW strategy will send a broadcast message if the device_id is not already registered. Once a response is received (assuming auto-registration is enabled) the device automatically adds the node id and mac in its table. Sender auto-registration is enabled by default and can be disabled using the following setter:

```cpp
Expand Down