I am trying to develop a NTP client library for ESP8266/Arduino to make adding NTP sync an easier task.
Basically, I've thought about a constructor as NTPClient(String host, int interval);
and a NTPClient.begin()
function to register sync function.
My problem is with that registering.
I have a public function: time_t ntpClient::getNtpTime()
that connects to NTP server, decodes the response and returns a time_t
variable.
Then, inside boolean ntpClient::begin()
function I try to run setSyncProvider(ntpClient::getNtpTime)
. I've also tried to use setSyncProvider(this->getNtpTime)
.
I get a compile error here:
ntpClient.cpp:In member function 'boolean ntpClient::begin()
ntpClient.cpp:79:39: error: cannot convert 'ntpClient::getNtpTime' from type 'time_t (ntpClient::)() {aka long int (ntpClient::)()}' to type 'getExternalTime {aka long int (*)()}
setSyncProvider(ntpClient*:getNtpTime)
Error compiling project sources
What could I do to allow registering this function as sync provider to hide NTP internals to my sketches?