Let WebServer handle other EspLink calls

pull/183/head
cskarai 8 years ago
parent c56a7e5364
commit 62f8f70b96
  1. 11
      arduino/libraries/EspLink/WebServer.cpp
  2. 6
      arduino/libraries/EspLink/WebServer.h

@ -3,14 +3,14 @@
#define RESUBSCRIBE_LIMIT 1000 #define RESUBSCRIBE_LIMIT 1000
WebServer * WebServer::instance = NULL; WebServer * WebServer::instance = NULL;
void webServerCallback(CmdRequest *req) void webServerCallback(CmdRequest *req)
{ {
WebServer::getInstance()->handleRequest(req); WebServer::getInstance()->handleRequest(req);
} }
WebServer::WebServer(Stream &streamIn, const WebMethod * PROGMEM methodsIn):espLink(streamIn, webServerCallback),methods(methodsIn),stream(streamIn) WebServer::WebServer(Stream &streamIn, const WebMethod * PROGMEM methodsIn):espLink(streamIn, webServerCallback),methods(methodsIn),stream(streamIn),esplink_cb(NULL)
{ {
instance = this; instance = this;
} }
@ -89,6 +89,13 @@ void WebServer::invokeMethod(RequestReason reason, WebMethod * method, CmdReques
void WebServer::handleRequest(CmdRequest *req) void WebServer::handleRequest(CmdRequest *req)
{ {
if( req->cmd->cmd != CMD_WEB_REQ_CB )
{
if( esplink_cb != NULL )
esplink_cb(req);
return;
}
uint16_t shrt; uint16_t shrt;
espLink.cmdPopArg(req, &shrt, 2); espLink.cmdPopArg(req, &shrt, 2);
RequestReason reason = (RequestReason)shrt; RequestReason reason = (RequestReason)shrt;

@ -56,6 +56,8 @@ class WebServer
uint32_t last_connect_ts; uint32_t last_connect_ts;
CmdRequestCB esplink_cb;
protected: protected:
EspLink espLink; EspLink espLink;
@ -66,6 +68,8 @@ class WebServer
void loop(); void loop();
void registerCallback(); void registerCallback();
void setEspLinkCallback(CmdRequestCB cb) { esplink_cb = cb; }
static WebServer * getInstance() { return instance; } static WebServer * getInstance() { return instance; }
uint8_t * getRemoteIp() { return remote_ip; } uint8_t * getRemoteIp() { return remote_ip; }
@ -80,6 +84,8 @@ class WebServer
int32_t getArgInt(); int32_t getArgInt();
char * getArgString(); char * getArgString();
uint8_t getArgBoolean(); uint8_t getArgBoolean();
EspLink * getEspLink() { return &espLink; }
}; };
#endif /* WEB_SERVER_H */ #endif /* WEB_SERVER_H */

Loading…
Cancel
Save