Advanced scripting

Hi.

In this ESP32 Arduino sketch I am trying to change the original platformio.ini in order to have multiple configs without mucking around with config.h since it is both cumbersome and potentially dangerous (file contains passwords and is tracked in git)

To do so, I created a new environment for each configuration (only one at the moment) and added a script that populates the DEFINEs, like this:

[platformio]
env_default=esp32dev-oneplus-auto
src_dir=.
lib_extra_dirs=../../libraries
[env:esp32dev-oneplus-auto]
platform=espressif32
board=esp32dev
framework=arduino
monitor_speed=115200
extra_scripts = project_config.py

I tried following the “advanced scripting” section of the docs and whipped up this little script:

Import("projenv")
projenv.Append(CPPDEFINES=[
  ('HAVE_CONFIG','1'),
  ('STORAGE','STORAGE_SD'),
  ('ENABLE_HTTPD','1'),
  ('ENABLE_WIFI_AP','1'),
  ('WIFI_AP_SSID','\"SSID-withhyphen\"'),
  ('WIFI_AP_PASSWORD','123testpwd'),
  ('ENABLE_WIFI_STATION','0'),
  ('WIFI_SSID','FREEMATICS'),
  ('WIFI_PASSWORD','...'),
  ('USE_OBD','1'),
  ('USE_GPS','1'),
  ('MEMS_MODE','EMS_9DOF')
])

I’ve tried playing around with quotes, double quotes, backslash, etc but I always get compilation errors that lead me to believe the variables are not properly escaped:

In file included from dataserver.cpp:36:0:
/home/andrea/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/lwip/apps/sntp/sntp.h:2:2: warning: #warning "This header file is deprecated, please include lwip/apps/sntp.h instead." [-Wcpp]
#warning "This header file is deprecated, please include lwip/apps/sntp.h instead."
^
dataserver.cpp: In function 'bool serverSetup()':
<command-line>:0:14: error: 'mySSID' was not declared in this scope
dataserver.cpp:380:17: note: in expansion of macro 'WIFI_AP_SSID'
WiFi.softAP(WIFI_AP_SSID, WIFI_AP_PASSWORD);
^
<command-line>:0:21: error: 'withhyphen' was not declared in this scope
dataserver.cpp:380:17: note: in expansion of macro 'WIFI_AP_SSID'
WiFi.softAP(WIFI_AP_SSID, WIFI_AP_PASSWORD);
^
<command-line>:0:18: error: unable to find numeric literal operator 'operator""testpwd'
dataserver.cpp:380:31: note: in expansion of macro 'WIFI_AP_PASSWORD'
WiFi.softAP(WIFI_AP_SSID, WIFI_AP_PASSWORD);
^
*** [.pioenvs/esp32dev-oneplus-auto/src/dataserver.cpp.o] Error 1

I’m sure it is something blindingly obvious but I can’t seem to find it.
Any pointers?

Eventually, I’d like to save the password in an external file and pull it in from that script but for the moment I’d be happy to have it working :slight_smile:

Thanks,
Andrea.

Replying to self, it was indeed a matter of properly escaping the strings.
Here is where I got the solution.

2 Likes