Today’s (short) “duh!” story

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:-


Linking .pioenvs/nodemcuv2/firmware.elf
.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:-

~/platformio//packages/framework-arduinoespressif8266/tools/sdk

…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 platformio.ini file.

Clean compile; no errors.

Duh!  KISS!!


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!


 

Advertisements

4 thoughts on “Today’s (short) “duh!” story

    • Ivan,

      Many thanks for that. Can one only run the staging version from the IDE?


      gaijin@glen:~/PlatformIO/ESP-Now_Gateway$ pio run
      [Sun Dec 24 09:15:28 2017] Processing esp12e (platform: https://github.com/platformio/platform-espressif8266.git#feature/stage; board: esp12e; framework: arduino)
      -----------------------------------------------------------------------------------------------------------------------------------------------------
      PlatformManager: Installing platform-espressif8266
      espressif8266 @ 572bcc6 is already installed
      The platform 'https://github.com/platformio/platform-espressif8266.git#feature/stage' has been successfully installed!
      The rest of packages will be installed automatically depending on your build environment.
      Error: Unknown development platform 'https://github.com/platformio/platform-espressif8266.git#feature/stage'

      -John-

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s