I was going to try experimenting with ESP-Now (Espressif’s lightweight wireless protocol which uses a minimal networking stack to provide minimal, point-to-point communications between ESP modules), as it promises a very much faster start-up and delivery for short messages for things like dedicated battery-powered sensors which only send very limited amounts of data. There are a few examples out there; the most notable probably being HarringayMakerSpace’s ESP-Now Examples repository by Anthony (TornTrousers) Elder, which I promptly downloaded.
I’m using PlatformIO as my build environment, mainly because I feel more comfortable using the command line, but also because it generally just works. So, I created a new project directory with the BME sensor example and confidently connected up an ESP module to USB, ready to flash. Uh-uh! ’twas not to be. The compile went merrily along until it hit the linker section and then fell over in a messy heap, with:-
.pioenvs/nodemcuv2/src/espnow-sensor-bme280.ino.o:(.text.setup+0x1c): undefined reference to `esp_now_init'
.pioenvs/nodemcuv2/src/espnow-sensor-bme280.ino.o:(.text.setup+0x20): undefined reference to `esp_now_set_self_role'
.pioenvs/nodemcuv2/src/espnow-sensor-bme280.ino.o:(.text.setup+0x24): undefined reference to `esp_now_add_peer'
.pioenvs/nodemcuv2/src/espnow-sensor-bme280.ino.o:(.text.setup+0x28): undefined reference to `esp_now_register_send_cb'
.pioenvs/nodemcuv2/src/espnow-sensor-bme280.ino.o:(.text.setup+0x2c): undefined reference to `esp_now_send'
.pioenvs/nodemcuv2/src/espnow-sensor-bme280.ino.o: In function `setup':
espnow-sensor-bme280.ino.cpp:(.text.setup+0xa6): undefined reference to `esp_now_init'
espnow-sensor-bme280.ino.cpp:(.text.setup+0xbc): undefined reference to `esp_now_set_self_role'
espnow-sensor-bme280.ino.cpp:(.text.setup+0xce): undefined reference to `esp_now_add_peer'
espnow-sensor-bme280.ino.cpp:(.text.setup+0xd7): undefined reference to `esp_now_register_send_cb'
espnow-sensor-bme280.ino.cpp:(.text.setup+0xff): undefined reference to `esp_now_send'
collect2: error: ld returned 1 exit status
In other words, it couldn’t find the ESP-Now library. This seemed pretty strange to me, as it’s and Espressif library, not a contributed, external library and, as such, I would have expected it to be automatically linked in.
I tried a lot of things (most of which were quite silly), to no avail. A little bit of investigation showed that the ESP-Now library did indeed exist under:-
…with the espnow.h sitting in the include subdir and the libespnow.a in the lib subdir.
A little bit of Oogleg’ing brought up a hit where an Arduino user was having the same problem, where the suggested (and tested) fix was to add “-lespnow” to the compiler.c.elf.libs line in the relevant platform.txt file, but unfortunately that didn’t seem to make any difference for PlatformIO. I kept on thinking that it really shouldn’t be that difficult (most things aren’t with PlatformIO) and finally had a small flash of inspiration.
I went back to the project directory and simply added:-
build_flags = -lespnow
…into the [env:……] section of my
Clean compile; no errors.
Special message for someone with more time on his hands than he actually wants and is probably scouring the ‘net for anything readable with ESP8266 in it.
Take it easy Pete and listen to what the Doc’ (and HID) says. Let me know if you want some green tea (seriously!). All the best!