- Mon Feb 20, 2017 2:12 am
#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.