Captive portal on ESPAsyncWebServer (LmacRxBlk:1 error)
Posted: Tue Sep 12, 2017 7:57 am
I'm trying to figure out how to set up a captive portal using the ESPAsyncWebServer and not really getting anywhere. The only information I can seem to find on the net says to start the dns server with an 'asterix' glob for the hostname pointing back to the device IP:
But as soon as I add this to my code and try to connected to the soft_AP, the console starts spitting out LmacRxBlk:1 over and over indefinitely and doesn't do anything else until I reset it. I have narrowed it down specifically to this dns line suggested by the other posts. I assume something is getting stuck in a loop, but I'm not sure what needs to be done differently as there is little or not other information I can seem to find.
I would really like to be able to trigger handheld devices such as android phones and iphones to auto-pop-up the web page of my devices as I'm trying to make a dumbed down device for random users to connect to to sign in at a specific location to say they were there. The less instructions I have to give, the better. Any help to getting a captive portal to work with the ESPAsyncWebServer code is greatly appreciated.
Longer version of my setup code:
Code: Select all
dns.start ( 53, "*", WiFi.softAPIP() );
But as soon as I add this to my code and try to connected to the soft_AP, the console starts spitting out LmacRxBlk:1 over and over indefinitely and doesn't do anything else until I reset it. I have narrowed it down specifically to this dns line suggested by the other posts. I assume something is getting stuck in a loop, but I'm not sure what needs to be done differently as there is little or not other information I can seem to find.
I would really like to be able to trigger handheld devices such as android phones and iphones to auto-pop-up the web page of my devices as I'm trying to make a dumbed down device for random users to connect to to sign in at a specific location to say they were there. The less instructions I have to give, the better. Any help to getting a captive portal to work with the ESPAsyncWebServer code is greatly appreciated.
Longer version of my setup code:
Code: Select all
// needed for platformio
#include <Arduino.h>
// needed for async webserver that doesn't seem to find Hash on platformio
#include <Hash.h>
#include <ESPAsyncWebServer.h>
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
const char* host = "FlashAsync";
const char* ssid = "ESPWiFi";
IPAddress ip ( 10, 10, 10, 1 ); // for softAP mode if used
AsyncWebServer server(80);
DNSServer dns;
// redirect used for any specific device requests for captive portal handling
void captivePortalTarget(AsyncWebServerRequest *request) {
request->redirect("/index.htm");
}
// the following three functions are run in order from setup
void initWiFi() {
WiFi.hostname(host);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig ( ip, ip, IPAddress ( 255, 255, 255, 0 ) );
WiFi.softAP(ssid);
// if uncommented, the following line produces LmacRxBlk:1 errors
//dns.start ( 53, "*", WiFi.softAPIP() ); // captive portal redirect everything to here when in AP mode
}
void initMDNS() {
if (MDNS.begin(host)) {
MDNS.addService("http", "tcp", 80);
DBG_OUTPUT_PORT.println("MDNS responder started");
DBG_OUTPUT_PORT.print("You can now connect to http://");
DBG_OUTPUT_PORT.print(host);
DBG_OUTPUT_PORT.println(".local");
}
}
void initWebserver() {
server.on("/delete", HTTP_DELETE, handleDelete);
// upload a file to /upload
server.on("/upload", HTTP_POST, returnOK, handleUpload);
// Catch-All Handlers
server.onFileUpload(handleUpload);
//server.onRequestBody(onBody);
//Android captive portal. Maybe not needed. Might be handled by notFound handler.
server.on ( "/generate_204", captivePortalTarget );
//Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
server.on ( "/fwlink", captivePortalTarget );
// my base server code uses a variation of the SD webserver to load content
// from spiffs/flash filesystem finding files when 'not found' is triggered if there are
// not specific handlers defined. An index.htm is included on the filesystem
server.onNotFound(handleNotFound);
server.begin();
DBG_OUTPUT_PORT.println("HTTP server started");
}