RF24 lib compatibility with esp8266

They say RF24 library (ID:433) is compatible with esp8266 core for Arduino. There is no “espressif” in library.json but I decided to give a try - the code compiles with Arduino IDE so there should be no problems, right?

Unfortunately it’s not as easy, while trying to compile a simple helloworld I got:

xtensa-lx106-elf-gcc -o .pioenvs/nodemcuv2/lib/RF24_ID433/utility/ATXMegaD3/compatibility.o -c -std=gnu99 -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -Os -mlongcalls -mtext-section-literals -falign-functions=4 -ffunction-sections -fdata-sections -DARDUINO=20300 -DLWIP_OPEN_SRC -DF_CPU=80000000L -D__ets__ -DICACHE_FLASH -DPLATFORMIO=030000 -DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_NODEMCU -U__STRICT_ANSI__ -I/home/jazg/.platformio/packages/framework-arduinoespressif/tools/sdk/include -I/home/jazg/.platformio/packages/framework-arduinoespressif/tools/sdk/lwip/include -I.pioenvs/nodemcuv2/FrameworkArduino -I/home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266 -I.pioenvs/nodemcuv2/FrameworkArduinoVariant -I/home/jazg/.platformio/packages/framework-arduinoespressif/variants/nodemcu -I.pioenvs/nodemcuv2/lib/SPI -I/home/jazg/.platformio/packages/framework-arduinoespressif/libraries/SPI -I.pioenvs/nodemcuv2/lib/RF24_ID433 -I/home/jazg/.platformio/lib/RF24_ID433 -I.pioenvs/nodemcuv2/lib/RF24_ID433/utility -I/home/jazg/.platformio/lib/RF24_ID433/utility /home/jazg/.platformio/lib/RF24_ID433/utility/ATXMegaD3/compatibility.c
/home/jazg/.platformio/lib/RF24_ID433/utility/ATXMegaD3/compatibility.c:8:20: fatal error: avr/io.h: No such file or directory
#include <avr/io.h>
^
compilation terminated.

Build recurses into subdirectories of $HOME/.platformio/lib/RF24_ID433 and tries to build foreign code. How do I prevent this? I understand this code is be required for other platforms, is anything I could do in library.json to overcome this? Of course it will be possible to create separate library entry for esp8266 but i’m trying to avoid this.

One more question, is it possible to test if my changes to library.json will work? Or at least build filters and export includes/excludes?

  1. PlatformIO 3.0 uses library.json when builds library. You can here test it
  2. export includes/excludes relates to source code that should be exported to archive. Do you need it? You can resolve build process using build field and specify what need to build and etc.

Could you show your library?

OK, for future reference, the code builds if I remove following directories:

$HOME/.platformio/lib/RF24_ID433/utility/ATXMegaD3
$HOME/.platformio/lib/RF24_ID433/utility/MRAA
$HOME/.platformio/lib/RF24_ID433/utility/RPi
$HOME/.platformio/lib/RF24_ID433/utility/SPIDEV

I’m considering adding these as build filters. In PlatformIO this library is Arduino-only so this should not break anything.

Excludes are related to other issue - there is no point in exporting Python interface for this lib, as well as some tests.

See my updates here → https://github.com/zgoda/RF24/blob/library_json_update_platforms/library.json, I will do a PR once I confirm it builds with ESP8266.

That is really a bug. We should compile only the files in utility directory. I’ve just fixed it

Could you re-test? Please pio upgrade

See Arduino IDE 1.5: Library specification · arduino/Arduino Wiki · GitHub

For backward compatibility with Arduino 1.0.x, the library author may opt to not place source code into the root folder, instead of the folder called src. In this case the 1.0 library format is applied and the source code is searched from the library root folder and the utility folder, for example:

Thanks, it compiles now although with warnings:

In file included from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:0:
/home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:124:0: warning: "PSTR" redefined [enabled by default]
#define PSTR(x) (x)
^
In file included from /home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/Arduino.h:240:0,
from /home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:63,
from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:
/home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/pgmspace.h:21:0: note: this is the location of the previous definition
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
^
In file included from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:0:
/home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:128:0: warning: "strlen_P" redefined [enabled by default]
#define strlen_P strlen
^
In file included from /home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/Arduino.h:240:0,
from /home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:63,
from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:
/home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/pgmspace.h:73:0: note: this is the location of the previous definition
#define strlen_P(strP)          strnlen_P((strP), SIZE_IRRELEVANT)
^
In file included from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:0:
/home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:129:0: warning: "PROGMEM" redefined [enabled by default]
#define PROGMEM
^
In file included from /home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/Arduino.h:240:0,
from /home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:63,
from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:
/home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/pgmspace.h:18:0: note: this is the location of the previous definition
#define PROGMEM     ICACHE_RODATA_ATTR
^
In file included from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:0:
/home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:130:0: warning: "pgm_read_byte" redefined [enabled by default]
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
^
In file included from /home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/Arduino.h:240:0,
from /home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:63,
from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:
/home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/pgmspace.h:90:0: note: this is the location of the previous definition
#define pgm_read_byte(addr)                                              \
^
In file included from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:0:
/home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:131:0: warning: "pgm_read_word" redefined [enabled by default]
#define pgm_read_word(p) (*(p))
^
In file included from /home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/Arduino.h:240:0,
from /home/jazg/.platformio/lib/RF24_ID433/RF24_config.h:63,
from /home/jazg/.platformio/lib/RF24_ID433/RF24.cpp:10:
/home/jazg/.platformio/packages/framework-arduinoespressif/cores/esp8266/pgmspace.h:99:0: note: this is the location of the previous definition
#define pgm_read_word(addr)                                              \
^

But I believe this is a problem with library itself when used with plain ESP8266, the macro ARDUINO_ARCH_ESP8266 should be defined only for Arduino DUE, not for plain ESP8266.

PlatformIO defines these macros depending on the type of platform and board. The library can use them.

Okay then this is a bug somewhere. Either this macro should not be defined, or the definiton is used for wrong purpose. This has been reported already.