Hi guys!
I'm trying to use the WiFiManager library.
It works, but I need to recover the SSID and the passphrase that this library stores because I need to manage the connection in another way.
Explanation:
I want to keep to connect in the ESP8266WiFi.h library (WiFi.begin(ssid, password) because I don't need to go in AP mode if the connection fails (if it fails...it fails, I don't mind.), but only on a button push during startup and I don't see how to do this with the wifiManager library.
So, how can I get the SSID and passphrase that it stores?
Thanks!
So, how can I get the SSID and passphrase that it stores?
Set up your ouiji board. That's what we'd need to do, since you posted no code and no link to the library you are talking about.
PaulS:
Set up your ouiji board. That's what we'd need to do, since you posted no code and no link to the library you are talking about.
Hemmm....sorry.
I've just update the original post with the link to the libraries.
I've just update the original post with the link to the libraries.
Well, I'm not going to help you, then. You make me look like a fool by changing your post AFTER I comment on it. I do not appreciate that.
I make you look like a fool? But I've clearly wrote that I've modified the original post!
By the way, sorry, I haven't thought that I could offend you.
I've edited the original post again so it is as originally posted.
The WiFiManager library I'm talking about is url=http://[]this one
And the ESP8266WiF library I'm talking about is url=http://[]this one
So, how are you using the WiFiManager class? We need to see your code. In code tags, in a new reply.
Here the actual code:
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
// select wich pin will trigger the configuraton portal when set to LOW
// ESP-01 users please note: the only pins available (0 and 2), are shared
// with the bootloader, so always set them HIGH at power-up
#define TRIGGER_PIN D1
const char* ssid = "SSIDWiFi";
const char* password = "passphrase";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial){
delay(10);
}
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT);
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW ) {
Serial.println("Request to modify the stored WiFi data");
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//reset settings - for testing
//wifiManager.resetSettings();
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep
//in seconds
//wifiManager.setTimeout(120);
//it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
//WITHOUT THIS THE AP DOES NOT SEEM TO WORK PROPERLY WITH SDK 1.5 , update to at least 1.5.1
//WiFi.mode(WIFI_STA);
if (!wifiManager.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(5000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}else{
Serial.println("Using the already stored WiFi data");
WiFi.begin(ssid, password);
}
}
void loop() {
//
}
I guess I'm not really sure what you are looking for. You are asking the class to start an access point, with a known name and no password.
The class has two private variables, _ssid and _pass. There are no methods defined to return the values, but the source file has two commented out methods, starting on line 310, to get the SSID and password. If those are the values that you want, uncomment the function implementations, and add declarations to the header file.
PaulS, that is exactly what I need! Thanks!
I've added these 2 lines in WiFiManager.h:
void getSSID();
void getPassword();
and this 2 methods in WiFiManager.cpp:
String WiFiManager::getSSID() {
if (_ssid == "") {
DEBUG_WM(F("Reading SSID"));
_ssid = WiFi.SSID();
DEBUG_WM(F("SSID: "));
DEBUG_WM(_ssid);
}
return _ssid;
}
String WiFiManager::getPassword() {
if (_pass == "") {
DEBUG_WM(F("Reading Password"));
_pass = WiFi.psk();
DEBUG_WM("Password: " + _pass);
//DEBUG_WM(_pass);
}
return _pass;
}
This is how I try to recover them:
WiFiManager wifiManager;
Serial.print("Stored SSID: ");
Serial.println(wifiManager.getSSID());
Serial.print("Stored passphrase: ");
Serial.println(wifiManager.getPassword());
but when I compile, it says that
OnDemandConfigPortal_test:65: error: 'class WiFiManager' has no member named 'getSSID'
Serial.println(wifiManager.getSSID());
OnDemandConfigPortal_test:67: error: 'class WiFiManager' has no member named 'getPassword'
Serial.println(wifiManager.getPassword());
but when I compile, it says that
The declaration of the getSSID() function says that it returns nothing. The implementation says that it returns a String. Oops.
The declaration of the getPassword() function says that it returns nothing. The implementation says that it returns a String. Oops.
I've added these 2 lines in WiFiManager.h:
Where? Inside the WiFiManager class? In the public: section?
PaulS:
The declaration of the getSSID() function says that it returns nothing. The implementation says that it returns a String. Oops.
...oops!
I've added these 2 lines in WiFiManager.h:
Where? Inside the WiFiManager class? In the public: section?
In the private: section where there are the other class that already works:
void setupConfigPortal();
void startWPS();
String getSSID();
String getPassword();
I've tried to put them in the public: section but the error is still the same.
Yes, yes, I'm a noob and I don't know much about coding, but I'm trying to learn...coding! Usually I just break my head on the desktop over and over again reading posts all over the net and trying until it works or until I give up. This time I said...well, let's see if there is a good guy over there that can help! ...and here you are! Thanks!
If you define the function in the private: region, you won't be able to call them from the sketch. To do that, they need to be in the public: region.
Create a zip file with the header file, the source file, and the sketch. Use Reply, not the Quick Reply field, and attach the zip file using the Additional Options link that looks nothing like a link.
If you define the function in the private: region, you won't be able to call them from the sketch. To do that, they need to be in the public: region.
I've imagined that :-[ so I've tried to put it in the public: region too.
Here's the file.
Thanks a lot for the help!
OnDemandConfigPortal_test.zip (10.2 KB)
I don't have all those libraries, so I can't compile your code. Can you enable verbose mode during compilation (use File + Preferences), and post the output?
I don't see anything wrong with the code, but I have been known to miss the obvious.
Here the rsult:
/home/andrea/Arduino/OnDemandConfigPortal_test/OnDemandConfigPortal_test.ino: In function 'void setup()':
OnDemandConfigPortal_test:11: error: 'D1' was not declared in this scope
#define TRIGGER_PIN D1
^
/home/andrea/Arduino/OnDemandConfigPortal_test/OnDemandConfigPortal_test.ino:24:11: note: in expansion of macro 'TRIGGER_PIN'
pinMode(TRIGGER_PIN, INPUT);
^
OnDemandConfigPortal_test:65: error: 'class WiFiManager' has no member named 'getSSID'
Serial.println(wifiManager.getSSID());
^
OnDemandConfigPortal_test:67: error: 'class WiFiManager' has no member named 'getPassword'
Serial.println(wifiManager.getPassword());
^
Multiple libraries were found for "ESP8266WiFi.h"
Used: /home/andrea/Arduino/libraries/ESP8266WiFi
Not used: /home/andrea/arduino-1.6.12/hardware/esp8266com/esp8266/libraries/ESP8266WiFi
Using library ESP8266WiFi at version 1.0 in folder: /home/andrea/Arduino/libraries/ESP8266WiFi
Using library ESP8266WebServer at version 1.0 in folder: /home/andrea/arduino-1.6.12/hardware/esp8266com/esp8266/libraries/ESP8266WebServer
Using library DNSServer at version 1.1.0 in folder: /home/andrea/arduino-1.6.12/hardware/esp8266com/esp8266/libraries/DNSServer
Using library WiFiManager-master at version 0.12 in folder: /home/andrea/Arduino/libraries/WiFiManager-master
exit status 1
'D1' was not declared in this scope
There are a lot of other lines like this one:
Detecting libraries used...
"/home/andrea/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I/home/andrea/arduino-1.6.12/hardware/esp8266com/esp8266/tools/sdk/include" "-I/home/andrea/arduino-1.6.12/hardware/esp8266com/esp8266/tools/sdk/lwip/include" "-I/home/andrea/arduino-1.6.12/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/include" "-I/tmp/arduino_build_526301/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DARDUINO=10612 -DARDUINO_ESP8266_ESP01 -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_ESP01" -DESP8266 "-I/home/andrea/arduino-1.6.12/hardware/esp8266com/esp8266/cores/esp8266" "-I/home/andrea/arduino-1.6.12/hardware/esp8266com/esp8266/variants/generic" "/tmp/arduino_build_526301/sketch/OnDemandConfigPortal_test.ino.cpp" -o "/dev/null"
Do you need them all? I didn't include them here because the messge was too long
Thanks again!
I haven't thought about uploading a file.
Here it is with all the log from the compile.
Compile logs.txt (30.2 KB)
Using library WiFiManager-master at version 0.12 in folder: /home/andrea/Arduino/libraries/WiFiManager-master
Is that the folder that contains the files you modified?
Damned it!
I've copied those files into the project folder and I (wrongly) thought that Arduino would use those (even because when I open the project, it also opens those 2 files).
Moving the files into the correct folder solved the problem.
Paul thanks for you precious help!
Have a nice day!
Can you share the final project or library ? i want to add same compatibility in wifi manager too