Dumb question about build_flags


I am new to developing anything that needs to be compiled and trying to figure out what the hell are build_flags are supposed to do.

Lets take this example from the docs:

; Build options
build_flags =

How would I address SSID_NAME/SSID_PASSWORD from inside my main.cpp file?

Other than being able to see if they are defined, I don’t seem to be able to access those things in my functions.

 #ifdef SSID_NAME

You need to create two macros in your program.

#define XSTR(x) #x
#define STR(x) XSTR(x)

Then your code can get the values like

String s = STR(SSID_NAME);

In: platformio.ini
I have:

env_default = esp01

platform = espressif8266
framework = arduino
board = esp01
build_flags = '-DaSSID="your_ssid"' '-DaSSID_PASS="your_password"'

In: *.cpp
I have:

void setup() {

  thing.add_wifi(aSSID, aSSID_PASS); // needs only once

See example here Redirecting...

build_flags = '-DHELLO="World!"' '-DWIFI_PASS="My password"'