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.softAP DHCP issue - ERROR: send_offer (error -13) #7871

Closed
4 of 6 tasks
michaloles opened this issue Feb 10, 2021 · 2 comments · Fixed by #8546
Closed
4 of 6 tasks

Wifi.softAP DHCP issue - ERROR: send_offer (error -13) #7871

michaloles opened this issue Feb 10, 2021 · 2 comments · Fixed by #8546

Comments

@michaloles
Copy link

michaloles commented Feb 10, 2021

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: ESP8266 node MCU V3
  • Core Version: 2.7.2
  • Development Env: Platformio
  • Operating System: Windows

Settings in IDE

  • Module: nodemcuv2
  • Flash Mode: [qio|dio|other]
  • Flash Size: 4MB
  • Flash Frequency: 40Mhz
  • CPU Frequency: [80Mhz
  • Upload Using: SERIAL]
  • Upload Speed: 115200

Problem Description

When I run WIFI in soft AP mode I can't connect to my board using DHCP. I've tried from different devices both Windows PC and Android phones failed during obtaining IP address. When I assign static IP everything works fine. I've checked network communication using Wireshark and DHCP offer message wasn't send from ESP. When I enabled debug I see following errors:
ERROR: send_offer (error -13)
ERROR: dhcps send ack (error -13)

I've tried different devices and play with a lot of different settings like: WiFi.setSleepMode. IP configuration, dhcps_offer_option, WiFi.mode but without success. I've also check a lot of similar issues (one with mDNS, too short password etc) but none of them fix mine. I will be really glad if somebody give me some advice.

MCVE Sketch

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncJson.h>
#include <ArduinoJson.h>
#include <DHT.h>
#include <LittleFS.h>

extern "C" {
  #include "user_interface.h"
}

void setup() {
     Serial.begin(115200);
     Serial.setDebugOutput(true);

     WiFi.setSleepMode(WIFI_NONE_SLEEP);
     WiFi.disconnect(true);
     WiFi.mode(WIFI_AP);

     uint8 mode = 1;
     wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode);

     WiFi.softAP(systemConfig.wifiName, systemConfig.wifiPassword, 9);
     delay(500); //wait for SYSTEM_EVENT_AP_START 
     WiFi.softAPConfig(IPAddress{10, 0, 0, 1}, IPAddress{10, 0, 0, 1}, IPAddress{255, 255, 255, 0});

     Serial.println("Connected:");
     Serial.println(WiFi.softAPIP());
     
     Serial.println("DHCP status:");
     Serial.println(wifi_softap_dhcps_status());

    //starting web server etc
}

void loop() {
   //basic reading sensor operation nothing heavy
}

Debug Messages

SDK:2.2.2-dev(38a443e)/Core:2.7.2=20702000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-30-g92add50/BearSSL:5c771be
sleep disable
[AP] softap config unchanged
[APConfig] local_ip: 10.0.0.1 gateway: 10.0.0.1 subnet: 255.255.255.0
[APConfig] DHCP IP start: 10.0.0.100
[APConfig] DHCP IP end: 10.0.0.200
Connected:
10.0.0.1
DHCP status:
1
wifi evt: 7
aid 1
station: 28:b2:bd:cf:c0:f1 join, AID = 1
wifi evt: 5
ERROR: send_offer (error -13)
wifi evt: 7
....
wifi evt: 7
wifi evt: 9
wifi evt: 7
ERROR: dhcps send ack (error -13)
wifi evt: 9
wifi evt: 7
wifi evt: 7
...

@d-a-v d-a-v self-assigned this Mar 2, 2021
@d-a-v d-a-v added this to the 3.0.0 milestone Mar 2, 2021
@d-a-v d-a-v modified the milestones: 3.0.0, 3.0.1 Mar 31, 2021
@d-a-v d-a-v modified the milestones: 3.0.1, 3.1 Jun 16, 2021
@mcspr
Copy link
Collaborator

mcspr commented Apr 11, 2022

The MCVE above can be fixed by changing the order of softAPConfig and softAP

Which seems to because of the way DHCP server is managed from Core via the new DHCP server object vs. the old SDK functions

if(!wifi_softap_dhcps_start()) {

#if 0
// can't use C++ now, global ctors are not initialized yet
dhcpSoftAP.begin(info);
#else

While the softAP call uses the method call directly

@mcspr
Copy link
Collaborator

mcspr commented Apr 12, 2022

...and another thing is that begin() might as well lose the ip parameter. We get it from the interface regardless of it's contents, so the ip_info struct could be created on demand

     // added for lwip-git, not sure whether useful!
      if (_netif->num == SOFTAP_IF)
      {
          ip_info info;
          info.ip      = *ip_2_ip4(&_netif->ip_addr);
          info.netmask = *ip_2_ip4(&_netif->netmask);
          info.gw      = *ip_2_ip4(&_netif->gw);
          wifi_set_ip_info(SOFTAP_IF, &info);
      }

What I am also not sure is whether the C++ notice is valid for the dhcpSoftAP object <-> SDK interaction. Re-doing it as

DhcpServer& dhcpSoftAP() {
  static DhcpServer server(netif_git[SOFTAP_IDX]);
  return server;
}

and patching the initialization to use the auto& server = dhcpSoftAP(); seems to work just fine
(so far with the mcve above)

Sure, we don't get global ctors (core_esp8266_main.cpp:do_global_ctors()), but the statically allocated data is already there?

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.

3 participants