ESP 8266 Wifi Manager Question.

Hello. First-time poster and very new to programming.

I’m trying to add the wifi Manager Libary to a small program I found. I replaced the project wifi code with the wifi manager code

Below code is what I Removed and replaced with wifi manager

const char ssid = “my wifi”; /* Replace with your SSID /
const char passphrase[] = “password”; /
Replace with your WPA2 passphrase */

However later in the original program, I have this.

//e131.begin(ssid, passphrase); /* via Unicast on the default port */

Anybody know how I can pull the ssid and passpharse from wifi manager into the main code.

Please assume I’m an idiot, and very new to this…

wifi manager GitHub - tzapu/WiFiManager: ESP8266 WiFi Connection manager with web captive portal

e.131 GitHub - forkineye/E131: E1.31 (sACN) library for Arduino with ESP8266 support

attached is my “mongrel” code.

project_x.ino (3.57 KB)

kgreene:
//e131.begin(ssid, passphrase); /* via Unicast on the default port */

The "//" at the start of that line makes it a comment so it has absolutely no effect on your program.

Looks like you just need to uncomment these lines:

/* #define ssid WLAN_SSID /* Replace with your SSID /
/
const char passphrase = “WLAN_PASS”; /* Replace with your WPA2 passphrase */

And change the values to whatever your wifi network name and SSID are.

boylesg:
Looks like you just need to uncomment these lines:

/* #define ssid WLAN_SSID /* Replace with your SSID /
/
const char passphrase = "WLAN_PASS"; /* Replace with your WPA2 passphrase */

And change the values to whatever your wifi network name and SSID are.

The whole point of the WiFiManager library is for the WiFi credentials to not be hardcoded so that's definitely not the solution. The idea is for the user of a WiFi device to be able to use the device on any network without needing to modify and update the firmware. Instead it creates an access point with a captive portal. So you just connect to the ESP8266's AP with a WiFi device and open the browser. The captive portal causes any URL to load a web page that allows you to set your WiFi credentials, which are then written to non-volatile memory. Take a look at the library, it's pretty useful.

pert:
The "//" at the start of that line makes it a comment so it has absolutely no effect on your program.

Sorry added the // to compile

Thanks for your responses.

As Bert said wifi manager replaces the need to hardcode the ssid and password so it can join to anynetwork..

Original code uses this for wifi connection..

/const char [] = "mywifi"; / Replace with your SSID */
/const char passphrase[] = "password"; / Replace with your WPA2 passphrase */

This has all been replaced with wifi managers library

but the code needs to know what the SSID and passphrase are needed later on.

e131.beginMulticast(ssid, passphrase, universe); /* via Multicast for Universe 1 */

So how to pull the SSID & Passphrase out of the wifimanager libary.

See what you get from WiFi.SSID() and WiFi.psk(). They both return String.

If you don't want to use String you can find the source of those functions here:

where in my code should I try that

const char ssid [] = WiFi.SSID(); /* Replace with your SSID */
const char passphrase[] = WiFi.psk() ; /* Replace with your WPA2 passphrase */

I get this error

Arduino: 1.8.5 (Windows 10), Board: "WeMos D1 R2 & mini, 80 MHz, 921600, 4M (3M SPIFFS)"

another_goV3.1:8: error: initializer fails to determine size of 'ssid'

const char ssid = WiFi.SSID(); /* Replace with your SSID */

^

another_goV3.1:8: error: array must be initialized with a brace-enclosed initializer

another_goV3.1:9: error: initializer fails to determine size of 'passphrase'

const char passphrase = WiFi.psk() ; /* Replace with your WPA2 passphrase */

^

another_goV3.1:9: error: array must be initialized with a brace-enclosed initializer

exit status 1
initializer fails to determine size of 'ssid'

If I try

e131.beginMulticast( WiFI.ssid (), WiFI.psk(), universe); /* via Multicast for Universe 1 */

I get this error

Arduino: 1.8.5 (Windows 10), Board: "WeMos D1 R2 & mini, 80 MHz, 921600, 4M (3M SPIFFS)"

C:\Users\lxkev\Documents\Arduino\another_goV3.1\another_goV3.1.ino: In function 'void setup()':

another_goV3.1:47: error: 'WiFI' was not declared in this scope

e131.beginMulticast( WiFI.ssid (), WiFI.psk(), universe); /* via Multicast for Universe 1 */

^

exit status 1
'WiFI' was not declared in this scope

:frowning:

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

kgreene:
const char ssid = WiFi.SSID(); /* Replace with your SSID */

It returns a String, not a string. I realize that’s confusing but it’s important to understand the difference:
https://www.arduino.cc/reference/en/language/variables/data-types/string/
You can convert a String to string:
https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/c_str/
or better yet, don’t ever use String at all by reproducing the necessary parts of the code for these functions, as shown in the link in my last reply.

kgreene:
another_goV3.1:47: error: ‘WiFI’ was not declared in this scope

It’s WiFi, not WiFI. Case is important!

You’re getting ahead of yourself here. First is just a simple test to make sure the functions will actually return the correct values:

Serial.print("SSID: ");
Serial.println(WiFi.SSID());
Serial.print("password: ");
Serial.println(WiFi.psk());

Thanks Pert

Thanks for the info on using the forum.

So I can now see the correct information in the serial monitor.

How would I used the convert a String to string, I understand it's not best practice. However, reproducing the necessary parts of the code for these functions is beyond my current skill set.

Thanks for your help.

This forum is great.

lxkev:
So I can now see the correct information in the serial monitor.

Cool. That's progress! I've never used those functions so I wasn't certain what they would return in your application. Always smart to have a quick sanity check before you go too far down the rabbit hole.

lxkev:
How would I used the convert a String to string, I understand it's not best practice. However, reproducing the necessary parts of the code for these functions is beyond my current skill set.

There's a handy function you can use to convert Strings to strings:
https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/c_str/
Unfortunately they didn't bother to add a nice simple usage example on that page but it's easy enough:

e131.beginMulticast(WiFi.SSID().c_str(), WiFi.psk().c_str(), universe);

Thank you :slight_smile: