Class myIOT2 contains a function that need to be called from class IPmonitoring:
bool myIOT2::checkInternet(char *externalSite, byte pings)
{
return Ping.ping(externalSite, pings);
}
This function is needed as a pinger in IPmonitor:
void IPmonitoring::start(cb_func ping)
{
_ping_cb = ping;
}
and this cb_func is defined by (inside IPmonitor.h):
typedef bool (*cb_func)(char *externalSite, byte pings);
cb_func _ping_cb;
inside my sketch (relevant parts only) I fail when iot.checkInternet is passed, while using a function test that calls iot.checkInternet succeeds:
myIOT2 iot;
IPmonitoring WiFi_service(ROUTER_IP, "Router");
bool test(char *a, byte b)
{
bool x = iot.checkInternet(ROUTER_IP);
return x;
}
void setup()
{
WiFi_service.start(iot.checkInternet); // <---- Trial a)fails
WiFi_service.start(test); // <-----Trail b)succeeds
}
error is :
home/guy/Documents/git/Arduino/IPmonitor/IPmonitor.ino: In function 'void setup()':
IPmonitor:436:45: error: no matching function for call to 'IPmonitoring::start(<unresolved overloaded function type>)'
WiFi_service.start(iot.checkInternet);//
^
/home/guy/Documents/git/Arduino/IPmonitor/IPmonitor.ino:436:45: note: candidate is:
In file included from /home/guy/Documents/git/Arduino/IPmonitor/IPmonitor.ino:2:0:
/home/guy/Documents/git/Arduino/libraries/myIPmonitor/myIPmonitor.h:42:10: note: void IPmonitoring::start(IPmonitoring::cb_func)
void start(cb_func ping);
^
/home/guy/Documents/git/Arduino/libraries/myIPmonitor/myIPmonitor.h:42:10: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'IPmonitoring::cb_func {aka bool (*)(char*, unsigned char)}'
Multiple libraries were found
What is done wrong ? and why test succeeds ?
testsucceedscb_func