Avoid hard coding of SSID and password
Posted:
Mon Apr 06, 2015 4:23 pm
by CheapB
I am looking for a way to avoid hardcoding SSID and password + a few other custom parameters.
Option 1 is to have a windows program that will take input of SSID, password and lest say 1-2 other custom parameters and then communicate these to the ESP-01. The ESP should store the values so they would survive a power outage.
Option 2 would be to put the ESP-01 in configuration mode - maybe by putting GPIO2 high and then it would serve up an AP and a webserver where the data could be entered. The values should be stored and and the SSId and pasword should be used after a reset
Any pointers on how do do one of the above options in Arduino?
Re: Avoid hard coding of SSID and password
Posted:
Mon Apr 06, 2015 11:00 pm
by longinus
This is a good idea... I should start doing this.
I think you can save the SSID info on the EEPROM, and then read it back later.
You don't have a lot of space, only 512 bytes... but should be enough for ssid and password.
There are 3 examples for writing/reading/clearing in the ESP8266 Libraries.
Like...
https://github.com/esp8266/Arduino/blob ... _write.inoUpdate: HUmmm, reading the readme in Github though, igrr mentions there is more space...
This is a bit different from standard EEPROM class. You need to call EEPROM.begin(size) before you start reading or writing, size being the number of bytes you want to use. Size can be anywhere between 4 and 4096 bytes.
EEPROM.write does not write to flash immediately, instead you must call EEPROM.commit() whenever you wish to save changes to flash. EEPROM.end() will also commit, and will release the RAM copy of EEPROM contents.
Re: Avoid hard coding of SSID and password
Posted:
Tue Apr 07, 2015 7:33 am
by CheapB
longinus wrote:This is a good idea... I should start doing this.
I think you can save the SSID info on the EEPROM, and then read it back later.
You don't have a lot of space, only 512 bytes... but should be enough for ssid and password.
There are 3 examples for writing/reading/clearing in the ESP8266 Libraries.
Like... https://github.com/esp8266/Arduino/blob ... _write.ino
Update: HUmmm, reading the readme in Github though, igrr mentions there is more space...
This is a bit different from standard EEPROM class. You need to call EEPROM.begin(size) before you start reading or writing, size being the number of bytes you want to use. Size can be anywhere between 4 and 4096 bytes.
EEPROM.write does not write to flash immediately, instead you must call EEPROM.commit() whenever you wish to save changes to flash. EEPROM.end() will also commit, and will release the RAM copy of EEPROM contents.
Thanks for the pointer - this would likely work. I will experiment with this. either there need to be a metadata format where a couple of bytes describes the length and maybe the type of data or fixed address format. the meta data format is likely more compressed but you would be forced to read all values to get the the address of the data you are looking for where as the fixed address format would be possible to read one by one - but more bloated. I am leaning towards the metadata model.
Re: Avoid hard coding of SSID and password
Posted:
Tue Apr 07, 2015 9:22 am
by draco
I would suggest that you just hardcode the address and length in your program, if all you need to store are the SSID and password.
For example, write your SSID into byte 0, with a length of 32.
Then write your password into byte 33, with a length of 64.
32 and 64 are the maximum lengths permitted for SSID/password, according to the standards. No overhead wasted on metadata in your tiny EEPROM space available that way, and you've ensured that you have enough space available for any SSID/password combination possible.
But, realistically, you might not even need to do that. In my experience, the ESP8266 is already storing the SSID and password by itself somewhere, so if you just start it up and tell it to connect, it will use the previous SSID/password.