0

I had written some time ago a setup procedure that worked very fine when connecting my ESP8266 Wifi module to any Android device , to a Windows 10 Desk computer and a Windows 11 laptop. This is the setup procedure :

void setup() {
  
  WiFi.persistent(false);       // to save flash memory

  Serial.begin (115200);       // debug logging port monitored through ARDUINO port 0
 
  WiFi.mode(WIFI_AP);

  //Set new hostname
  WiFi.hostname(newHostname.c_str());
  
  Serial.print("Configuring access point...");
  Serial.print("Setting soft-AP configuration ... ");
  Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");
  
  WiFi.setPhyMode(WIFI_PHY_MODE_11G);
  if (WiFi.softAP(ssid,pass,chan))
  {
    IPAddress myIP = WiFi.softAPIP();
    Serial.print("AP IP address: ");
    Serial.println(myIP);
    Serial.printf("MAC address = %s\n", WiFi.softAPmacAddress().c_str()); 
    Serial.println();
    server_UDP.begin();
    Udp.begin(localPort_UDP);
    
    server_TCP.begin(localPort_TCP); 
    server_TCP.setNoDelay(true); 
    INIT_UDP_Ok = false;
    INIT_TCP_Ok = false;
    
    InitNMEA ();  // to transmit NMEA 183 sentences 

    uint8 mode = 0;
    wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode);
    
    wifi_softap_dhcps_start();

      
  }else Serial.println(" Failed to launch the AP mode");

}

Now I am trying to program the same module with another appli and the code does not want to compile : The error message is NO REFERENCE to wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode);

I find the explanation here in the user_interface.h lib header :

bool wifi_softap_dhcps_start(void);
bool wifi_softap_dhcps_stop(void);

// esp8266/Arduino notice:
// **these dhcp functions are no longer provided by the lwip lib**
// only way to include them is to build our NonOS LwipDhcpServer helpers
// (ref. libraries/ESP8266WiFi/src/ESP8266WiFiAP-DhcpServer.cpp)

bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please);
bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please);
uint32 wifi_softap_get_dhcps_lease_time(void);
bool wifi_softap_set_dhcps_lease_time(uint32 minute);
bool wifi_softap_reset_dhcps_lease_time(void);
bool wifi_softap_add_dhcps_lease(uint8 *macaddr);   // add static lease on the list, this will be the next available @

enum dhcp_status wifi_softap_dhcps_status(void);
bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg);

But both the ESP8266WiFiAP-DhcpServer.cpp src file and the wifi_softap_set_dhcps_offer_option procedure are nowhere to be found on github or anywhere else.

I tried just to remove the call to wifi_softap_set_dhcps_offer_option but now the connection is impossible to restore and the DHCP works randomly ( I use Wireshark to spy the exchanges).

In your opinion how could I solve the problem ? I asked GPT-4 ( MS Copilot) but it did not help much :-)

Oct 8th :

I have eventually found how to solve the problem by rewriting the setup proc in good order after carefully reading the new sources. Now the Wifi transmission is acceptable :

 
  Serial.begin(UART_BaudRate);         //  reception 
  
  wifi_set_phy_mode (PHY_MODE_11G); // G
 // WiFi.mode(WIFI_AP_STA);         //  Access Point mode
  WiFi.mode(WIFI_AP);
  //Set new hostname
  WiFi.hostname(newHostname.c_str());
  WiFi.softAPConfig(AP_IP, gateway,subnet);   // Acces point config
  
  wifi_softap_dhcps_stop();
  auto& server = WiFi.softAPDhcpServer(); 
  server.setRouter (false); // no router
  if (wifi_softap_dhcps_start()) {Serial.println("DHCP started ");};     

  // softAP Configure with AES encryption
  struct softap_config config;
  wifi_softap_get_config(&config); // Get the current configuration
  config.authmode = AUTH_WPA2_PSK; // Force WPA2 AES 
  if (wifi_softap_set_config(&config)) {Serial.println("AP configured");};

   if  (WiFi.softAP(ssid,pass,chan)) { Serial.println("AP started");};   
  
  NMEA_IN_ready = false;         // NMEA init
  NMEA_IN = "";
 
  Udp.begin(Port_NMEA);           
  server_TCP.begin(Port_NMEA);    
  server_TCP.setNoDelay(true);    
  
  dnsServer.start(DNS_PORT, "*", AP_IP); 
}```


jptrol 
3
  • WiFi.softAP now starts a DHCP server Commented Oct 3, 2024 at 7:56
  • Thank you for your answer. In fact I know that Wifi.softAP now starts a DHCP server. To be more precise with my question : I know that my previous app worked fine when defining all router options to zero. Now that the wifi_softap_set_dhcps_offer_option procedure has been removed , my problem becomes how can I now set all router options to zero ? This point is not clearly documented if any. I found no other information than this example : Commented Oct 3, 2024 at 10:08
  • 'AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266WiFi\examples\CustomOffer but without any supporting doc ( github or else) Commented Oct 3, 2024 at 10:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.