alanswx / ESPAsyncWiFiManager

Port WiFiManager to ESP Async Server
MIT License
219 stars 83 forks source link

Unable to access Captive Portal #24

Open Misiu opened 6 years ago

Misiu commented 6 years ago

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!

alanswx commented 6 years ago

I installed PlatformIO and ran your code.. I can't get it to work either. I will try to work on it later.

Misiu commented 6 years ago

@alanswx I'm installing Arduino IDE right now and I will try Your lib there. I have latest versions of libraries in PlatformIO. I'm using Espressif 8266 1.7.3 as platform.

If You find the reason why this might not work I'll be more than grateful.

I've noticed that similar error were described here: https://github.com/esp8266/Arduino/issues/1847 fix was to add couple of delay(0)

alanswx commented 6 years ago

There is something indeterminate about the code now. If you figure out a fix, please add a comment, and/or a pull request.

Misiu commented 6 years ago

@alanswx I found similar problem described here: https://github.com/me-no-dev/ESPAsyncWebServer/issues/228

suggested solution was to add:

void loop(){
  dnsServer.processNextRequest();
}

Did You found something regards this issue? Maybe You could add one example using PlatformIO? That would help a lot 😄

Misiu commented 6 years ago

@alanswx any news about this? Currently, I've hardcoded ssid and pass, but I'd like to add WiFiManager to my project

Misiu commented 5 years ago

@debsahu any updates on this? I saw Your PR merged. Does it fix this issue?

debsahu commented 5 years ago

@Misiu I checked with Async and regular DNS server, and everything works. An issue with Arduino ESP8266 core 2.5.0-beta3 is that captive IP is 192.168.244.1 and since the introduction of IPv6, IP return values are not null upon failing to connect. Both issues are open and being addressed.

Misiu commented 5 years ago

@debsahu thank You for the quick reply. I'll try the latest version of ESPAsyncWiFiManager with ESP8266 Core 2.4.2 (I'll wait for stable 2.5.0) Hopefully everything will work just fine :)