So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By login721
#76248 Hello .
I writing a simple captive portal using DNSServer.I can access the web server by ip ,but the captive portal now show up.What i did is wrong ?

Thank in advance!
Sorry for my bad English.

This is the source code

WiFiMan.h
Code: Select all#ifndef __WIFI_MAN_H
#define __WIFI_MAN_H

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>

class WiFiMan
{
private:
    std::unique_ptr<DNSServer> dnsServer;
    // some other codes
};
#endif



WiFiMan.cpp
Code: Select all#include "WiFiMan.h"

void WiFiMan::test()
{
    dnsServer.reset(new DNSServer());
    //setup soft ap
    WiFi.softAPConfig(apIp, apGateway, apSubnet);
    WiFi.softAP("ESP8266-Test");

    delay(500);

    dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
    dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
   
    //webserver handle codes...

    //startweb server
    webServer->begin();

    WiFi.mode(WIFI_AP_STA);

    int startConfigTime = millis();
    while(millis()-startConfigTime < CONFTIMEOUT)
    {
        dnsServer->processNextRequest();
        webServer->handleClient();
    }

    //timeout
    webServer->stop();
    dnsServer->stop();
    WiFi.softAPdisconnect(true);
}