Search code examples
c++arduinoenvironment-variablesesp32fastled

Environment Variables for Arudino / ESP32 module code


I have some simple FastLed & wifi code on my ESP32 module, but I don't want to store my WIFI ssid & password in the code (on github). So i'd like to have that info in a separate file that doesn't get checked into source control but DOES get compiled and loaded onto the ESP32 during the upload process. Is this possible?

I'd imagine I would have a wifi.env.json file or something that is read at compile time, the variables are used in the code in the correct places, and then the compiled code w/ those variables are uploaded to the ESP32.

i'm a web developer and this is a common practice for that community, just curious if it's possible for arudino/ESP32 code also.


Solution

  • I have a separate header with projects like this with a name like WiFiCredentials.h The body of that file will just be:

    #define SSID myssidwhatever
    #define PASSWORD mypassword
    

    And that is all that's in the file. I include that file in the main project so it has access to those defines but I don't include the file in the repo. I just add it to the gitignore file. So if you were to go and download one of my projects from github you'd get an error that file doesn't exist and you'd have to create that file and #define your ssid and password. I include those instructions in the readme.