PlatformIO Community

How to use "ESP NOW" with PlatformIO's default libraries?

I am trying to test ESP NOW with two 8266 boards by following this website. The sample code starts with

#include <esp_now.h>
#include <WiFi.h>

but it seems that my PlatformIO does not find such files. Using IntelliSense, I chose the closest ones <espnow.h> and <ESP8266WiFi.h>, and I added <Esp.h> just in case, but as I expected, the code below did not compile. Is there an “ESP NOW” example that works with the default libraries that come with the PlatformIO?

If that is not possible, how can I get the “esp_now.h” and “WiFi.h” that the example of that website uses? The page only says this and does not explain how to get those.

image

Compile errors

image
image
image
image

Based on how you use esp_now_send_status_t etc. it looks like you’re attempting to use the ESP32’s version of espnow on your ESP8266.

Arduino-ESP32’s SDK file has esp_now_send_status_t in esp_now.h

Arduino-ESP8266 does not. Also the header file is called espnow.h there.

Careful to use the correct library and APIs. You can’t write code against ESP32 libs on an ESP8266.

Just use the reference code at Getting Started with ESP-NOW (ESP8266 NodeMCU with Arduino IDE) | Random Nerd Tutorials.

Note that Arduino-ESP8266 also features a ESP8266WiFiMesh library with an espnow example.

Thanks. You were right that the example was for ESP32. The website had a separate page for ESP8266 version, so I switched to that example, and that removed a lot of errors.

However, there still are a few errors, and I do not know why they do not compile. To me, they look like correct code. Could you tell me what this “XXX cannot be used as a function” error means?
image

That function was defined in “espnow.h” like so:
image

The only weird thing about that header file is that it has the following error. Is that related to the “XXX cannot be used as a function” error above?
image

One has to differentiate what VSCode highlights as errors and what is an actual compile error thrown by GCC when PlatformIO tells it to compile stuff.

Does it compile? What’s the error message if not?

If it does compile, the fault is purely in the intellisense.

Solved it. The sample code was

#include <ESP8266WiFi.h>
#include <espnow.h>

and I had used (used the same lines from my old code above)

#include <espnow.h>
#include <ESP8266WiFi.h>

. I changed the order of the two header files, and now the complication succeeded.

1 Like