intellij-micropython icon indicating copy to clipboard operation
intellij-micropython copied to clipboard

Environment Variables?

Open gamename opened this issue 2 years ago • 4 comments

Hi,

Is there any way to pass environment variables to the micropython environment? I'm trying to avoid hard-coding wifi passwords in the code. If I could pass that as an env var, then I could just set the variable that way.

thank you

gamename avatar Aug 09 '22 04:08 gamename

I am not sure how such a thing could be possible. Since a Microcontroller has no operating system, any needed data has to be saved either directly in your code or in some other connected storage.

In the case of the Raspberry Pi Pico (I am sure it works with other microcontrollers also), some hacks exist to write data directly to the flash storage, but this is highly not recommended. I am currently creating a project where I need configuration data, also (including Wifi credentials). I am going to try to use an SD card for this.

Btw: Environment variables are the least secure way to store credentials ;)

vekunz avatar Aug 09 '22 06:08 vekunz

@vekunz OK. So how can I pass sensitive info like SSIDs/Passwords without keeping it in source?

gamename avatar Aug 09 '22 11:08 gamename

I think the only good way (except in source code) is an SD card.

vekunz avatar Aug 09 '22 12:08 vekunz

I recently used this pattern:

  • create a settings.py or config.py file
  • add it to .gitignore
  • define your variables on each line like SSID_NAME="Network Name"
  • copy settings.py on to the device
  • put import settings at the top of main.py

Hope this helps!

vdavez avatar Sep 28 '22 21:09 vdavez