Post topics, source code that relate to the Arduino Platform

User avatar
By ScotleCyphez
#25126 Thank you again Kolban, as your post and book http://neilkolban.com/tech/wp-content/uploads/2015/08/The-ESP8266-Book-August-2015.pdf were very helpful. I got an example up and running using the Arduino IDE, my ESP8266, and an FTDI (Examples > Esp8266WiFi > WiFiAccessPoint)

After a bit of a trip, I'm back to my main goal - to disable the DHCP offer option using the ESP8266 SDK command
Code: Select allwifi_softap_set_dhcps_offer_option

After modifying the example mentioned above, I now have the following Sketch

Code: Select all/*
/* Create a WiFi access point and provide a web server on it. */
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "user_interface.h"

/* Set these to your desired credentials. */
const char *ssid = "ESPap";
const char *password = "thereisnospoon";

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {
   server.send(200, "text/html", "<h1>You are connected</h1>");
}

void setup() {
   delay(1000);
   Serial.begin(115200);
   Serial.println();
   Serial.print("Configuring access point...");
   /* You can remove the password parameter if you want the AP to be open. */
   WiFi.softAP(ssid, password);

   IPAddress myIP = WiFi.softAPIP();

  wifi_softap_set_dhcps_offer_option(OFFER_ROUTER,0);

   Serial.print("AP IP address: ");
   Serial.println(myIP);
   server.on("/", handleRoot);
   server.begin();
 
   Serial.println("HTTP server started");
 
}

void loop() {
   server.handleClient();
}

But when I try to upload it, I am met with the error:
Code: Select allWiFiAccessPoint.cpp.o: In function `handleRoot()':
/Users/cypher/WiFiAccessPoint.ino:48: undefined reference to `wifi_softap_set_dhcps_offer_option(unsigned char, void*)'
WiFiAccessPoint.cpp.o: In function `setup':
/Users/cypher/WiFiAccessPoint.ino:50: undefined reference to `wifi_softap_set_dhcps_offer_option(unsigned char, void*)'
collect2: error: ld returned 1 exit status
Error compiling.

Does this mean this command is not available through the Arduino IDE, or am I going about this the wrong way? After some reasearch I would have thought that adding the "user_interface.h" include statement would have made the function usable. I have dug through ESP8266WebServer.h, WiFiClient.h, and ESP8266WiFi.h but can't seem to find an easy to use function that is the same as the SDK command I want to use.

Any tips would be greatly appreciated!
Last edited by ScotleCyphez on Wed Aug 05, 2015 8:02 pm, edited 1 time in total.
User avatar
By martinayotte
#25129 First, a quick question, just to understand : why do you wish to turn off the DHCP ?
I don't see benefit except to reduce memory footprint ...

I've tried your code, and the fix is quite simple, the wifi_softap_set_dhcps_offer_option() is a plain C function, so the #include need to be done the following way :

Code: Select allextern "C" {
  #include "user_interface.h"
}


(BTW, I didn't verify that it is actually run properly at runtime, only get it compiled and linked)
User avatar
By kolban
#25131 I got to thinking why the solution by Martin would work ... I looked inside "user_interface.h" and found the forward definition of the function:

bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg);

Seems like an ordinary C function ... however, what I believe is happening is that the bracketing with the 'extern "C"' is defining the function to have a C language signature as opposed to a C++ language signature (default) ... I guess.

Neil