How should I store WiFi credentials in public project?

I’m wanting to upload a project I made to GitHub as a portfolio piece. Right now, it stores my WiFi SSID and password as plain text in main.cpp.
Is there a common way to avoid this?

I know there are general solutions to this. But they mainly rely on storing credentials in files separate from the project. And that’s not really an option for microcontrollers, especially if I want it to be platform-independent.

  1. Put your secrets in a dedicated config file, like /config/secret.yml
  2. git-ignore the secret file: https://github.com/MacDada/DnWiFiDoorLock/blob/29d08cef04a1d6ba48cdca443e7e41c17e2bcf80/.gitignore#L4
  3. Load your secret config from PlatformIO config: https://github.com/MacDada/DnWiFiDoorLock/blob/29d08cef04a1d6ba48cdca443e7e41c17e2bcf80/platformio.ini#L16
  4. You can keep a template for the secret config in the repo: https://github.com/MacDada/DnWiFiDoorLock/blob/29d08cef04a1d6ba48cdca443e7e41c17e2bcf80/config/secret.ini.dist
  5. Pass your secret values to the project as global MACRO values: https://github.com/MacDada/DnWiFiDoorLock/blob/29d08cef04a1d6ba48cdca443e7e41c17e2bcf80/config/nodemcu.ini#L71
  6. Use the values in your code: https://github.com/MacDada/DnWiFiDoorLock/blob/29d08cef04a1d6ba48cdca443e7e41c17e2bcf80/src/arduino.cpp#L9
1 Like