Skip to content

WiFi.softAPConfig returns fail for non-debug build #7795

Closed
@mhightower83

Description

@mhightower83

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12
  • Core Version: [l5c29517d119393f3197871957ff18adbf918bac9]
  • Development Env: Arduino IDE
  • Operating System: Ubuntu

Settings in IDE

  • Module: [DOIT]
  • Flash Mode: [qio|]
  • Flash Size: [4MB]
  • lwip Variant: [Higher Bandwidth]
  • Reset Method: [nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200]

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 = ""
                      "<!DOCTYPE html><html lang='en'><head>"
                      "<meta name='viewport' content='width=device-width'>"
                      "<title>CaptivePortal</title></head><body>"
                      "<h1>Hello World!</h1><p>This is a captive portal example."
                      " All requests will be redirected here.</p></body></html>";

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions