Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By quiet_coder
#62565 I'm trying to add the ability to request and decode more DHCP options from a DHCP server (for example, an NTP server) but I'm having a hard time following all the loops of code for version 2.3.0. So far I have added the option numbers to the lwip library dhcp.h and extended the functions in dhcp.c to transmit the extra option numbers in the request. I also extended the parser to look for the additional options however this is where things start to break down.

I was planning to extend the Arduino IDE library to add functions that fetch these additional option values (for example, adding ntpserverIP() to the library) and I was trying to follow the existing localIP() but I seem to lose where the Arduino library is able to reach back into lwip to get the values. I see the function is present in both ESP8266WiFiSTA.cpp and WiFiClient.cpp but with two different methods of acquiring an IP, one pulls from a struct using wifi_get_ip_info() and the other returns the value from a function _client->getLocalAddress()

I tried creating new null functions in WiFiClient.cpp but I get an error that the ESP8266WiFiClass has no member named ntpserverIP() which says to me that the IDE is not utilizing WiFiClient therefore it must be using ESP8266WiFiSTA instead but now I'm lost about how to bring the additional data from lwip over to ESP8266WiFiSTA or if I'm even looking in the right place.
User avatar
By mrburnette
#62624 Maybe the ESP8266 Class index will assist:
https://links2004.github.io/Arduino/index.html

However, were we dealing with anything except Arduino, I would recommend subclassing and adding the new functionality. Having some experience with the STM32duino core, I understand that many, many modules are often affected by a single change.

The concern I have is that most of the underlying low-level code that touch the silicon is binary and provided by Esperif; therefore there is no source: just the API.

Good luck.

Ray
User avatar
By quiet_coder
#62626 I saw that list before but it didn't really help much since it didn't expose the underlying C code, just the higher level function calls. The lower level code is present and the DHCP module is visible, being able to modify dhcp.h and dhcp.c to request and accept additional parameters.

I may just brute force it with a global variable somewhere and stick the results in that. It's not an elegant solution but it would function.
User avatar
By quiet_coder
#62792 So I gave it a shot but the linking fails when it reaches the Arduino cpp files.

Here's what I've done so far:
In dhcp.c/dhcp.h I added a static global variable to hold one of the extra values (similar to the way the dns.c/dns.h file works with DNS servers):

static ip_addr_t ntp_server;

I also added a new function in dhcp.c to return that value:
ip_addr_t ICACHE_FLASH_ATTR dhcp_get_ntpserver()
{
return ntp_server;
}

I extended the parsing code to pick up the new option as well.

Then in the Arduino ESP8266WiFiSTA.cpp file I added an extra include to "lwip/dhcp.h" in the extern "C" block and I added a new function similar to the dnsIP() function to return the desired value from the static variable:

IPAddress ESP8266WiFiSTAClass::NTPServer()
{
ip_addr_t ntp_ip = dhcp_get_ntpserver();
return IPAddress(ntp_ip.addr);
}

This is as far as I can go because I'm running into problems while compiling. If I leave the NTPServer() function in place I get errors referencing other functions within ESP8266WiFiSTA.cpp such as:

"In function 'ESP8266WiFiSTAClass::macAddress(unsigned char*)':
undefined reference to dhcp_get_ntpserver

If I remove the NTPServer function from ESP8266WiFiSTA.cpp and recompile, it compiles (although I can't call NTPServer from my ino file of course). I'm trying to understand what may have gone wrong with that function to cause an issue with a completely unrelated function. As a note, if I move the function elsewhere within ESP8266WiFiSTA.cpp, the error points to a new function. For example, I had moved it to just after localIP() and it errored by saying dhcp_get_ntpserver was undefined in localIP().

At the same time I get an additional error that dhcp_get_ntpserver is undefined within NTPServer() as well.

I'm a bit lost now. It appears that this should work and accomplish what I'm looking for if I can understand why it does not take the new Arduino class functions and why it is claiming the function is undefined.