mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 09:05:56 +03:00
[GH-ISSUE #243] Access SSID and Password #203
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#203
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @dudesky71 on GitHub (Nov 11, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/243
Hello,
I'm trying to use WiFi Manager with ADAFRUIT IO with an ESP8266.
Your code works fine by itself. My problem is passing the saved WiFi SSID and PW to Adafruit's SSID and PW code. It defines it as a constant string.
Is there an easy way to do this?
Thanks!
@tzapu commented on GitHub (Nov 11, 2016):
hi,
fetch it from WiFi.SSID() and WIFI.psk() after the setup is done
cheers
alex
@dudesky71 commented on GitHub (Nov 11, 2016):
Sorry, don't mean to be a bonehead but their code does this...
#define WIFI_SSID "SSID goes here"
#define WIFI_PASS "PW goes here"
These sit in a config.h file
If I remove the quotes and insert WiFi.SSID() and WIFI.psk() It tells me they are not declared in the scope. I'm sure i'm doing it wrong... Any ideas? Much appreciated :)
@tablatronix commented on GitHub (Nov 11, 2016):
You should be able to just remove adafruit connection code and just use wifimanager autoconenct
@dudesky71 commented on GitHub (Nov 14, 2016):
I got this to work but it seems to not play nicely with Adafruit.IO
When WiFimanager is in the code, it randomly locks up the esp8266 when sending sensor data to Adafruit.IO. If I remove WiFimanager from the startup, it works fine. Everything is running latest. Any ideas?
@tzapu
@tablatronix commented on GitHub (Nov 14, 2016):
basic sketch example ?
@dudesky71 commented on GitHub (Nov 14, 2016):
ok sorry... What's the secret to pasting code so it all shows up? The forum is stripping some things out :/
@tzapu commented on GitHub (Nov 14, 2016):
add three backticks ` before and three after the code
@tablatronix commented on GitHub (Nov 14, 2016):
single tick is for inline code, triple ticks for blocks
@dudesky71 commented on GitHub (Nov 14, 2016):
#include <DHT.h> #include <SPI.h> #include <ESP8266WiFi.h> #include <DNSServer.h> #include <WiFiManager.h> #include "AdafruitIO_WiFi.h" /************************ Example Starts Here *******************************/ #define IO_USERNAME "xxxxxx" #define IO_KEY "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #define WIFI_SSID "" #define WIFI_PASS "" #define DHTPIN 4 // what digital pin we're connected to. Mapped to pin D2 on WeMOS #define DHTTYPE DHT11 // DHT 11 //#define BLYNK_PRINT Serial // Comment this out to disable prints and save space #define ANALOG_PIN A0 // analog pin 0 // Initialize DHT sensor. DHT dht(DHTPIN, DHTTYPE); AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); // analog state int currentwetness = 0; int lastwetness = -1; int tempint = 0; int humint = 0; unsigned long previousMillis = 0; const long interval = 10000; // set up the 'analog' feed AdafruitIO_Feed *wetnessfeed = io.feed("wetness"); // set up the 'DHT' feed float AdafruitIO_Feed *tempfeed = io.feed("temp"); AdafruitIO_Feed *humfeed = io.feed("hum"); // set up the 'DHT' feed integer AdafruitIO_Feed *tempfeedint = io.feed("tempint"); AdafruitIO_Feed *humfeedint = io.feed("humint"); void setup() { // start the serial connection Serial.begin(9600); Serial.println(""); Serial.println(WiFi.SSID()); Serial.println(WiFi.psk()); // put your setup code here, to run once: //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager; //reset saved settings //wifiManager.resetSettings(); //set custom ip for portal //wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); //fetches ssid and pass from eeprom and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" //and goes into a blocking loop awaiting configuration //wifiManager.autoConnect("Test-DongleAP"); //or use this for auto generated name ESP + ChipID wifiManager.autoConnect(); //if you get here you have connected to the WiFi Serial.println("Connected to WiFi Network..."); dht.begin(); delay(100); // wait for serial monitor to open while(! Serial); // connect to io.adafruit.com Serial.println(""); Serial.print("Connecting to Adafruit IO"); io.connect(); // wait for a connection while(io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } // we are connected Serial.println(); Serial.println(io.statusText()); pinMode(2, OUTPUT); // set blue led pin to output // Show Connection Status and IP Address Serial.println(""); Serial.println("WiFi connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); // Blink the blue LED three times for WiFi connection confirmation digitalWrite(2, LOW); // sets the LED on delay(50); digitalWrite(2, HIGH); // sets the LED off delay(200); digitalWrite(2, LOW); // sets the LED on delay(50); digitalWrite(2, HIGH); // sets the LED off delay(200); digitalWrite(2, LOW); // sets the LED on delay(50); digitalWrite(2, HIGH); // sets the LED off Serial.println(""); } void loop() { io.run(); // io.run(); is required for all sketches. // it should always be present at the top of your loop // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. unsigned long currentMillis = millis(); if(currentMillis - previousMillis >= interval) { previousMillis = currentMillis; // grab the current state of the photocell currentwetness = analogRead(ANALOG_PIN); // return if the value hasn't changed Serial.println("Reading ADC..."); //if(currentwetness == lastwetness) // return; // store last analog state lastwetness = currentwetness; // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) Serial.println("Reading DHT..."); float hum = dht.readHumidity(); humint = hum; // wait half second (1000 milliseconds == 1 second) delay(500); // Read temperature as Celsius (the default) // float temp = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) float temp = dht.readTemperature(true); tempint = temp; // float f = dht.readTemperature(true); // wait half second (1000 milliseconds == 1 second) delay(500); // Check if any reads failed and exit early (to try again). // if (isnan(hum) || isnan(temp) || isnan(f)) { if (isnan(hum) || isnan(temp)) { Serial.println("Failed to read from DHT sensor!"); return; } // Compute heat index in Fahrenheit (the default) // float hif = dht.computeHeatIndex(f, hum); // Compute heat index in Celsius (isFahreheit = false) // float hic = dht.computeHeatIndex(temp, hum, false); Serial.print("Humidity: "); Serial.print(hum); Serial.println(" %\t"); Serial.print("Temperature: "); Serial.print(temp); Serial.println(" *F "); //Serial.print(f); //Serial.print(" *F\t"); //Serial.print("Heat index: "); //Serial.print(hic); //Serial.print(" *C "); //Serial.print(hif); //Serial.println(" *F"); // save the current state to the analog feed Serial.print("Sending -> "); if (currentwetness <= 10)currentwetness = 0; Serial.println(currentwetness); wetnessfeed->save(currentwetness); delay(1000); Serial.print("Sending -> "); Serial.println(temp); String tempstring = String(temp); tempfeed->save(temp); delay(1000); tempfeedint->save(tempint); Serial.print("Sending -> "); delay(1000); Serial.println(hum); humfeed->save(hum); delay(1000); humfeedint->save(humint); Serial.println("Sent..."); Serial.println(""); // Blink the blue LED once for data sent confirmation digitalWrite(2, LOW); // sets the LED on delay(100); digitalWrite(2, HIGH); // sets the LED off // wait ten seconds (10000 milliseconds == 10 seconds) Serial.println("Pausing 10 Seconds..."); } }@dudesky71 commented on GitHub (Nov 14, 2016):
any ideas @tzapu ?
Thank You for looking.
@tablatronix commented on GitHub (Nov 14, 2016):
I would suggest reducing this to a minimum amount of code to reproduce, there is just too much going on, it makes for a bad test. Start pulling everything out but the 2 things being tested
@dudesky71 commented on GitHub (Nov 14, 2016):
this is a super simple sketch. There is hardly anything going on as-is. There are 3 data pushes to Adafruit's server. That is all. Anything less in the code and it will not be doing anything... There are alot of comments but it explains what is going on. Again, it runs fine without WiFi manager.
@tablatronix commented on GitHub (Nov 14, 2016):
well no
This would be a simple sketch, minimal code required
or use the examples and add to them, you have spi dht libraries etc.
Either way i doubt this is going to work with wifimanager, since this library handles wifi for you, you might have to use the adafruit mqtt library directly.
@dudesky71 commented on GitHub (Nov 14, 2016):
ok thank you
@dudesky71 commented on GitHub (Nov 16, 2016):
I just tried another WeMos module. I've tried a HUZZAH. I've tried the basic MQTT client and they all lock up or reset the module within minutes of running. Please see the log and dump below... Can you help with this? @tzapu @tablatronix
Thank You
Sending counter val 248...OK!
Sending counter val 249...OK!
Sending counter val 250...OK!
Sending counter val 251...OK!
Sending counter val 252...OK!
Sending counter val 253...OK!
Sending counter val 254...OK!
Sending counter val 255...OK!
Sending counter val 256...OK!
Sending counter val 257...OK!
Sending counter val 258...Failed
Connecting to MQTT... Connection failed
Retrying MQTT connection in 5 seconds...
Connection failed
Retrying MQTT connection in 5 seconds...
MQTT Connected!
Sending counter val 259...OK!
Sending counter val 260...Failed
Connecting to MQTT...
MQTT Connected!
Sending counter val 261...Failed
Connecting to MQTT...
MQTT Connected!
Sending counter val 262...Failed
Connecting to MQTT... Connection failed
Retrying MQTT connection in 5 seconds...
MQTT Connected!
Sending counter val 263...OK!
Sending counter val 264...OK!
Connecting to MQTT... Connection failed
Retrying MQTT connection in 5 seconds...
Connection failed
Retrying MQTT connection in 5 seconds...
Connection failed
Retrying MQTT connection in 5 seconds...
Soft WDT reset
ctx: cont
sp: 3ffef710 end: 3ffef900 offset: 01b0
ets Jan 8 2013,rst cause:2, boot mode:(1,7)
ets Jan 8 2013,rst cause:4, boot mode:(1,7)
wdt reset
@tzapu commented on GitHub (Nov 16, 2016):
that looks more like an error related to mqtt
there is an esp8266 exception decoder floating around somehwre you can install and see exactly where the error came from
good luck
@tablatronix commented on GitHub (Nov 16, 2016):
not sure, i am using the adafruit mqtt anon_time example , it works fine.
Its not an exception, soft wdt reset usually means something is restarting it
@tablatronix commented on GitHub (Nov 16, 2016):
usually a infinite loop tripping the
watchdog. check for rogue while loops without a delay or yield()@dudesky71 commented on GitHub (Nov 16, 2016):
here is the basic sketch...
`include "ESP8266WiFi.h"
include "Adafruit_MQTT.h"
include "Adafruit_MQTT_Client.h"
/************************* WiFi Access Point *********************************/
#define WLAN_SSID "...your SSID..."
#define WLAN_PASS "...your password..."
/************************* Adafruit.io Setup *********************************/
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883 // use 8883 for SSL
#define AIO_USERNAME "...your AIO username (see https://accounts.adafruit.com)..."
#define AIO_KEY "...your AIO key..."
/************ Global State (you don't need to change this!) ******************/
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
/****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: /feeds/
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell");
// Setup a feed called 'onoff' for subscribing to changes.
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");
/*************************** Sketch Code ************************************/
// Bug workaround for Arduino 1.6.6, it seems to need a function declaration
// for some reason (only affects ESP8266, likely an arduino-builder bug).
void MQTT_connect();
void setup() {
Serial.begin(115200);
delay(10);
Serial.println(F("Adafruit MQTT demo"));
// Connect to WiFi access point.
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());
// Setup MQTT subscription for onoff feed.
mqtt.subscribe(&onoffbutton);
}
uint32_t x=0;
void loop() {
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
MQTT_connect();
// this is our 'wait for incoming subscription packets' busy subloop
// try to spend your time here
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000))) {
if (subscription == &onoffbutton) {
Serial.print(F("Got: "));
Serial.println((char *)onoffbutton.lastread);
}
}
// Now we can publish stuff!
Serial.print(F("\nSending photocell val "));
Serial.print(x);
Serial.print("...");
if (! photocell.publish(x++)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
// ping the server to keep the mqtt connection alive
// NOT required if you are publishing once every KEEPALIVE seconds
/*
if(! mqtt.ping()) {
mqtt.disconnect();
}
*/
}
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
int8_t ret;
// Stop if already connected.
if (mqtt.connected()) {
return;
}
Serial.print("Connecting to MQTT... ");
uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0) {
// basically die and wait for WDT to reset me
while (1);
}
}
Serial.println("MQTT Connected!");`
@tzapu commented on GitHub (Nov 16, 2016):
this
looks like an watchdog triggered reset, so there is a problem, not just a reset
@tablatronix commented on GitHub (Nov 16, 2016):
I am gonna guess this
So your mqtt is timing out or failing and this is resetting your board.
Try increasing that retry count, or find out why your connection is dropping out
@dudesky71 commented on GitHub (Nov 16, 2016):
I just changed over to a completely different communication method used by thinger.io
Here is the example sketch. It is super simple. It still locks up the 8266 modules. Seems like its a core 8266 problem...?
#include <ESP8266WiFi.h> #include <ThingerESP8266.h> #define USERNAME "your_user_name" #define DEVICE_ID "your_device_id" #define DEVICE_CREDENTIAL "your_device_credential" #define SSID "your_wifi_ssid" #define SSID_PASSWORD "your_wifi_ssid_password" ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); void setup() { pinMode(BUILTIN_LED, OUTPUT); thing.add_wifi(SSID, SSID_PASSWORD); // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc) thing["led"] << digitalPin(BUILTIN_LED); // resource output example (i.e. reading a sensor value) thing["millis"] >> outputValue(millis()); // more details at http://docs.thinger.io/arduino/ } void loop() { thing.handle(); }@tablatronix commented on GitHub (Nov 16, 2016):
Are you running wifimanager all the time ?
@dudesky71 commented on GitHub (Nov 16, 2016):
Yes. Is there a way to shut it down after the credentials get saved?
@tablatronix commented on GitHub (Nov 16, 2016):
I was testing with this
I did have an SSID check but i just removed it, cause I was using the ken taylor branch, i have switched back to stable, so that is not necessary. I have a feeling it is something else causing too much work maybe dropping your connection, not sure thought. I was thinking maybe your esp was stuck in STA+AP mode and causing issues
@dudesky71 commented on GitHub (Nov 17, 2016):
I can see the AP drop offline so I don't think it is that.
@wyojustin commented on GitHub (Feb 12, 2018):
I had the same question using the 8266 Feather HUZZAH. I finally just bit the bullet and hacked the AdafruitIO_ESP8266.cpp code. One small change makes the code work.
Include WiFi Mananger header file near the top of "AdafruitIO_ESP8266.cpp"
`
#ifdef ESP8266
#include "AdafruitIO_ESP8266.h"
#include <WiFiManager.h> // TJS: Hacked in for Mac's Klok
Change _connect to read as below
@elanozturk commented on GitHub (Jun 13, 2018):
i find out the way,thank you.
@gabi68 commented on GitHub (Nov 6, 2019):
Also,
Serial.printf("BSSID: %s\n", WiFi.BSSIDstr().c_str());
Good luck!!!