While I'm sure there's a simple way to achieve my end goal, let's consider this educational exploration.
The aim is to change char data type variables while the board is running. Specifically to the current project, I want to be able to update values for SSID and password on an ESP8266 D1 Mini instead of being stuck with what was entered at the time of compile/upload.
They are #define wifi_ssid SampleSSID
though might be more malleable using
char* wifi_ssid = "SampleSSID";
Board will take input possibly via Bluetooth from Android phone.
My wondering is, would it work if I defined a variable as an array of many variables? E.g.:
wifi_ssid[] = {p1, p2, p3, p4, p5}
Then I could individually assign values to each p1, p2, etc ? Such as the android serially sending over 5 characters (e.g., name of ssid) then having that reconstructed.
I still don't have a grasp on turning
wifi_ssid[] = {'w', 'i', 'f', 'i', '3'}
into
someVariable = "wifi3"
Seems like something I have to do? Iirc I can't just move whole strings, they need to be read one char at a time in a for loop as many times as the mrssage is long, etc.
The aim is to change char data type variables while the board is running.
Now I am no English major , but would this be better way to express your aim?
The aim is to change variables while the board is running.
I believe adding more info than is actually necessary is working against you.
Again , my English is pretty rudimentary, but if you really want to get technical - it is the application / code which is being executed.
Running boards used to be popular on cars.
Besides - why would they be called variables if you could not change them?
Constant "variables" being exempt.
off my soapbox, sorry for the irrelevant comments.
The normal way of changing wlan credentials in the ESP8266 is to get it to temporarily run an access point and a web server. It is relatively simple and there are plenty of standard examples. Look here for instance: ESP8266 WiFi configuration manager library for Arduino IDE for a ready made library.
6v6gt:
The normal way of changing wlan credentials in the ESP8266 is to get it to temporarily run an access point and a web server. It is relatively simple and there are plenty of standard examples. Look here for instance: ESP8266 WiFi configuration manager library for Arduino IDE for a ready made library.
Thanks for the link. The captive portal thing was exactly the term I was looking for in relation to another project.
I'm not sure if your ssid is a nul terminated character array or 32 octets. Based on
char* wifi_ssid = "SampleSSID";
it's the former. So you can use a simple strcpy(). In that case you have to make sure that the destination can contain the full SSID.
// max 63 character SSID plus nul terminator; not initialized
char wifi_ssid[64];
or
// max 63 character SSID plus nul terminator; initialized with a default
char wifi_ssid[64] = "somessid';
Depending on your code, it might be advisable to store updated SSID in eeprom so reboots do not result in changing back to the original.
The usual way to have a value that changes at runtime is to declare a variable and to assign values to it. That's why it's called a "variable". You can vary it.