I’ve added a dynamic build flag using the $PIOENV
in my platformio.ini file in the hopes of adding some cross-platform portability with my pin_definitions, as seen below:
in platformio.ini
:
[env:node]
platform = espressif32
board = lolin_d32_pro
framework = arduino
...
src_filter = +<node>
upload_port = /dev/cu.wchusbserial*
monitor_port = /dev/cu.wchusbserial*
upload_protocol = esptool
build_flags =
-D BUILD_ENV_NAME=$PIOENV
[env:root]
platform = espressif8266@2.2.1
board = d1_mini
framework = arduino
src_filter = +<root>
upload_port = /dev/cu.wchusbserial*
monitor_port = /dev/cu.wchusbserial*
upload_protocol = esptool
build_flags =
-D BUILD_ENV_NAME=$PIOENV
in pin_definitions.h
:
#if BUILD_ENV_NAME == root
#ifdef ESP32
#define RX_PIN -1
#define TX_PIN -1
....
#elif ESP8266
#define RX_PIN D4
#define TX_PIN D3
...
#endif
#elif BUILD_ENV_NAME == node
#ifdef ESP32
#define RX_PIN 1
#define TX_PIN 2
...
#elif ESP8266
#define RX_PIN D4
#define TX_PIN D3
...
#endif
#endif
But the preprocessor conditionals doesn’t seem to work. I’ve tried defining new symbols and equating to those and those didn’t work as well, nor did comparing against chars / strings – can someone tell me what data type is the symbol exactly comparing against? Because somehow BUILD_ENV_NAME == node
(is this a string literal?) compiles.
I’ve worked around by defining each environment explicitly with IS_ROOT
and IS_NODE
, but would love to know how I can work with $PIO_ENV
. Thanks in advance!