Sneaky ways to 'change' code externally

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.

I want to be able to update values for SSID and password on an ESP8266

That has NOTHING to do with changing the data type, which you can NOT do.

They are

define wifi_ssid SampleSSID

though might be more malleable using wifi_ssid = "SampleSSID"

Quit using #define to create a name = value pair that goes away when the preprocessor is done.

Use a (non-const) char array!

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.

Jim

I felt the need to clarify as strings are involved whereas it’d be a lot simpler with number type variables.

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: https://tzapu.com/esp8266-wifi-connection-manager-library-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: https://tzapu.com/esp8266-wifi-connection-manager-library-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.

Disclaimer: no experience with ESP

INTP: Board will take input possibly via Bluetooth from Android phone.

Apply the principles as described in Serial Input Basics - updated.

INTP: Seems like something I have to do?

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.

PS

INTP: wifi_ssid[] = {'w', 'i', 'f', 'i', '3'} into someVariable = "wifi3";

Be aware that those two are not the same; the one is an array of characters, the second one is a c-string (with nul terminator).

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.