Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 of 6 tasks
mhightower83 opened this issue Dec 26, 2020 · 0 comments · Fixed by #7905
Closed
5 of 6 tasks

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

mhightower83 opened this issue Dec 26, 2020 · 0 comments · Fixed by #7905

Comments

@mhightower83
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants