So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By JPM06
#94559 Hello, all,
My NodeMCU is supposed to connect to different networks.
I'd like to write:
Code: Select all  if (ntwrk == 1) {
    WIFI_SSID = "thisnetworkSSID";
    WIFI_PASS = "thisnetworkpwd";
    break;
  }

...and so on for the other networks, that are selected by variable ntwrk, in EEPROM.
But this refused because WIFI_SSID must be a constant, if my understanding is correct.
Any mean to solve this (probably basic) programming problem?
Many thanks
JPM
User avatar
By Inq720
#94570
JPM06 wrote:Hello, all,
My NodeMCU is supposed to connect to different networks.
I'd like to write:
Code: Select all  if (ntwrk == 1) {
    WIFI_SSID = "thisnetworkSSID";
    WIFI_PASS = "thisnetworkpwd";
    break;
  }

...and so on for the other networks, that are selected by variable ntwrk, in EEPROM.
But this refused because WIFI_SSID must be a constant, if my understanding is correct.
Any mean to solve this (probably basic) programming problem?
Many thanks
JPM


To answer properly, we'd need see how WIFI_SSID/WIFI_PASS are defined.
If they are define like:

#define WIFI_SSID "Some SSID"

... it won't work! If it is defined as:

const char* WIFI_SSID;

... your code snippet will work.