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.load();
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.setCallback(parentKeyHandler);

View File

@ -149,6 +149,13 @@ void interpretJsonCommand(char* pLine)
}
else if(strcmp("TimerRefresh", it->key) == 0) {
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) {
setFanSensor(it->value.as<unsigned char>());
@ -388,7 +395,8 @@ void updateJSONclients(bool report)
void resetJSONmoderator()
{
JSONmoderator.reset();
TimerModerator.reset();
initTimerJSONmoderator();
initMQTTJSONmoderator();
}
void initMQTTJSONmoderator()
@ -397,4 +405,10 @@ void initMQTTJSONmoderator()
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);
bool makeJSONStringMQTT(CModerator& moderator, char* opStr, int len);
void initMQTTJSONmoderator();
void initTimerJSONmoderator();
template<class T>
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 "../Utility/DebugPort.h"
@ -150,7 +150,7 @@ const char* updateIndex = R"=====(
}
function init() {
ws = new WebSocket('ws://' + window.location.hostname + ':81/');
ws.onmessage = function(event){
var response = JSON.parse(event.data);
var key;
@ -175,7 +175,7 @@ const char* updateIndex = R"=====(
var JSONmsg = {};
JSONmsg['UploadSize'] = sendSize;
var str = JSON.stringify(obj);
var str = JSON.stringify(JSONmsg);
console.log("JSON Tx:", str);
ws.send(str);

Binary file not shown.

Binary file not shown.