platformio / platformio-docs

PlatformIO Documentation
https://docs.platformio.org
Apache License 2.0
241 stars 326 forks source link

Update envvars.rst #129

Closed Reinbert closed 4 years ago

Reinbert commented 4 years ago

Hi there!

I tried to inject my Wifi credentials on Ubuntu 16.04 via platformio's environment build flags by appending each statement to the end of my .bashrc file. However, the stated Unix examples did not work for me. As I suspect that other systems are affected too, I suggest the following changes to the docs. In detail:

export PLATFORMIO_BUILD_FLAGS=-DFOO (Works)


export PLATFORMIO_BUILD_FLAGS=-DFOO -DBAR=1 -DFLOAT_VALUE=1.23457e+07 Error when opening a new terminal:

bash: export: `-DBAR=1': not a valid identifier
bash: export: `-DFLOAT_VALUE=1.23457e+07': not a valid identifier

Adding single quotes around all values fixes this: export PLATFORMIO_BUILD_FLAGS='-DFOO -DBAR=1 -DFLOAT_VALUE=1.23457e+07'


export PLATFORMIO_BUILD_FLAGS='-DWIFI_PASS=\"My password\"' '-DWIFI_SSID=\"My ssid name\"' Build flags are cut off after first pair of single quotes. Solution: Enclose all flags in one pair of single quotes: export PLATFORMIO_BUILD_FLAGS='-DWIFI_PASS=\"My password\" -DWIFI_SSID=\"My ssid name\"'


(I did not check the flags on Windows)

Additionally: I changed the order of password and ssid flag and added a statement to look out for escaping rules of special characters. E.g.: My password contains a single $ which needs to be escaped like this: \$\$. (Doubling $ for CMake and \ for bash)

Cheers, Reinbert

CLAassistant commented 4 years ago

CLA assistant check
All committers have signed the CLA.

ivankravets commented 4 years ago

Thanks for the PR!

@valeros, please re-test on Win/Unix.

ivankravets commented 4 years ago

@valeros, please provide a unit test for this case.

valeros commented 4 years ago

Thanks a lot for the PR, it might be a good idea to transform WIFI_SSID and WIFI_PASS to separate environment variables and pass them to your project via Dynamic Variables