Implemented TQuery to greatly reduce JSON traffic upon new client connections.

This commit is contained in:
Ray Jones 2019-05-30 20:31:34 +10:00
parent 7817b7f2e0
commit 18927d758a
6 changed files with 21 additions and 4 deletions

View file

@ -374,6 +374,8 @@ void setup() {
NVstore.init(); NVstore.init();
NVstore.load(); NVstore.load();
initMQTTJSONmoderator(); // prevent JSON for MQTT unless requested initMQTTJSONmoderator(); // prevent JSON for MQTT unless requested
initTimerJSONmoderator(); // prevent JSON for timers unless requested
KeyPad.begin(keyLeft_pin, keyRight_pin, keyCentre_pin, keyUp_pin, keyDown_pin); KeyPad.begin(keyLeft_pin, keyRight_pin, keyCentre_pin, keyUp_pin, keyDown_pin);
KeyPad.setCallback(parentKeyHandler); KeyPad.setCallback(parentKeyHandler);

View file

@ -149,6 +149,13 @@ void interpretJsonCommand(char* pLine)
} }
else if(strcmp("TimerRefresh", it->key) == 0) { else if(strcmp("TimerRefresh", it->key) == 0) {
TimerModerator.reset(); TimerModerator.reset();
}
else if(strcmp("TQuery", it->key) == 0) {
int timerID = it->value.as<int>();
if(timerID)
TimerModerator.reset(timerID-1);
else
TimerModerator.reset();
} }
else if(strcmp("FanSensor", it->key) == 0) { else if(strcmp("FanSensor", it->key) == 0) {
setFanSensor(it->value.as<unsigned char>()); setFanSensor(it->value.as<unsigned char>());
@ -388,7 +395,8 @@ void updateJSONclients(bool report)
void resetJSONmoderator() void resetJSONmoderator()
{ {
JSONmoderator.reset(); JSONmoderator.reset();
TimerModerator.reset(); initTimerJSONmoderator();
initMQTTJSONmoderator();
} }
void initMQTTJSONmoderator() void initMQTTJSONmoderator()
@ -397,4 +405,10 @@ void initMQTTJSONmoderator()
makeJSONStringMQTT(MQTTmoderator, jsonStr, sizeof(jsonStr)); makeJSONStringMQTT(MQTTmoderator, jsonStr, sizeof(jsonStr));
} }
void initTimerJSONmoderator()
{
char jsonStr[800];
for(int tmr=0; tmr<14; tmr++)
makeJSONTimerString(tmr, jsonStr, sizeof(jsonStr));
}

View file

@ -33,6 +33,7 @@ bool makeJSONTimerString(int channel, char* opStr, int len);
void updateJSONclients(bool report); void updateJSONclients(bool report);
bool makeJSONStringMQTT(CModerator& moderator, char* opStr, int len); bool makeJSONStringMQTT(CModerator& moderator, char* opStr, int len);
void initMQTTJSONmoderator(); void initMQTTJSONmoderator();
void initTimerJSONmoderator();
template<class T> template<class T>
const char* createJSON(const char* name, T value) const char* createJSON(const char* name, T value)

View file

@ -20,7 +20,7 @@
* *
*/ */
//#define USE_EMBEDDED_WEBUPDATECODE #define USE_EMBEDDED_WEBUPDATECODE
#include "BTCWebServer.h" #include "BTCWebServer.h"
#include "../Utility/DebugPort.h" #include "../Utility/DebugPort.h"
@ -150,7 +150,7 @@ const char* updateIndex = R"=====(
} }
function init() { function init() {
ws = new WebSocket('ws://' + window.location.hostname + ':81/'); ws = new WebSocket('ws://' + window.location.hostname + ':81/');
ws.onmessage = function(event){ ws.onmessage = function(event){
var response = JSON.parse(event.data); var response = JSON.parse(event.data);
var key; var key;
@ -175,7 +175,7 @@ const char* updateIndex = R"=====(
var JSONmsg = {}; var JSONmsg = {};
JSONmsg['UploadSize'] = sendSize; JSONmsg['UploadSize'] = sendSize;
var str = JSON.stringify(obj); var str = JSON.stringify(JSONmsg);
console.log("JSON Tx:", str); console.log("JSON Tx:", str);
ws.send(str); ws.send(str);

Binary file not shown.

Binary file not shown.