-->
Page 1 of 1

How to put WIFI_SSID in a variable?

PostPosted: Thu May 19, 2022 5:31 am
by JPM06
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

Re: How to put WIFI_SSID in a variable?

PostPosted: Thu May 19, 2022 11:35 am
by JPM06
Its more or less what I was doing, but I wished to avoid the multiple wifi.begin.
Thanks anyway.

Re: How to put WIFI_SSID in a variable?

PostPosted: Fri May 20, 2022 7:41 am
by Inq720
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.