Added JSON command handling for thermostat control method

This commit is contained in:
rljonesau 2019-03-15 19:08:05 +11:00
parent d8c050b165
commit ae102021d5
3 changed files with 37 additions and 3 deletions

View file

@ -37,7 +37,7 @@
static const int Line3 = 14;
static const int Line2 = 27;
static const int Line1 = 40;
static const int Column = 75;
static const int Column = 70;
static const int plugPowers[] = { 35, 40, 45, 80, 85, 90};
@ -79,8 +79,8 @@ CExperimentalSettingsScreen::show()
}
else {
_printInverted(_display.xCentre(), 0, " Experimental ", true, eCentreJustify);
_printMenuText(67, Line2, "Thermostat:", false, eRightJustify);
_printMenuText(67, Line1, "Window:", false, eRightJustify);
_printMenuText(65, Line2, "Thermostat:", false, eRightJustify);
_printMenuText(65, Line1, "Window:", false, eRightJustify);
sprintf(msg, "%.1f", _window);
_printMenuText(Column, Line1, msg, _rowSel == 1);
switch(_thermoMode) {

View file

@ -86,6 +86,12 @@ void interpretJsonCommand(char* pLine)
else if(strcmp("FanMax", it->key) == 0) {
setFanMax(it->value.as<short>());
}
else if(strcmp("ThermostatMethod", it->key) == 0) {
NVstore.setThermostatMethodMode(it->value.as<unsigned char>());
}
else if(strcmp("ThermostatWindow", it->key) == 0) {
NVstore.setThermostatMethodWindow(it->value.as<float>());
}
else if(strcmp("Thermostat", it->key) == 0) {
if(!setThermostatMode(it->value.as<unsigned char>())) { // this request is blocked if OEM controller active
JSONmoderator.reset("ThermoStat");
@ -199,6 +205,23 @@ bool makeJSONString(CModerator& moderator, char* opStr, int len)
return bSend;
}
bool makeJSONStringEx(CModerator& moderator, char* opStr, int len)
{
StaticJsonBuffer<800> jsonBuffer; // create a JSON buffer on the stack
JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to
bool bSend = false; // reset should send flag
bSend |= moderator.addJson("ThermostatMethod", NVstore.getThermostatMethodMode(), root);
bSend |= moderator.addJson("ThermostatWindow", NVstore.getThermostatMethodWindow(), root);
if(bSend) {
root.printTo(opStr, len);
}
return bSend;
}
// the way the JSON timer strings are crafted, we have to iterate over each timer's parameters
// individually, the JSON name is always the same for each timer, the payload IDs the specific
// timer
@ -237,6 +260,16 @@ void updateJSONclients(bool report)
sendWebServerString( jsonStr );
}
}
// update extended params
{
if(makeJSONStringEx(JSONmoderator, jsonStr, sizeof(jsonStr))) {
if (report) {
DebugPort.print("JSON send: "); DebugPort.println(jsonStr);
}
getBluetoothClient().send( jsonStr );
sendWebServerString( jsonStr );
}
}
// update timer parameters
bool bNewTimerInfo = false;
for(int tmr=0; tmr<14; tmr++)

View file

@ -28,6 +28,7 @@
extern char defaultJSONstr[64];
bool makeJSONString(CModerator& moderator, char* opStr, int len);
bool makeJSONStringEx(CModerator& moderator, char* opStr, int len);
bool makeJSONTimerString(int channel, char* opStr, int len);
void updateJSONclients(bool report);