GithubHelp home page GithubHelp logo

espasyncwifimanager's Introduction

AsyncWiFiManager

ESP8266 Async WiFi Connection manager with fallback web configuration portal

Build Status

The configuration portal is of the captive variety, so on various devices it will present the configuration dialogue as soon as you connect to the created access point.

First attempt at a library. Lots more changes and fixes to do. Contributions are welcome.

This works with the ESP8266 Arduino platform with a recent stable release(2.0.0 or newer) https://github.com/esp8266/Arduino

Contents

How It Works

  • when your ESP starts up, it sets it up in Station mode and tries to connect to a previously saved Access Point
  • if this is unsuccessful (or no previous network saved) it moves the ESP into Access Point mode and spins up a DNS and WebServer (default ip 192.168.4.1)
  • using any wifi enabled device with a browser (computer, phone, tablet) connect to the newly created Access Point
  • because of the Captive Portal and the DNS server you will either get a 'Join to network' type of popup or get any domain you try to access redirected to the configuration portal
  • choose one of the access points scanned, enter password, click save
  • ESP will try to connect. If successful, it relinquishes control back to your app. If not, reconnect to AP and reconfigure.

How It Looks

ESP8266 WiFi Captive Portal Homepage ESP8266 WiFi Captive Portal Configuration

Wishlist

  • remove dependency on EEPROM library
  • move HTML Strings to PROGMEM
  • cleanup and streamline code (although this is ongoing)
  • if timeout is set, extend it when a page is fetched in AP mode
  • add ability to configure more parameters than ssid/password
  • maybe allow setting ip of ESP after reboot
  • add to Arduino Library Manager
  • add to PlatformIO
  • add multiple sets of network credentials
  • allow users to customize CSS

Quick Start

Installing

You can either install through the Arduino Library Manager or checkout the latest changes or a release from github

Install through Library Manager

Currently version 0.8+ works with release 2.0.0 or newer of the ESP8266 core for Arduino

  • in Arduino IDE got to Sketch/Include Library/Manage Libraries Manage Libraries

  • search for WiFiManager WiFiManager package

  • click Install and start using it

Checkout from github

Github version works with release 2.0.0 or newer of the ESP8266 core for Arduino

  • Checkout library to your Arduino libraries folder

Using

  • Include in your sketch
#if defined(ESP8266)
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#else
#include <WiFi.h>
#endif

#include <ESPAsyncWebServer.h>     //Local WebServer used to serve the configuration portal
#include <ESPAsyncWiFiManager.h>          //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
  • Initialize library, in your setup function add
AsyncWebServer server(80);
DNSServer dns;
  • Also in the setup function add
//first parameter is name of access point, second is the password
AsyncWiFiManager wifiManager(&server,&dns);

wifiManager.autoConnect("AP-NAME", "AP-PASSWORD");

if you just want an unsecured access point

wifiManager.autoConnect("AP-NAME");

or if you want to use and auto generated name from 'ESP' and the esp's Chip ID use

wifiManager.autoConnect();

After you write your sketch and start the ESP, it will try to connect to WiFi. If it fails it starts in Access Point mode. While in AP mode, connect to it then open a browser to the gateway IP, default 192.168.4.1, configure wifi, save and it should reboot and connect.

Also see examples.

Documentation

Password protect the configuration Access Point

You can and should password protect the configuration access point. Simply add the password as a second parameter to autoConnect. A short password seems to have unpredictable results so use one that's around 8 characters or more in length. The guidelines are that a wifi password must consist of 8 to 63 ASCII-encoded characters in the range of 32 to 126 (decimal)

wifiManager.autoConnect("AutoConnectAP", "password")

Callbacks

Enter Config mode

Use this if you need to do something when your device enters configuration mode on failed WiFi connection attempt. Before autoConnect()

wifiManager.setAPCallback(configModeCallback);

configModeCallback declaration and example

void configModeCallback (WiFiManager *myWiFiManager) {
  Serial.println("Entered config mode");
  Serial.println(WiFi.softAPIP());

  Serial.println(myWiFiManager->getConfigPortalSSID());
}
Save settings

This gets called when custom parameters have been set AND a connection has been established. Use it to set a flag, so when all the configuration finishes, you can save the extra parameters somewhere.

See AutoConnectWithFSParameters Example.

wifiManager.setSaveConfigCallback(saveConfigCallback);

saveConfigCallback declaration and example

//flag for saving data
bool shouldSaveConfig = false;

//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

Configuration Portal Timeout

If you need to set a timeout so the ESP doesn't hang waiting to be configured, for instance after a power failure, you can add

wifiManager.setConfigPortalTimeout(180);

which will wait 3 minutes (180 seconds). When the time passes, the autoConnect function will return, no matter the outcome. Check for connection and if it's still not established do whatever is needed (on some modules I restart them to retry, on others I enter deep sleep)

On Demand Configuration Portal

If you would rather start the configuration portal on demand rather than automatically on a failed connection attempt, then this is for you.

Instead of calling autoConnect() which does all the connecting and failover configuration portal setup for you, you need to use startConfigPortal(). Do not use BOTH.

Example usage

void loop() {
  // is configuration portal requested?
  if ( digitalRead(TRIGGER_PIN) == LOW ) {
    WiFiManager wifiManager;
    wifiManager.startConfigPortal("OnDemandAP");
    Serial.println("connected...yeey :)");
  }
}

See example for a more complex version. OnDemandConfigPortal

Custom Parameters

You can use WiFiManager to collect more parameters than just SSID and password. This could be helpful for configuring stuff like MQTT host and port, blynk or emoncms tokens, just to name a few. You are responsible for saving and loading these custom values. The library just collects and displays the data for you as a convenience. Usage scenario would be:

  • load values from somewhere (EEPROM/FS) or generate some defaults
  • add the custom parameters to WiFiManager using
// id/name, placeholder/prompt, default, length
AsyncWiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
wifiManager.addParameter(&custom_mqtt_server);
  • if connection to AP fails, configuration portal starts and you can set /change the values (or use on demand configuration portal)
  • once configuration is done and connection is established save config callback is called
  • once WiFiManager returns control to your application, read and save the new values using the AsyncWiFiManagerParameter object.
mqtt_server = custom_mqtt_server.getValue();

This feature is a lot more involved than all the others, so here are some examples to fully show how it is done. You should also take a look at adding custom HTML to your form.

  • Save and load custom parameters to file system in json form AutoConnectWithFSParameters
  • Save and load custom parameters to EEPROM (not done yet)

Custom IP Configuration

You can set a custom IP for both AP (access point, config mode) and STA (station mode, client mode, normal project state)

Custom Access Point IP Configuration

This will set your captive portal to a specific IP should you need/want such a feature. Add the following snippet before autoConnect()

//set custom ip for portal
wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
Custom Station (client) Static IP Configuration

This will make use the specified IP configuration instead of using DHCP in station mode.

wifiManager.setSTAStaticIPConfig(IPAddress(192,168,0,99), IPAddress(192,168,0,1), IPAddress(255,255,255,0));

There are a couple of examples in the examples folder that show you how to set a static IP and even how to configure it through the web configuration portal.

Custom HTML, CSS, Javascript

There are various ways in which you can inject custom HTML, CSS or Javascript into the configuration portal. The options are:

  • inject custom head element You can use this to any html bit to the head of the configuration portal. If you add a <style> element, bare in mind it overwrites the included css, not replaces.
wifiManager.setCustomHeadElement("<style>html{filter: invert(100%); -webkit-filter: invert(100%);}</style>");
  • inject a custom bit of html in the configuration form
WiFiManagerParameter custom_text("<p>This is just a text paragraph</p>");
wifiManager.addParameter(&custom_text);
  • inject a custom bit of html in a configuration form element Just add the bit you want added as the last parameter to the custom parameter constructor.
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "iot.eclipse", 40, " readonly");

Filter Networks

You can filter networks based on signal quality and show/hide duplicate networks.

  • If you would like to filter low signal quality networks you can tell WiFiManager to not show networks below an arbitrary quality %;
wifiManager.setMinimumSignalQuality(10);

will not show networks under 10% signal quality. If you omit the parameter it defaults to 8%;

  • You can also remove or show duplicate networks (default is remove). Use this function to show (or hide) all networks.
wifiManager.setRemoveDuplicateAPs(false);

Debug

Debug is enabled by default on Serial. To disable add before autoConnect

wifiManager.setDebugOutput(false);

espasyncwifimanager's People

Contributors

alanswx avatar baggior avatar belveder79 avatar bmoniey avatar debsahu avatar dumarjo avatar errolsancaktar avatar gmag11 avatar hamzahajeir avatar hmronline avatar jorgechagui avatar jorgen-vikinggod avatar judge2005 avatar kaegi avatar mattbradford83 avatar pedrosousabarreto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

espasyncwifimanager's Issues

WiFi credentials lost after first connection fail

I'm using this library in some of my projects. I've noticed that, if configured SSID is not active when calling autoconnect() SSID is reset.
My code to initialise wifiManager is here.

This is the log I've got. 1st attempt it shows it tries to connect to my SSID, but following trials show an empty SSID string.

*WM: Adding parameter
*WM: mqttserver
*WM: Adding parameter
*WM: mqttport
*WM: Adding parameter
*WM: mqttuser
*WM: Adding parameter
*WM: mqttpass
*WM: Adding parameter
*WM: mqtttopic
[186] 38096 free (configWiFiManager:179) Connecting to WiFi: MY_SSID
*WM: 
*WM: AutoConnect Try No.:
*WM: 0
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 1
*WM: SET AP STA
*WM: 
*WM: Configuring access point... 
*WM: EnigmaIoTMQTTBridge2410ac
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: DUP AP: WLAN_11F3
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: DUP AP: WLAN_11F3
[69922] 34792 free (setup:252) Error connecting to WiFi

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
ve56aed65
~ld

*WM: Adding parameter
*WM: mqttserver
*WM: Adding parameter
*WM: mqttport
*WM: Adding parameter
*WM: mqttuser
*WM: Adding parameter
*WM: mqttpass
*WM: Adding parameter
*WM: mqtttopic
[190] 36584 free (configWiFiManager:179) Connecting to WiFi: 
*WM: 
*WM: AutoConnect Try No.:
*WM: 0
*WM: Connecting as wifi client...
*WM: Try to connect with saved credentials
*WM: Connection result: 
*WM: 0
*WM: SET AP STA
*WM: 
*WM: Configuring access point... 
*WM: EnigmaIoTMQTTBridge2410ac
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: DUP AP: WLAN_11F3
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: DUP AP: WLAN_11F3
[60371] 34680 free (setup:252) Error connecting to WiFi

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
ve56aed65
~ld

It keeps so until I reconfigure WiFi credentials using web portal.

I'm not sure if I am doing something wrong.

Compiler error after latest platform.io update

Hello,

I used the library on an ESP32 (Lolin32) board. Since the latest platform.io update (espressif32 platform is now @ 1.1.2) I get the following errors:

In file included from .piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp:14:0:
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.h: In constructor 'AsyncWiFiManager::AsyncWiFiManager(AsyncWebServer*
, DNSServer*)':
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.h:166:19: warning: 'AsyncWiFiManager::server' will be initialized aft
er [-Wreorder]
AsyncWebServer *server;

^
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.h:164:19: warning:   'DNSServer* AsyncWiFiManager::dnsServer' [-Wreor
der]
DNSServer      *dnsServer;
^
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp:67:1: warning:   when initialized here [-Wreorder]
AsyncWiFiManager::AsyncWiFiManager(AsyncWebServer *server, DNSServer *dns) :server(server), dnsServer(dns) {
^
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp: In member function 'void AsyncWiFiManager::scan()':
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp:283:16: warning: unused variable 'res' [-Wunused-variable]
bool res=WiFi.getNetworkInfo(i, wifiSSIDs[i].SSID, wifiSSIDs[i].encryptionType, wifiSSIDs[i].RSSI, wifiSSIDs[i].BSSID, wifiSSIDs
[i].channel);
^
In file included from .piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.h:21:0,
from .piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp:14:
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp: In member function 'void AsyncWiFiManager::startWPS()':
/Users/to/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32/esp_wps.h:86:1: error: C99 designator 'manuf
acturer' outside aggregate initializer
}
^
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp:590:29: note: in expansion of macro 'WPS_CONFIG_INIT_DEFAULT'
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
^
/Users/to/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32/esp_wps.h:86:1: error: C99 designator 'model
_number' outside aggregate initializer
}
^
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp:590:29: note: in expansion of macro 'WPS_CONFIG_INIT_DEFAULT'
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
^
/Users/to/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32/esp_wps.h:86:1: error: C99 designator 'model
_name' outside aggregate initializer
}
^
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp:590:29: note: in expansion of macro 'WPS_CONFIG_INIT_DEFAULT'
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
^
/Users/to/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32/esp_wps.h:86:1: error: C99 designator 'devic
e_name' outside aggregate initializer
}
^
.piolibdeps/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp:590:29: note: in expansion of macro 'WPS_CONFIG_INIT_DEFAULT'
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
^
*** [.pioenvs/lolin32/lib2d4/ESPAsyncWifiManager_ID1438/ESPAsyncWiFiManager.cpp.o] Error 1

Suggestions on how to debug a failed connection

I am currently shipping a product that used this Async WiFi Manager. It is working great on 99% of the devices, but I have a couple of people who try to connect and it just fails, but I can't tell why. It goes through the whole captive process and looks like it should be working, but then never completes the connection

  1. I walked them through checking whether they have a MAC filter on.
  2. I had one person switch their device to have different SSIDs for the 2.4GHz and 5GHz

Both were with older routers (an Apple Airport Express and an ActionTec Model C1000A cable modem+router). I just don't have a good way to debug these issues without having them (a) install FTDI or CH340 drivers, (b) install a serial monitor, (c) have them try to capture the serial output and send it to me.

I am open to suggestions.

Android devices not automatically redirected to captive portal on ESP32

After connecting to the local network, I am not automatically brought to the portal page. I can reach it by entering it's local IP in a browser, or by selecting "manage router" in the network settings, but I'd rather the captive portal was just automatically detected like a "cafe style" login page.

Unable to access Captive Portal

I have hard time setting up this library.
I'm using Wemos D1 mini and PlatformIO as IDE.

My code is very simple (based on one of Your examples):

#include <FS.h>                   //this needs to be first, or it all crashes and burns...

#if defined(ESP8266)
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#else
#include <WiFi.h>
#endif

//needed for library
#include <ESPAsyncWebServer.h>
#include <ESPAsyncWiFiManager.h>         //https://github.com/tzapu/WiFiManager

#include "config.h"

//////////////////////////variables//////////////////////////
AsyncWebSocket ws("/ws");
AsyncWebServer server(80);
DNSServer dns;

///////////////////////////////////////////////////////////////////////////

void configModeCallback(AsyncWiFiManager *myWiFiManager)
{
    Serial.println("Entered config mode");
    Serial.println(WiFi.softAPIP());

    Serial.println(myWiFiManager->getConfigPortalSSID());
}

void setup()
{
    Serial.begin(115200);
    Serial.setDebugOutput(true);

    // Wait for connection
    AsyncWiFiManager wifiManager(&server, &dns);

    wifiManager.setAPCallback(configModeCallback);
    if (!wifiManager.autoConnect("TestAP", "password"))
    {
        Serial.println("failed to connect, we should reset as see if it connects");
        delay(30000);
        ESP.reset();
        delay(5000);
    }

    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");
    Serial.println("local ip");
    Serial.println(WiFi.localIP());

    server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
        request->send(200, "text/plain", "Hello World");
    });

    server.on("/reset", HTTP_GET, [](AsyncWebServerRequest *request) {
        ESP.restart();
    });

    server.onNotFound([](AsyncWebServerRequest *request) {
        request->send(404);
    });

    // Start the webserver
    //
    server.begin();
    Serial.println("Webserver started ");

    pinMode(BUILTIN_LED, OUTPUT); // initialize onboard LED as output

    Serial.println("Led setup");
}

int led_1_blink_time = 200;
long led_1_last_blink;

void loop()
{
    if ((millis() - led_1_last_blink) >= led_1_blink_time)
    {
        if (digitalRead(BUILTIN_LED) == HIGH)
        {
            digitalWrite(BUILTIN_LED, LOW);
        }
        else
        {
            digitalWrite(BUILTIN_LED, HIGH);
        }
        led_1_last_blink = millis();
    }
}

When I upload this code to my board I can see this output in Serial Port monitor:

;l␀d��|␀�$�|␃␄␌␄�␄$�␄c|��␂�␛�{�c�␄c��o'�lno���␌b␜x��l;l{lp�g�␐␃␄␄�␄l␄��␄␌␄c␌n�|␃$�␄␌�c��o'�␀l��d␃�␓␛gn␌d␂␇␃gs�ۓn␌␄#␌�␎d␏;��g␄␌c␄�␏l�sĜ��␜␃␄␌d`␂��o�␃�*WM:
*WM: AutoConnect
bcn 0
del if1
mode : sta(2c:3a:e8:01:0c:27)
*WM: Connecting as wifi client...
*WM: Try to connect with saved credentials
*WM: Connection result:
*WM: 0
mode : sta(2c:3a:e8:01:0c:27) + softAP(2e:3a:e8:01:0c:27)
add if1
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
*WM: SET AP STA
Entered config mode
192.168.4.1
TestAP
*WM:
*WM: Configuring access point...
*WM: TestAP
*WM: password
add 1
aid 1
station: 6c:91:2e:b3:72:03 join, AID = 1
*WM: AP IP address:
*WM: 192.168.4.1
*WM: HTTP server started
*WM: About to scan()
*WM: About to scan()
f r0, scandone
*WM: Scan done
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
*WM: About to scan()
*WM: About to scan()
f r0, LmacRxBlk:1
LmacRxBlk:1
scandone
*WM: Scan done
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1

I'm just getting started with Wemos and Arduino stuff, so I don't know how should I interpret that output.
Any hints are more than welcome!

Using different port other than 80

This is more of a question and not an issue.

Can I use other ports? Other than 80? Port 80 conflicts with my other program when I combine the WifiManagerAsync.
AsyncWebServer server_Wifimanger(80);

Forget connection settings

Hi!
Is there any way to forget the connection settings?
I would like to use the autoconnect in the normal mode but enter the config portal on demand
Is it possible?
Thanks

not compatible with Alexa?

so far I have been using another wifi library, but I really don't want to hardcode my password, the problem is that as soon as I use this library to stablish connection Alexa cannot find the connected devices, I can clearly see my esp8266 connected to my router, how can I solve this problem? I tried with different examples and all has the same outcome, is there something in particular that I should be looking for?

this is the last one that I tried (just a copy and paste of one of the examples), all seems to be working as expected but for Alexa not finding the device at all

#include <Arduino.h>
#include <fauxmoESP.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#else
#include <WiFi.h>
#endif

//needed for library
#include <ESPAsyncWebServer.h>
#include <ESPAsyncWiFiManager.h>    


DNSServer dnsServer;
AsyncWebServer server(80);

fauxmoESP fauxmo;
bool MoveCommand = false;

void setup() {
  Serial.begin(115200);
  WifiSetup();
  AlexaSetup();
}

class CaptiveRequestHandler : public AsyncWebHandler {
public:
  CaptiveRequestHandler() {}
  virtual ~CaptiveRequestHandler() {}

  bool canHandle(AsyncWebServerRequest *request){
    //request->addInterestingHeader("ANY");
    return true;
  }

  void handleRequest(AsyncWebServerRequest *request) {
    AsyncResponseStream *response = request->beginResponseStream("text/html");
    response->print("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
    response->print("<p>This is out captive portal front page.</p>");
    response->printf("<p>You were trying to reach: http://%s%s</p>", request->host().c_str(), request->url().c_str());
    response->printf("<p>Try opening <a href='http://%s'>this link</a> instead</p>", WiFi.softAPIP().toString().c_str());
    response->print("</body></html>");
    request->send(response);
  }
};

void AlexaSetup(){
  
  fauxmo.addDevice("motor on");
    fauxmo.setPort(80); // required for gen3 devices
    fauxmo.enable(true);
    

  fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
    Serial.println("alexa can hear you");
        MoveCommand = true;
    });
    
      Serial.println("alexa device setup complete");
}

void WifiSetup(){
   WiFi.softAP("esp-captive");
  dnsServer.start(53, "*", WiFi.softAPIP());
  server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER);//only when requested from AP
  //more handlers...
  server.begin();
}

void loop() {
 fauxmo.handle();

 if(MoveCommand){
  Serial.println("completed!");
 }
}

task_wdt: - async_tcp (CPU 0/1) ESP32

Hey. I am trying to design my own wifi manager program for ESP32.
Initially, I start ESP32 in access point and start a weberver where user can select wifi network and input ID and Password credentials. After submitting the ID and Password, I turn OFF the wifi and wait for 5 seconds. After that, I start wifi in Station mode and attempt to connect to the select WIFI network with given ID and Password credentials, If failed, start an access point again.
This is the setup code which attempts to connect to WIFI, if not succesfull, start and Acces point:

void setup() {
for (int i = 0; i < 10; ++i){
  list_of_networks[i] = (char*)malloc( 256 ); // string length up to 255 bytes + null
}
 Serial.begin(115200);
 if(!SPIFFS.begin(true)){
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }

  
 drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
 number_of_wifi_networks=scan_wifi_networks();
 for (int i=0;i<=number_of_wifi_networks;i++)
 {
    Serial.println(list_strings[i]);
 }
 delay(2000);

 
  if (drd->detectDoubleReset()) 
  {
    Serial.println("Double Reset Detected");
    handle_access_point();
  } 
  else 
  {
    Serial.println("No Double Reset Detected");
    WiFi.mode(WIFI_STA);//start program by attempting to connect to wifi
    char temp_buffer_ID[100];
    char temp_buffer_Pass[100];
    readFile(SPIFFS, "/ID.txt").toCharArray(temp_buffer_ID, sizeof(temp_buffer_ID));
    readFile(SPIFFS, "/Pass.txt").toCharArray(temp_buffer_Pass, sizeof(temp_buffer_Pass));
    Serial.print("Spiffs id converted to char array=");
    Serial.println(temp_buffer_ID);
    Serial.print("Spiffs password converted to char array=");
    Serial.println(temp_buffer_Pass);
    WiFi.begin(ssid,password);
    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
      Serial.println("WiFi Failed!");
      handle_access_point();
      return;
    }
    Serial.println();
    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());
  }

}

Access point code:

void handle_access_point() {

  WiFi.mode(WIFI_AP);
  WiFi.softAPdisconnect (true);
  WiFi.softAP("ESPNOW123", nullptr, 3);
  Serial.print("MAC address of this node is ");
  Serial.println(WiFi.softAPmacAddress());
  Serial.println();
  Serial.print("IP address: ");
  Serial.println(WiFi.softAPIP());


  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    //request->send(SPIFFS, "/index.html", String(), false);
    request->send(200, "text/html", SendHTML());
    Serial.println("executing index page");
  });

  
  server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/style.css", "text/css");
  });

 server.on("/static", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/static.html", String(), false, processor_static);
    Serial.println("executing static page");
  });

server.on("/action_page", HTTP_GET, [](AsyncWebServerRequest * request) {
    Serial.println("executing action page");
    int paramsNr = request->params();
    String inputMessage_ID;
    String inputMessage_Pass;
    Serial.println(paramsNr);

        if (request->hasParam("Network_ID")) {
          inputMessage_ID = request->getParam("Network_ID")->value();
          Serial.print("Input message ID: ");
          Serial.println(inputMessage_ID);
          writeFile(SPIFFS, "/ID.txt", inputMessage_ID.c_str());
        }

        if (request->hasParam("Network_pass")) {
          inputMessage_Pass = request->getParam("Network_pass")->value();
          Serial.print("Input message pass: ");
          Serial.println(inputMessage_Pass);
          writeFile(SPIFFS, "/Pass.txt", inputMessage_Pass.c_str());
        }


    //request->send(SPIFFS, "/action_page.html");
    request->send(200, "text/html", "<h1>The following values has been changed:</h1> <br>  Network_ID: " + inputMessage_ID +"<br> Network_Pass:"+inputMessage_Pass+"<br><a href=\"/\">Return to Home Page</a>");
    delay(1000);
    attempt_wifi_connection(inputMessage_ID,inputMessage_Pass);
  });

  server.begin();
}
void attempt_wifi_connection(String ID_string, String Pass_string){
//void attempt_wifi_connection(char* ID_string, char* Pass_string){
  Serial.println("turning OFF wifi and waiting for 5 sec");
  WiFi.mode(WIFI_OFF); // First turn OFF the WIFI interface
  delay(5000); //Needed, at least in my tests WiFi doesn't power off without this for some reason
  Serial.println("5 seconds had passed");
  char temp_buffer_ID[100]; // temporary storage for char array ID
  char temp_buffer_Pass[100]; // temporary storage for char array Password
   //Convert String type ID and password to char array
   ID_string.toCharArray(temp_buffer_ID, sizeof(temp_buffer_ID));
   Pass_string.toCharArray(temp_buffer_Pass, sizeof(temp_buffer_Pass));
   Serial.print("Attempting to connect to the wifi with ID and password=");
   Serial.println(temp_buffer_ID);
   Serial.println(temp_buffer_Pass);


   
   WiFi.mode(WIFI_STA);//start program by attempting to connect to wifi
   WiFi.begin(temp_buffer_ID,temp_buffer_Pass);
   //WiFi.begin(ID_string.c_str(),Pass_string.c_str());
   if(WiFi.waitForConnectResult() != WL_CONNECTED)
    {
    Serial.println("WiFi Failed!");
    handle_access_point();
    return;
    }
    
   Serial.println("Connection sucessful");
   Serial.print("IP Address: ");
   Serial.println(WiFi.localIP());
}

However, I am noticing a strange behaviour when submitting the ID and password, I can see that attempt_wifi_connect function executes but immediately after 5 seconds delay the device restarts without even printing the following line:
Serial.println("5 seconds had passed");

image

I have tried googling but could not find a real solution to this problem. Is this a known issue?

Destroy/Reset AsyncWebserver & DNS after successful connect?

Great work @alanswx, saved me tons of time re-coding WiFiManager.
In line 484, could you destroy/reset both AsyncWebserver & DNS after successful connect?

dnsServer = DNSServer();
server.reset();

This way the server is usable after AsyncWiFiManger connect, or else both DNS and webserver become unusable. Let me know if you want me to create a PR.

Maybe this will also solve #17

Captive portal not accessible sometimes

I am using the following;

  1. ESPAsyncTCP
  2. ESPAsyncWebServer
  3. ESPAsyncWifiManager
  4. 2.4.0-rc1 ESP8266 core
  5. NodeMCU board 12E variant
  6. Arduino IDE 1.8.3 on Mac OS
    All libraries are as of today the 27th August 2017.

On a newly programmed ESP8266, or after I do a WiFi.disconnect(); or wifiManager.resetSettings(); the serial terminal shows me that I am running in access point mode...

*WM: HTTP server started

Then after about 2 seconds I get this

*WM: About to scan()
*WM: About to scan()

then at about 5 seconds it prints

*WM: Scan done

And then after about 12 seconds it repeats the above until my configPortalTimeout, or until I try to connect to it.

*WM: HTTP server started
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
*WM: About to scan()
*WM: About to scan()
*WM: Scan done

I then have random success connecting to it as an AP. Sometimes it connects and gives me a blank captive portal page. Sometimes it won't connect. Sometimes it will connect but won't let me save.

At the start of my code I have

AsyncWebServer server(80);
DNSServer dns;

I am using a timeout as follows;

wifiManager.setConfigPortalTimeout(180);

I am using the following so I can start and stop EspAsyncMQTT

WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;

void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
  Serial.println(F("[WIFI] {DIS} Disconnected from Wi-Fi."));
  mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
}

void onWifiConnect(const WiFiEventStationModeGotIP& event) {
  Serial.println(F("[WIFI] {CON} Connected to Wi-Fi."));
  if (WiFi.isConnected()) {
    mqttReconnectTimer.once(2, connectToMqtt);
    Serial.println(F("[MQTT] {CON} Re-connecting"));
  }
}

I have been using the non Async version for a long time successfully on many projects so I don't really know what's going on here.

Reset when in AP mode

Hi,

When trying to scan in AP mode i see resets, sta or ap+sta don't make this.
Do you have an idea?

*WM: About to scan()
mode : sta(5c:cf:7f:18:3d:7c) + softAP(5e:cf:7f:18:3d:7c)
add if0
Fatal exception 0(IllegalInstructionCause):
epc1=0x402189cc, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

Exception (0):
epc1=0x402189cc epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont
sp: 3fff2840 end: 3fff2d00 offset: 01a0

stack>>>

Can't connect to AP after power cycle

Hi,

If I power cycle my ESP32 after uploading my sketch. I can no longer connect to the AP from either windows or iPhone. The iPhone just says the password is invalid every time I enter it. Windows just says it can't connect.

Considering moving captive portal page to a template in SPIFFS

Is there a design goal that precludes taking advantage of the built-in template engine in ESPAsyncWebServer to store and server the captive portal template content from SPIFFS? I ask this before I undertake to do so, in case there are compelling reasons not to do so. While my first thought was for dependencies, it seems all those dependencies (fs.h and hardware that supports SPIFFS, I guess) are baked into ESPAsyncWebServer already, so that shouldn't play into it. Are there other considerations I'm overlooking?

The obvious advantage to serving that content out of SPIFFS, is the ability to highly customize the portal appearance without need to modify the library directly.

Compile error C99 on esp_wps.h

Hi all, I see that this has been brought up before, #26 and apparently fixed, but I am getting the same error if I try and compile ESPAsyncWiFiManager.h in PlatformIO. I wonder what was done to fix it and how I can somehow have a version that does not compile, I did a quick check an I seem to have espresives most recent files and the espasyncwifimanager.h code still references esp_wps.h, I can only think esp_wpsh has changed to correct the wps issue but I do not have that file, I looked for a local version here as it is referred to in "" but I can't see it in the files here unless I have gone code blind ;) I'm sure it is something simple I have overlooked.

Compiler error after latest Arduino update to the latest code

Hi!
Your example AutoConnect.ino compile with errors:
In file included from C:\Users---\Documents\Arduino\libraries\ESPAsyncWiFiManager-master\ESPAsyncWiFiManager.h:21:0,

             from C:\Users\---\Documents\Arduino\libraries\ESPAsyncWiFiManager-master\ESPAsyncWiFiManager.cpp:14:

C:\Users---\Documents\Arduino\libraries\ESPAsyncWiFiManager-master\ESPAsyncWiFiManager.cpp: In member function 'void AsyncWiFiManager::startWPS()':

C:\Users---\Documents\Arduino\hardware\espressif\esp32/tools/sdk/include/esp32/esp_wps.h:86:1: error: C99 designator 'manufacturer' outside aggregate initializer
}
^
C:\Users---\Documents\Arduino\libraries\ESPAsyncWiFiManager-master\ESPAsyncWiFiManager.cpp:590:29: note: in expansion of macro 'WPS_CONFIG_INIT_DEFAULT'
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
^
C:\Users---\Documents\Arduino\hardware\espressif\esp32/tools/sdk/include/esp32/esp_wps.h:86:1: error: C99 designator 'model_number' outside aggregate initializer
}
^
C:\Users---\Documents\Arduino\libraries\ESPAsyncWiFiManager-master\ESPAsyncWiFiManager.cpp:590:29: note: in expansion of macro 'WPS_CONFIG_INIT_DEFAULT'
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
^
C:\Users---\Documents\Arduino\hardware\espressif\esp32/tools/sdk/include/esp32/esp_wps.h:86:1: error: C99 designator 'model_name' outside aggregate initializer
}
^
C:\Users---\Documents\Arduino\libraries\ESPAsyncWiFiManager-master\ESPAsyncWiFiManager.cpp:590:29: note: in expansion of macro 'WPS_CONFIG_INIT_DEFAULT'
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
^
C:\Users---\Documents\Arduino\hardware\espressif\esp32/tools/sdk/include/esp32/esp_wps.h:86:1: error: C99 designator 'device_name' outside aggregate initializer
}
^
C:\Users---\Documents\Arduino\libraries\ESPAsyncWiFiManager-master\ESPAsyncWiFiManager.cpp:590:29: note: in expansion of macro 'WPS_CONFIG_INIT_DEFAULT'
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
^

ESP-32: crash on Wifi scan

Hi,

i get this ESP-32 crash on startup with a simple scetch. Log:

*WM:
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Try to connect with saved credentials
*WM: Connection result:
*WM: 6
*WM: SET AP STA
*WM:
*WM: Configuring access point...
*WM: ESP30AEA4730518
*WM: AP IP address:
*WM: 192.168.4.1
*WM: HTTP server started
*WM: About to scan()
*WM: About to scan()
*WM: Scan done
abort() was called at PC 0x401458bb on core 1

Backtrace: 0x40090450:0x3ffb1c20 0x40090681:0x3ffb1c40 0x401458bb:0x3ffb1c60 0x40145902:0x3ffb1c80 0x40145217:0x3ffb1ca0 0x40145306:0x3ffb1cc0 0x401452bd:0x3ffb1ce0 0x400de7e7:0x3ffb1d00 0x400dea3d:0x3ffb1d60 0x400ded31:0x3ffb1df0 0x400ded89:0x3ffb1e30 0x400d2293:0x3ffb1e70 0x40145e5b:0x3ffb1fb0 0x400927d9:0x3ffb1fd0

Rebooting...
ets Jun 8 2016 00:22:57

exception trace is:

grafik

So something went wrong here (ESPAsyncWiFiManager.cpp line 274):

    wifiSSIDs = new WiFiResult[n];

i assume "n" is out of range? Problem in cleanup? Any idea?

using latest revsions..
Best Dirk

Return scanned wifi as string

Hi,
Is it possible to add these to your repo?
Returns scanned wifi as string

class AsyncWiFiManager
{
  public:
    AsyncWiFiManager(AsyncWebServer * server, DNSServer *dns);

    void          scan();
    String        scanme();

cpp:


String AsyncWiFiManager::scanme( )
{
   //if (!shouldscan) return;
DEBUG_WM(F("About to scan()"));
if (wifiSSIDscan)
{
  delay(100);
}

if (wifiSSIDscan)
{
    int n = WiFi.scanNetworks();
    DEBUG_WM(F("Scan done"));
    if (n == 0) {
      DEBUG_WM(F("No networks found"));
     // page += F("No networks found. Refresh to scan again.");
    } else {


if (wifiSSIDscan)
{
/* WE SHOULD MOVE THIS IN PLACE ATOMICALLY */
  if (wifiSSIDs) delete [] wifiSSIDs;
  wifiSSIDs = new WiFiResult[n];
  wifiSSIDCount = n;

  if (n>0)
      shouldscan=false;

  for (int i=0;i<n;i++)
  {
       wifiSSIDs[i].duplicate=false;

    bool res=WiFi.getNetworkInfo(i, wifiSSIDs[i].SSID, wifiSSIDs[i].encryptionType, wifiSSIDs[i].RSSI, wifiSSIDs[i].BSSID, wifiSSIDs[i].channel, wifiSSIDs[i].isHidden);
  }


      // RSSI SORT

      // old sort
      for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
          if (wifiSSIDs[j].RSSI > wifiSSIDs[i].RSSI) {
            std::swap(wifiSSIDs[i], wifiSSIDs[j]);
          }
        }
      }


      // remove duplicates ( must be RSSI sorted )
      if (_removeDuplicateAPs) {
        String cssid;
        for (int i = 0; i < n; i++) {
          if (wifiSSIDs[i].duplicate == true) continue;
          cssid = wifiSSIDs[i].SSID;
          for (int j = i + 1; j < n; j++) {
            if (cssid == wifiSSIDs[j].SSID) {
              DEBUG_WM("DUP AP: " +wifiSSIDs[j].SSID);
              wifiSSIDs[j].duplicate=true; // set dup aps to NULL
            }
          }
        }
      }
      String page = FPSTR(WFM_HTTP_HEAD);
String pager ;
      //display networks in page
      for (int i = 0; i < n; i++) {
        if (wifiSSIDs[i].duplicate == true) continue; // skip dups
        DEBUG_WM(wifiSSIDs[i].SSID);

        DEBUG_WM(wifiSSIDs[i].RSSI);
        int quality = getRSSIasQuality(wifiSSIDs[i].RSSI);

        if (_minimumQuality == -1 || _minimumQuality < quality) {
          String item = FPSTR(HTTP_ITEM);
          String rssiQ;
          rssiQ += quality;
          item.replace("{v}", wifiSSIDs[i].SSID);
          item.replace("{r}", rssiQ);
          if (wifiSSIDs[i].encryptionType != ENC_TYPE_NONE) {
            item.replace("{i}", "l");
          } else {
            item.replace("{i}", "");
          }
          //DEBUG_WM(item);
          page += item;
          pager += item;
          delay(0);

        } else {
          DEBUG_WM(F("Skipping due to quality"));
        }

      }
    //  request->send(200, "text/html", page);
    return pager;
}
}
}
}

usage:
Get an interrupt and scan in loop, send String response with web socket.
Result: directly add response (

...) to html page.

bool searchWifi =false;
void loop() {
  ArduinoOTA.handle();
  //  wifiManager.loop(); no need if you dont need to use captive portal etc..

  if (searchWifi) {
    String ok = wifiManager.scanme(); //returns scanned wifi
    ws.textAll(ok);
    searchWifi = false;  
 }
}

Why is switch to revert to station/client only mode commented out?

Just wondering if this was done due to a bug/issue, or was something that didn't get finished. I love this library, as it allows me to have the wifi non-blocking through the modeless functionality, and able to use ESPAsyncWebServer as well, but I'd rather the ESPs AP shut down if a connection to the configured AP is established, rather than leave it running all the time.

//connected
// alanswx - should we have a config to decide if we should shut down AP?
// WiFi.mode(WIFI_STA);

STA mode static IP DNS not set

get host by name doesn't works after operning Wifi connection via static ip assignement

This appens because after a call to
void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
The body of the method
int AsyncWiFiManager::connectWifi(String ssid, String pass)
doesnt properly initializes WiFi

// check if we've got static_ip settings, if we do, use those.
 if (_sta_static_ip) {
   DEBUG_WM(F("Custom STA IP/GW/Subnet"));
   WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
   DEBUG_WM(WiFi.localIP());
 }

at least one of DNS1 or DNS2 should be assigned in static IP configuration
thus should call
WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn, **dns1**, **dns2**);

please fix

Captive Portal doesn't appear on iPhone

Hi,

I'm using this on an ESP32. The captive portal never appears when I connect to it with an iPhone. It does appear if I connect using windows. I tried turning on debug, but it doesn't print anything to the console.

Custom Parameters

Hello and thank you for your library

i`m need to add some custom parameters to my wifi settings page , but as i say only text inputs can added now , can you consider this feature in next version ? my first priority is drop down element

Captive Portal without AsyncDNS

Apparently without EADNS, the "loop" function was not being called and so dnsServer->processNextRequest(); was also not getting called so Captive Portal was not working. I added a call to loop() inside the while of startconfigPortal and it works great now. Thanks...

Curious But Not Forked

I'm curious and will be interested in pulling it into this version https://github.com/kentaylor/WiFiManager when it works well. The biggest delay for me is slow server start up rather than queued requests though.

It would be easier to figure out what you have changed if you forked it from another repository rather than starting a new one.

Implement non-blocking mode

WifiManager in development branch have setConfigPortalBlocking function. It is handy to have some code running in background or utilize same webserver instance for actual web serving purposes for wifi clients.

How to use WiFiManager only as a fallback if a certain network is not there?

(Follow-up post from tzapu/WiFiManager#497)

I need to use WiFiManager only as a fallback if a certain network (homeNetwork) is not there.

However, if I do the following then apparently the credentials do not get saved and loaded correctly - after a reboot, AutoConnectAP is always spawned.

How to fix this?

#if defined(ESP8266)
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#else
#include <WiFi.h>
#endif

#include <DNSServer.h>
#include <ESPAsyncWebServer.h>
#include <ESPAsyncWiFiManager.h>

AsyncWebServer server(80);
DNSServer dns;

void setup() {
  Serial.begin(115200);

  bool homeNetworkAvailable = false;

  // Check if the home network is available
  // it needs some special authentication mechanism through a captive portal
  // (not shown in this example)

  int n = WiFi.scanNetworks();
  randomSeed(ESP.getCycleCount());
  Serial.println("scan done");
  if (n == 0)
    Serial.println("no networks found");
  else
  {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i)
    {
      // Print SSID and RSSI for each network found
      Serial.println(WiFi.SSID(i));
      if (WiFi.SSID(i) == "homeNetwork") { // enter the ssid which you want to search
        Serial.println("The homeNetwork network is available, trying to log in");
        homeNetworkAvailable = true;

      }
    }
  }

  // ONLY if the home network is NOT available use AsyncWiFiManager
  // This works only ONCE, after a reboot I get "*WM: No saved credentials
  // FIXME

  if (homeNetworkAvailable == false) {
    AsyncWiFiManager wifiManager(&server, &dns);
    //wifiManager.resetSettings(); // reset settings - for testing
    wifiManager.setTimeout(180);

    if (!wifiManager.autoConnect("AutoConnectAP")) {
      Serial.println("failed to connect and hit timeout");
      delay(3000);
      ESP.reset();
      delay(5000);
    }
  }

  Serial.println("connected...yeey :)");

}

void loop() {
  // put your main code here, to run repeatedly:

}

Bypass opening screen

Hi
Is there a way to bypass the opening screen with configure, info and reset and go straight to "Configure wifi" with scan.
thanks

PlatformIO compiler warnings: unused variable and signed / unsigned int comparison

PlatformIO compiler gives this warning: "In member function 'void AsyncWiFiManager::copySSIDInfo(wifi_ssid_count_t)':
.pio/libdeps/d1_mini/ESPAsyncWiFiManager/ESPAsyncWiFiManager.cpp:312:12: warning: unused variable 'res' [-Wunused-variable]
bool res=WiFi.getNetworkInfo(i, wifiSSIDs[i].SSID, wifiSSIDs[i].encryptionType, wifiSSIDs[i].RSSI, wifiSSIDs[i].BSSID, wifiSSIDs[i].channel, wifiSSIDs[i]." The code is below - it appears it can safely be deleted to eliminate this warning.

#if defined(ESP8266)
      bool res=WiFi.getNetworkInfo(i, wifiSSIDs[i].SSID, wifiSSIDs[i].encryptionType, wifiSSIDs[i].RSSI, wifiSSIDs[i].BSSID, wifiSSIDs[i].channel, wifiSSIDs[i].isHidden);
#else
      bool res=WiFi.getNetworkInfo(i, wifiSSIDs[i].SSID, wifiSSIDs[i].encryptionType, wifiSSIDs[i].RSSI, wifiSSIDs[i].BSSID, wifiSSIDs[i].channel);
#endif

And this warning:
"In member function 'boolean AsyncWiFiManager::isIp(String)':
.pio/libdeps/d1_mini/ESPAsyncWiFiManager/ESPAsyncWiFiManager.cpp:1162:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < str.length(); i++) { "
The code for that is:

boolean AsyncWiFiManager::isIp(String str) {
  for (int i = 0; i < str.length(); i++) {

String::length() returns a size_t, which is an unsigned integral type. I think the warning will go away by making i an unsigned int:

boolean AsyncWiFiManager::isIp(String str) {
  for (unsigned int i = 0; i < str.length(); i++) {

Captive portal not appearing

Hello! Some time ago I have made a PR #32 that fixes the problem that the captive portal was not appearing, would like to know if it can be merged.

Thanks!

Migrate to ESPAsyncDNSServer?

How difficult is it to migrate to ESPAsyncDNSServer from DNSServer? Looks like a drop-in replacement of DNSServer.h -> ESPAsyncDNSServer.h.

Just removing all handleNextRequest() calls is sufficient for migration.

Access Point AP Not Starting : ESP32 Sparkfun Thingy

image

It was working fine until reandomly it just wasn't. I noticed that sometime it would report :
"About to scan()", but then connect anyway.
However now, it reports the same and "WM: DUP AP: TPG-RGBW", and now never connects and constantly runs into timeouts.

image
image

Can anyone help with this or suggest a method to try and fix. Happy to run extra code for debug purposes.

WM: No saved credentials

Hi,

i try to use your library together with ESPWebserver to replace the sync->async versions.
Captive portal works fine, i can connect to my WIFI.
But after hard resetting the AP is opened again, message is
WM: No saved credentials.

As far as i see WiFi.SSID cannot be read if not connected. Credentials are saved but not accessable if Wifi.begin(); is not yet called.

Problem seems in ESPAsyncWiFiManager.cpp:

AsyncWiFiManager::connectWifi(String ssid, String pass);
..
WiFi.SSID() is empty even if a connection was made before reset.

After making this changes the credentials are working fine:
before (Line 530):
DEBUG_WM("No saved credentials");
after:
DEBUG_WM("Try to connect with saved credentials");
WiFi.begin();

I use latest ESP32 aduino github version 20. march 2018 and your library version 0.13

Best regards
Dirk

Offline actions.

Hello

I've noticed that sometimes i need the plant to work even before i set an access point to connect to it, As a normal operation.

So, And because this library called "Async", I propose to make it fully meant .

I don't know if this concept is supported here, If so please guide me.

Note : I've heard of Esparto library, I've read some of it without implementation. Could it help ?

Reset Settings is not working on ESP32

ESP32 IDF3.2
PlatformIO Version 1.8

Please find the logs as below

*WM: settings invalidated
*WM: THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.
*WM:
*WM: AutoConnect Try No.:
*WM: 0
*WM: Connecting as wifi client...
*WM: Try to connect with saved credentials
*WM: Connection result:
*WM: 3
*WM: IP Address:

WifiMan Constantly Reporting "About to scan()"

Hi. Not really sure why this is happening but I think it's affecting my ability to connect to the AP. Running as ESP32 Sparkfun Thingy. Any suggestions for a fix? Happy to try anything to help solve this. @alanswx Send result 0 is me trying to connect to AP and then in just starts to scan for no reason at all.....

image

AP Not Starting on ESP8266

I include:

#include <ESPAsyncWebServer.h> #include <ESPAsyncWiFiManager.h> AsyncWebServer server(80); DNSServer dns;
In setup() I have the following code:

AsyncWiFiManager wifiManager(&server, &dns); if (!wifiManager.autoConnect("TEST-AP", "test-ap")) { BroadcastMessageLn("Failed to connect and hit timeout"); ESP.reset(); delay(1000); }
However, when I execute the code, I see the following in serial over and over:

13:43:25.529 -> *WM: About to scan() 13:43:25.630 -> *WM: About to scan() 13:43:27.909 -> *WM: Scan done 13:43:27.942 -> *WM: DUP AP: WolfeDen-House2.4
But, it never creates an access point for configuration.

I have tried wifiManager.resetSettings(); to no avail.

What can I look at or change to fix this problem?

** UPDATED **

I used the follow "generic" example with the exact same outcome:

#if defined(ESP8266)
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#else
#include <WiFi.h>
#endif

//needed for library
#include <ESPAsyncWebServer.h>
#include <ESPAsyncWiFiManager.h>         //https://github.com/tzapu/WiFiManager

AsyncWebServer server(80);
DNSServer dns;

void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200);

    //WiFiManager
    //Local intialization. Once its business is done, there is no need to keep it around
    AsyncWiFiManager wifiManager(&server,&dns);
    //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("AutoConnectAP");
    //or use this for auto generated name ESP + ChipID
    //wifiManager.autoConnect();
    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");
}

void loop() {
    // put your main code here, to run repeatedly:
}

Guaranteed of solved problem : undefined reference to `WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool'

Hello
First of all, I had a problem related to WPS, Which was :
Arduino: 1.8.7 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, 4M (3M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

libraries\ESPAsyncWiFiManager-master\ESPAsyncWiFiManager.cpp.o: In function `AsyncWiFiManager::waitForConnectResult()':

C:\Users\Hamza\Documents\Arduino\libraries\ESPAsyncWiFiManager-master/ESPAsyncWiFiManager.cpp:1029: undefined reference to `WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool'

libraries\ESPAsyncWiFiManager-master\ESPAsyncWiFiManager.cpp.o: In function `AsyncWiFiManager::startWPS()':

C:\Users\Hamza\Documents\Arduino\libraries\ESPAsyncWiFiManager-master/ESPAsyncWiFiManager.cpp:1029: undefined reference to `WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I've followed a similar changes solved in WiFiManager library here .

Now it works well with me, But are those changes guaranteed ?

Set HostName

How can I set the hostname? calling the classic WiFi.setHostname("name"); is not working.

Problems with ESP32 and ESPAsyncWiFiManager

I have troubles to run the sample "AutoConnect" on my ESP32 (NodeMcu32).
I'm using PlatformIO and I'm able to compile and upload the binary to ESP32. I can find the "AutoConnectAP" network and connect to this network, but when I try to connect to the IP 192.168.4.1 nothing happens, and I can't reach the AsyncWiFiManager via browser.
With ESP8266 and PlatformIO the same example works well with PlatformIO with the precondition of using flag build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
Does the actual version just works with ESP8266 or is it also tested with ESP32?
BR
franzzi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.