WiFi.softAPConfig returns fail for non-debug build · Issue #7795 · esp8266/Arduino (original) (raw)

Basic Infos

Platform

Settings in IDE

Problem Description

WiFi.softAPConfig returns fail for non-debug build.
Appears to work with the Debug port: Serial, Debug level: WIFI.

Part of the problem appears to be not setting enable in dhcp_lease before calling dhcpSoftAP.set_dhcps_lease:

struct dhcps_lease dhcp_lease;
IPAddress ip = local_ip;
ip[3] += 99;
dhcp_lease.start_ip.addr = ip.v4();
DEBUG_WIFI("[APConfig] DHCP IP start: %s\n", ip.toString().c_str());
ip[3] += 100;
dhcp_lease.end_ip.addr = ip.v4();
DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str());
if(!dhcpSoftAP.set_dhcps_lease(&dhcp_lease))

MCVE Sketch

// Modified CaptivePortal example #include <ESP8266WiFi.h> #include <DNSServer.h> #include <ESP8266WebServer.h>

#define DBGLOG_FAIL(a, fmt, ...) do { if (!(a)) { Serial.printf_P( PSTR(fmt " line: %d, function: %S\r\n"), ##VA_ARGS, LINE, FUNCTION ); } } while(false);

const byte DNS_PORT = 53; IPAddress apIP(172, 217, 28, 1); DNSServer dnsServer; ESP8266WebServer webServer(80);

String responseHTML = "" "" "" "CaptivePortal" "

Hello World!

This is a captive portal example." " All requests will be redirected here.

";

void setup() { WiFi.persistent(false); WiFi.mode(WIFI_OFF); Serial.begin(115200); delay(15); Serial.println(); Serial.println();

Serial.println("\r\ncalling: WiFi.mode(WIFI_AP)"); DBGLOG_FAIL(WiFi.mode(WIFI_AP), "Failed: WiFi.mode(WIFI_AP)");

Serial.println("\r\ncalling: WiFi.softAP(..."); DBGLOG_FAIL(WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)), "*** Failed: WiFi.softAPConfig(...");

Serial.println("\r\ncalling: WiFi.softAPConfig(..."); DBGLOG_FAIL(WiFi.softAP("DNSServer CaptivePortal example"), "Failed: WiFi.softAP(...");

dnsServer.start(DNS_PORT, "*", apIP);

Serial.println("\r\nDNSServer CaptivePortal example running");

webServer.onNotFound( { webServer.send(200, "text/html", responseHTML); }); webServer.begin(); }

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

Debug Messages

calling: WiFi.mode(WIFI_AP)

calling: WiFi.softAP(...
*** Failed: WiFi.softAPConfig(... line: 31, function: setup

calling: WiFi.softAPConfig(...

DNSServer CaptivePortal example running