Reconnect periodically

pull/193/head
Karai Csaba 9 years ago committed by Thorsten von Eicken
parent 3df5993c0a
commit 2d679decfe
  1. 9
      examples/arduino/EspLinkSample/WebServer.cpp
  2. 2
      examples/arduino/EspLinkSample/WebServer.h

@ -1,4 +1,7 @@
#include "WebServer.h" #include "WebServer.h"
#include "Arduino.h"
#define RESUBSCRIBE_LIMIT 1000
WebServer * WebServer::instance = NULL; WebServer * WebServer::instance = NULL;
@ -19,7 +22,10 @@ void WebServer::init()
void WebServer::loop() void WebServer::loop()
{ {
// TODO: resubscribe periodically // resubscribe periodically
uint32_t elapsed = millis() - last_connect_ts;
if( elapsed > RESUBSCRIBE_LIMIT )
registerCallback();
espLink.readLoop(); espLink.readLoop();
} }
@ -28,6 +34,7 @@ void WebServer::registerCallback()
espLink.sendPacketStart(CMD_CB_ADD, 100, 1); espLink.sendPacketStart(CMD_CB_ADD, 100, 1);
espLink.sendPacketArg(5, (uint8_t *)"webCb"); espLink.sendPacketArg(5, (uint8_t *)"webCb");
espLink.sendPacketEnd(); espLink.sendPacketEnd();
last_connect_ts = millis();
} }
void WebServer::invokeMethod(RequestReason reason, WebMethod * method, CmdRequest *req) void WebServer::invokeMethod(RequestReason reason, WebMethod * method, CmdRequest *req)

@ -55,6 +55,8 @@ class WebServer
int16_t args_to_send; int16_t args_to_send;
char * value_ptr; char * value_ptr;
uint32_t last_connect_ts;
protected: protected:
EspLink espLink; EspLink espLink;

Loading…
Cancel
Save