Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By andrew melvin
#30568 I'm trying to write a lib that will need to have a function that handles all onnotfound requests made to the web server.

When the class is initialised the user passes in a pointer to the HTTP server they are running.
Code: Select all     
HueBridge(ESP8266WebServer * HTTP, uint8_t lights, uint8_t groups);

 


I am then trying to use it in the following way..
Code: Select all       _HTTP->onNotFound(HandleHue);


where HandleWebRequest is a function inside my lib.

I've tried all sorts but, ultimately failed. can someone point me in the right direction!

This is the error:

Code: Select all
HueBridge.cpp: In constructor 'HueBridge::HueBridge(ESP8266WebServer*, uint8_t, uint8_t)':
HueBridge.cpp:13: error: no matching function for call to 'ESP8266WebServer::onNotFound(<unresolved overloaded function type>)'
    _HTTP->onNotFound(HandleHue);
                               ^
HueBridge.cpp:13:31: note: candidate is:
In file included from HueBridge.h:19:0,
                 from HueBridge.cpp:2:
/Users/amelvin/git/Arduino/build/Arduino-latest.app/Contents/Java/portable/packages/esp8266/hardware/esp8266/1.6.5-1160-gef26c5f/libraries/ESP8266WebServer/src/ESP8266WebServer.h:69:8: note: void ESP8266WebServer::onNotFound(ESP8266WebServer::THandlerFunction)
   void onNotFound(THandlerFunction fn);  //called when handler is not assigned
        ^
/Users/amelvin/git/Arduino/build/Arduino-latest.app/Contents/Java/portable/packages/esp8266/hardware/esp8266/1.6.5-1160-gef26c5f/libraries/ESP8266WebServer/src/ESP8266WebServer.h:69:8: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'ESP8266WebServer::THandlerFunction {aka std::function<void()>}'
no matching function for call to 'ESP8266WebServer::onNotFound(<unresolved overloaded function type>)'

User avatar
By andrew melvin
#30672 IGRR... you are officially a legend!!!

This solved this issue, plus another one i was having with callbacks to my own libs...

I had tried various methods of casting to (this)... as i knew what i wanted, just no idea how to do it...

Many many thanks