2018-12-13 12:19:10 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BTC_JSON.h"
|
|
|
|
#include "DebugPort.h"
|
2019-07-02 10:22:14 +00:00
|
|
|
#include "NVStorage.h"
|
2019-07-15 09:56:36 +00:00
|
|
|
#include "../RTC/Clock.h"
|
2019-07-24 09:25:07 +00:00
|
|
|
#include "../RTC/RTCStore.h"
|
2018-12-16 07:34:39 +00:00
|
|
|
#include "../RTC/BTCDateTime.h"
|
2018-12-19 08:39:07 +00:00
|
|
|
#include "../RTC/Timers.h"
|
2019-03-05 09:40:00 +00:00
|
|
|
#include "../RTC/TimerManager.h"
|
2018-12-20 04:19:59 +00:00
|
|
|
#include "../Bluetooth/BluetoothAbstract.h"
|
|
|
|
#include "../WiFi/BTCWebServer.h"
|
2019-07-11 12:03:27 +00:00
|
|
|
#include "../WiFi/BTCWifi.h"
|
2018-12-20 04:19:59 +00:00
|
|
|
#include "../cfg/BTCConfig.h"
|
2019-06-15 23:09:29 +00:00
|
|
|
#include "macros.h"
|
|
|
|
#include "../Protocol/Protocol.h"
|
2019-07-22 20:15:18 +00:00
|
|
|
#include <string.h>
|
2019-07-24 20:06:47 +00:00
|
|
|
#include "HourMeter.h"
|
2018-12-13 12:19:10 +00:00
|
|
|
|
|
|
|
char defaultJSONstr[64];
|
2018-12-20 04:19:59 +00:00
|
|
|
CModerator JSONmoderator;
|
2019-03-03 08:48:52 +00:00
|
|
|
CTimerModerator TimerModerator;
|
2019-03-05 09:40:00 +00:00
|
|
|
int timerConflict = 0;
|
2019-05-12 10:15:18 +00:00
|
|
|
CModerator MQTTmoderator;
|
2019-07-11 12:03:27 +00:00
|
|
|
CModerator IPmoderator;
|
2019-06-04 20:15:12 +00:00
|
|
|
CModerator GPIOmoderator;
|
2019-07-15 09:56:36 +00:00
|
|
|
CModerator SysModerator;
|
2019-07-15 20:29:23 +00:00
|
|
|
bool bTriggerSysParams = false;
|
2019-07-17 09:35:34 +00:00
|
|
|
bool bTriggerDateTime = false;
|
2018-12-13 12:19:10 +00:00
|
|
|
|
2019-03-05 09:40:00 +00:00
|
|
|
void validateTimer(int ID);
|
2019-06-06 01:32:43 +00:00
|
|
|
void Expand(std::string& str);
|
2019-07-15 09:56:36 +00:00
|
|
|
bool makeJSONString(CModerator& moderator, char* opStr, int len);
|
|
|
|
bool makeJSONStringEx(CModerator& moderator, char* opStr, int len);
|
|
|
|
bool makeJSONTimerString(int channel, char* opStr, int len);
|
|
|
|
bool makeJSONStringGPIO( CModerator& moderator, char* opStr, int len);
|
|
|
|
bool makeJSONStringSysInfo(CModerator& moderator, char* opStr, int len);
|
|
|
|
bool makeJSONStringMQTT(CModerator& moderator, char* opStr, int len);
|
|
|
|
bool makeJSONStringIP(CModerator& moderator, char* opStr, int len);
|
2018-12-15 09:34:58 +00:00
|
|
|
|
2018-12-13 12:19:10 +00:00
|
|
|
void interpretJsonCommand(char* pLine)
|
|
|
|
{
|
|
|
|
if(strlen(pLine) == 0)
|
|
|
|
return;
|
|
|
|
|
2019-05-12 10:15:18 +00:00
|
|
|
DebugPort.printf("JSON parse %s...", pLine);
|
2018-12-13 12:19:10 +00:00
|
|
|
|
|
|
|
StaticJsonBuffer<512> jsonBuffer; // create a JSON buffer on the heap
|
|
|
|
JsonObject& obj = jsonBuffer.parseObject(pLine);
|
|
|
|
if(!obj.success()) {
|
|
|
|
DebugPort.println(" FAILED");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DebugPort.println(" OK");
|
|
|
|
|
|
|
|
JsonObject::iterator it;
|
|
|
|
for(it = obj.begin(); it != obj.end(); ++it) {
|
|
|
|
|
2018-12-15 14:09:10 +00:00
|
|
|
if(strcmp("TempDesired", it->key) == 0) {
|
2019-07-19 20:53:12 +00:00
|
|
|
if( !reqDemand(it->value.as<uint8_t>(), false) ) { // this request is blocked if OEM controller active
|
2018-12-20 04:19:59 +00:00
|
|
|
JSONmoderator.reset("TempDesired");
|
|
|
|
}
|
2018-12-13 12:19:10 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("RunState", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
if(it->value.as<uint8_t>()) {
|
2018-12-13 12:19:10 +00:00
|
|
|
requestOn();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
requestOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(strcmp("PumpMin", it->key) == 0) {
|
|
|
|
setPumpMin(it->value.as<float>());
|
|
|
|
}
|
|
|
|
else if(strcmp("PumpMax", it->key) == 0) {
|
|
|
|
setPumpMax(it->value.as<float>());
|
|
|
|
}
|
|
|
|
else if(strcmp("FanMin", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
setFanMin(it->value.as<uint16_t>());
|
2018-12-13 12:19:10 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("FanMax", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
setFanMax(it->value.as<uint16_t>());
|
2018-12-13 12:19:10 +00:00
|
|
|
}
|
2019-07-03 13:01:36 +00:00
|
|
|
else if(strcmp("CyclicTemp", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
setDemandDegC(it->value.as<uint8_t>()); // directly set demandDegC
|
2019-07-03 13:01:36 +00:00
|
|
|
}
|
|
|
|
else if((strcmp("CyclicOff", it->key) == 0) || (strcmp("ThermostatOvertemp", it->key) == 0)) {
|
|
|
|
sUserSettings us = NVstore.getUserSettings();
|
2019-07-06 13:46:20 +00:00
|
|
|
int8_t val = it->value.as<int8_t>();
|
|
|
|
if(INBOUNDS(val, 0, 10)) {
|
|
|
|
if(val > 1) val--; // internal uses a 1 offset
|
2019-07-03 13:01:36 +00:00
|
|
|
us.cyclic.Stop = val;
|
2019-07-06 13:46:20 +00:00
|
|
|
}
|
2019-07-03 13:01:36 +00:00
|
|
|
NVstore.setUserSettings(us);
|
2019-04-27 10:41:47 +00:00
|
|
|
}
|
2019-07-03 13:01:36 +00:00
|
|
|
else if((strcmp("CyclicOn", it->key) == 0) || (strcmp("ThermostatUndertemp", it->key) == 0)) {
|
|
|
|
sUserSettings us = NVstore.getUserSettings();
|
2019-07-06 13:46:20 +00:00
|
|
|
int8_t val = it->value.as<int8_t>();
|
|
|
|
if(INBOUNDS(val, -20, 0)) {
|
|
|
|
us.cyclic.Start = val;
|
|
|
|
}
|
2019-07-03 13:01:36 +00:00
|
|
|
NVstore.setUserSettings(us);
|
2019-04-04 19:39:58 +00:00
|
|
|
}
|
2019-03-15 08:08:05 +00:00
|
|
|
else if(strcmp("ThermostatMethod", it->key) == 0) {
|
2019-06-06 01:32:43 +00:00
|
|
|
sUserSettings settings = NVstore.getUserSettings();
|
|
|
|
uint8_t val = it->value.as<uint8_t>();
|
2019-08-07 08:59:30 +00:00
|
|
|
if(INBOUNDS(val, 0, 3))
|
2019-06-06 01:32:43 +00:00
|
|
|
settings.ThermostatMethod = val;
|
|
|
|
NVstore.setUserSettings(settings);
|
2019-03-15 08:08:05 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("ThermostatWindow", it->key) == 0) {
|
2019-06-06 01:32:43 +00:00
|
|
|
sUserSettings settings = NVstore.getUserSettings();
|
|
|
|
float val = it->value.as<float>();
|
2019-06-15 23:09:29 +00:00
|
|
|
if(INBOUNDS(val, 0.2f, 10.f))
|
2019-06-06 01:32:43 +00:00
|
|
|
settings.ThermostatWindow = val;
|
|
|
|
NVstore.setUserSettings(settings);
|
2019-03-15 08:08:05 +00:00
|
|
|
}
|
2018-12-13 12:19:10 +00:00
|
|
|
else if(strcmp("Thermostat", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
if(!setThermostatMode(it->value.as<uint8_t>())) { // this request is blocked if OEM controller active
|
2018-12-20 04:19:59 +00:00
|
|
|
JSONmoderator.reset("ThermoStat");
|
|
|
|
}
|
2018-12-13 12:19:10 +00:00
|
|
|
}
|
2018-12-15 09:34:58 +00:00
|
|
|
else if(strcmp("NVsave", it->key) == 0) {
|
|
|
|
if(it->value.as<int>() == 8861)
|
|
|
|
saveNV();
|
|
|
|
}
|
|
|
|
else if(strcmp("DateTime", it->key) == 0) {
|
|
|
|
setDateTime(it->value.as<const char*>());
|
2019-07-17 09:35:34 +00:00
|
|
|
bTriggerDateTime = true;
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("Date", it->key) == 0) {
|
|
|
|
setDate(it->value.as<const char*>());
|
2019-07-17 09:35:34 +00:00
|
|
|
bTriggerDateTime = true;
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("Time", it->key) == 0) {
|
|
|
|
setTime(it->value.as<const char*>());
|
2019-07-17 09:35:34 +00:00
|
|
|
bTriggerDateTime = true;
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("PumpPrime", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
reqPumpPrime(it->value.as<uint8_t>());
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("Refresh", it->key) == 0) {
|
2018-12-19 12:07:51 +00:00
|
|
|
resetJSONmoderator();
|
2019-01-11 05:40:25 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("SystemVoltage", it->key) == 0) {
|
|
|
|
setSystemVoltage(it->value.as<float>());
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
2019-03-03 08:48:52 +00:00
|
|
|
else if(strcmp("TimerDays", it->key) == 0) {
|
|
|
|
// value encoded as "ID Days,Days"
|
2019-03-14 10:52:59 +00:00
|
|
|
decodeJSONTimerDays(it->value.as<const char*>());
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
2019-03-03 08:48:52 +00:00
|
|
|
else if(strcmp("TimerStart", it->key) == 0) {
|
|
|
|
// value encoded as "ID HH:MM"
|
2019-03-14 10:52:59 +00:00
|
|
|
decodeJSONTimerTime(0, it->value.as<const char*>());
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
2019-03-03 08:48:52 +00:00
|
|
|
else if(strcmp("TimerStop", it->key) == 0) {
|
|
|
|
// value encoded as "ID HH:MM"
|
2019-03-14 10:52:59 +00:00
|
|
|
decodeJSONTimerTime(1, it->value.as<const char*>());
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
2019-03-03 08:48:52 +00:00
|
|
|
else if(strcmp("TimerRepeat", it->key) == 0) {
|
|
|
|
// value encoded as "ID val"
|
2019-03-14 10:52:59 +00:00
|
|
|
decodeJSONTimerNumeric(0, it->value.as<const char*>());
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
2019-03-03 08:48:52 +00:00
|
|
|
else if(strcmp("TimerTemp", it->key) == 0) {
|
2019-03-14 10:52:59 +00:00
|
|
|
decodeJSONTimerNumeric(1, it->value.as<const char*>());
|
2019-03-05 09:40:00 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("TimerConflict", it->key) == 0) {
|
|
|
|
validateTimer(it->value.as<int>());
|
|
|
|
}
|
2019-06-01 00:18:31 +00:00
|
|
|
// request specific timer refresh
|
|
|
|
else if((strcmp("TQuery", it->key) == 0) || (strcmp("TimerRefresh", it->key) == 0) ) {
|
2019-05-30 10:31:34 +00:00
|
|
|
int timerID = it->value.as<int>();
|
|
|
|
if(timerID)
|
|
|
|
TimerModerator.reset(timerID-1);
|
|
|
|
else
|
|
|
|
TimerModerator.reset();
|
2018-12-15 09:34:58 +00:00
|
|
|
}
|
2019-01-11 05:40:25 +00:00
|
|
|
else if(strcmp("FanSensor", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
setFanSensor(it->value.as<uint8_t>());
|
2019-01-11 05:40:25 +00:00
|
|
|
}
|
2019-07-11 12:03:27 +00:00
|
|
|
else if(strcmp("IQuery", it->key) == 0) {
|
|
|
|
IPmoderator.reset(); // force IP params to be sent
|
|
|
|
}
|
2019-07-15 09:56:36 +00:00
|
|
|
// system info
|
|
|
|
else if(strcmp("SQuery", it->key) == 0) {
|
|
|
|
SysModerator.reset(); // force MQTT params to be sent
|
2019-07-15 20:29:23 +00:00
|
|
|
bTriggerSysParams = true;
|
2019-07-15 09:56:36 +00:00
|
|
|
}
|
2019-05-12 10:15:18 +00:00
|
|
|
// MQTT parameters
|
|
|
|
else if(strcmp("MQuery", it->key) == 0) {
|
|
|
|
MQTTmoderator.reset(); // force MQTT params to be sent
|
|
|
|
}
|
|
|
|
else if(strcmp("MEn", it->key) == 0) {
|
|
|
|
sMQTTparams info = NVstore.getMQTTinfo();
|
2019-07-06 13:46:20 +00:00
|
|
|
info.enabled = it->value.as<uint8_t>();
|
2019-05-12 10:15:18 +00:00
|
|
|
NVstore.setMQTTinfo(info);
|
|
|
|
}
|
|
|
|
else if(strcmp("MPort", it->key) == 0) {
|
|
|
|
sMQTTparams info = NVstore.getMQTTinfo();
|
2019-07-06 13:46:20 +00:00
|
|
|
info.port = it->value.as<uint16_t>();
|
2019-05-12 10:15:18 +00:00
|
|
|
NVstore.setMQTTinfo(info);
|
|
|
|
}
|
|
|
|
else if(strcmp("MHost", it->key) == 0) {
|
|
|
|
sMQTTparams info = NVstore.getMQTTinfo();
|
|
|
|
strncpy(info.host, it->value.as<const char*>(), 127);
|
|
|
|
info.host[127] = 0;
|
|
|
|
NVstore.setMQTTinfo(info);
|
|
|
|
}
|
|
|
|
else if(strcmp("MUser", it->key) == 0) {
|
|
|
|
sMQTTparams info = NVstore.getMQTTinfo();
|
|
|
|
strncpy(info.username, it->value.as<const char*>(), 31);
|
|
|
|
info.username[31] = 0;
|
|
|
|
NVstore.setMQTTinfo(info);
|
|
|
|
}
|
|
|
|
else if(strcmp("MPasswd", it->key) == 0) {
|
|
|
|
sMQTTparams info = NVstore.getMQTTinfo();
|
|
|
|
strncpy(info.password, it->value.as<const char*>(), 31);
|
|
|
|
info.password[31] = 0;
|
|
|
|
NVstore.setMQTTinfo(info);
|
|
|
|
}
|
2019-05-22 20:35:09 +00:00
|
|
|
else if(strcmp("UploadSize", it->key) == 0) {
|
|
|
|
setUploadSize(it->value.as<long>());
|
|
|
|
}
|
2019-06-04 20:15:12 +00:00
|
|
|
else if(strcmp("GPout1", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
setGPIOout(0, it->value.as<uint8_t>() ? true : false);
|
2019-06-04 20:15:12 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("GPout2", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
setGPIOout(1, it->value.as<uint8_t>() ? true : false);
|
2019-06-04 20:15:12 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("GPin1", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
simulateGPIOin(it->value.as<uint8_t>() ? 0x01 : 0x00); // simulate key 1 press
|
2019-06-04 20:15:12 +00:00
|
|
|
}
|
|
|
|
else if(strcmp("GPin2", it->key) == 0) {
|
2019-07-06 13:46:20 +00:00
|
|
|
simulateGPIOin(it->value.as<uint8_t>() ? 0x02 : 0x00); // simulate key 2 press
|
2019-06-04 20:15:12 +00:00
|
|
|
}
|
2019-06-29 08:08:37 +00:00
|
|
|
else if(strcmp("JSONpack", it->key) == 0) {
|
2019-06-15 23:09:29 +00:00
|
|
|
sUserSettings us = NVstore.getUserSettings();
|
2019-07-06 13:46:20 +00:00
|
|
|
uint8_t packed = it->value.as<uint8_t>() ? 0x00 : 0x01;
|
2019-06-29 08:08:37 +00:00
|
|
|
us.JSON.LF = packed;
|
|
|
|
us.JSON.padding = packed;
|
|
|
|
us.JSON.singleElement = packed;
|
2019-06-15 23:09:29 +00:00
|
|
|
NVstore.setUserSettings(us);
|
|
|
|
NVstore.save();
|
|
|
|
resetJSONmoderator();
|
|
|
|
}
|
2019-07-03 13:01:36 +00:00
|
|
|
else if(strcmp("TempMode", it->key) == 0) {
|
|
|
|
sUserSettings us = NVstore.getUserSettings();
|
2019-07-06 13:46:20 +00:00
|
|
|
us.degF = it->value.as<uint8_t>() ? 0x01 : 0x00;
|
2019-07-03 13:01:36 +00:00
|
|
|
NVstore.setUserSettings(us);
|
|
|
|
NVstore.save();
|
|
|
|
}
|
2019-07-19 20:53:12 +00:00
|
|
|
else if(strcmp("PumpCount", it->key) == 0) { // reset fuel gauge
|
|
|
|
int Count = it->value.as<int>();
|
|
|
|
if(Count == 0) {
|
|
|
|
RTC_Store.setFuelGauge(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(strcmp("PumpCal", it->key) == 0) {
|
|
|
|
float fCal = it->value.as<float>();
|
|
|
|
if(INBOUNDS(fCal, 0.001, 1)) {
|
|
|
|
sHeaterTuning ht = NVstore.getHeaterTuning();
|
|
|
|
ht.pumpCal = fCal;
|
|
|
|
NVstore.setHeaterTuning(ht);
|
2019-07-21 11:17:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(strcmp("TempOffset", it->key) == 0) {
|
|
|
|
float fCal = it->value.as<float>();
|
|
|
|
if(INBOUNDS(fCal, -10.0, +10.0)) {
|
|
|
|
sHeaterTuning ht = NVstore.getHeaterTuning();
|
|
|
|
ht.tempOfs = fCal;
|
|
|
|
NVstore.setHeaterTuning(ht);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(strcmp("LowVoltCutout", it->key) == 0) {
|
|
|
|
float fCal = it->value.as<float>();
|
2019-07-22 20:15:18 +00:00
|
|
|
bool bOK = false;
|
|
|
|
if(NVstore.getHeaterTuning().sysVoltage == 120)
|
|
|
|
bOK |= (fCal == 0) || INBOUNDS(fCal, 10.0, 12.5);
|
|
|
|
else
|
|
|
|
bOK |= (fCal == 0) || INBOUNDS(fCal, 20.0, 25.0);
|
|
|
|
if(bOK) {
|
|
|
|
sHeaterTuning ht = NVstore.getHeaterTuning();
|
|
|
|
ht.lowVolts = uint8_t(fCal * 10);
|
|
|
|
NVstore.setHeaterTuning(ht);
|
2019-07-19 20:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-15 23:09:29 +00:00
|
|
|
}
|
2018-12-13 12:19:10 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 09:40:00 +00:00
|
|
|
void validateTimer(int ID)
|
|
|
|
{
|
|
|
|
ID--; // supplied as +1
|
2019-06-15 23:09:29 +00:00
|
|
|
if(!INBOUNDS(ID, 0, 13))
|
2019-03-05 09:40:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
timerConflict = CTimerManager::conflictTest(ID); // check targeted timer against other timers
|
2018-12-13 12:19:10 +00:00
|
|
|
|
2019-03-14 10:52:59 +00:00
|
|
|
TimerModerator.reset(ID); // ensure we update client with our (real) version of the selected timer
|
2019-03-05 09:40:00 +00:00
|
|
|
}
|
2018-12-13 12:19:10 +00:00
|
|
|
|
2019-03-14 10:52:59 +00:00
|
|
|
bool makeJSONString(CModerator& moderator, char* opStr, int len)
|
2018-12-13 12:19:10 +00:00
|
|
|
{
|
2019-01-14 03:30:41 +00:00
|
|
|
StaticJsonBuffer<800> jsonBuffer; // create a JSON buffer on the stack
|
2018-12-15 09:34:58 +00:00
|
|
|
JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to
|
|
|
|
|
|
|
|
bool bSend = false; // reset should send flag
|
|
|
|
|
2019-03-14 10:52:59 +00:00
|
|
|
float tidyTemp = getTemperatureSensor();
|
2019-08-03 22:19:59 +00:00
|
|
|
tidyTemp = int(tidyTemp * 10 + 0.5) * 0.1f; // round to 0.1 resolution
|
2019-01-11 05:40:25 +00:00
|
|
|
if(tidyTemp > -80) {
|
|
|
|
bSend |= moderator.addJson("TempCurrent", tidyTemp, root);
|
|
|
|
}
|
2019-03-14 10:52:59 +00:00
|
|
|
bSend |= moderator.addJson("TempDesired", getTemperatureDesired(), root);
|
2018-12-15 09:34:58 +00:00
|
|
|
bSend |= moderator.addJson("TempMin", getHeaterInfo().getTemperature_Min(), root);
|
|
|
|
bSend |= moderator.addJson("TempMax", getHeaterInfo().getTemperature_Max(), root);
|
|
|
|
bSend |= moderator.addJson("TempBody", getHeaterInfo().getTemperature_HeatExchg(), root);
|
2019-04-04 10:48:05 +00:00
|
|
|
// bSend |= moderator.addJson("RunState", getHeaterInfo().getRunState(), root);
|
2019-04-04 19:39:58 +00:00
|
|
|
bSend |= moderator.addJson("RunState", getHeaterInfo().getRunStateEx(), root);
|
2018-12-16 02:45:13 +00:00
|
|
|
bSend |= moderator.addJson("RunString", getHeaterInfo().getRunStateStr(), root); // verbose it up!
|
2018-12-21 01:27:03 +00:00
|
|
|
bSend |= moderator.addJson("ErrorState", getHeaterInfo().getErrState(), root );
|
|
|
|
bSend |= moderator.addJson("ErrorString", getHeaterInfo().getErrStateStrEx(), root); // verbose it up!
|
2019-03-14 10:52:59 +00:00
|
|
|
bSend |= moderator.addJson("Thermostat", getThermostatModeActive(), root );
|
2018-12-15 09:34:58 +00:00
|
|
|
bSend |= moderator.addJson("PumpFixed", getHeaterInfo().getPump_Fixed(), root );
|
|
|
|
bSend |= moderator.addJson("PumpMin", getHeaterInfo().getPump_Min(), root );
|
|
|
|
bSend |= moderator.addJson("PumpMax", getHeaterInfo().getPump_Max(), root );
|
|
|
|
bSend |= moderator.addJson("PumpActual", getHeaterInfo().getPump_Actual(), root );
|
|
|
|
bSend |= moderator.addJson("FanMin", getHeaterInfo().getFan_Min(), root );
|
|
|
|
bSend |= moderator.addJson("FanMax", getHeaterInfo().getFan_Max(), root );
|
2019-07-06 13:46:20 +00:00
|
|
|
bSend |= moderator.addJson("FanRPM", getFanSpeed(), root );
|
2018-12-15 09:34:58 +00:00
|
|
|
bSend |= moderator.addJson("FanVoltage", getHeaterInfo().getFan_Voltage(), root );
|
2019-01-11 05:40:25 +00:00
|
|
|
bSend |= moderator.addJson("FanSensor", getHeaterInfo().getFan_Sensor(), root );
|
2019-07-21 11:17:54 +00:00
|
|
|
bSend |= moderator.addJson("InputVoltage", getBatteryVoltage(false), root );
|
2019-01-11 05:40:25 +00:00
|
|
|
bSend |= moderator.addJson("SystemVoltage", getHeaterInfo().getSystemVoltage(), root );
|
2019-07-06 13:46:20 +00:00
|
|
|
bSend |= moderator.addJson("GlowVoltage", getGlowVolts(), root );
|
|
|
|
bSend |= moderator.addJson("GlowCurrent", getGlowCurrent(), root );
|
2018-12-20 22:22:29 +00:00
|
|
|
bSend |= moderator.addJson("BluewireStat", getBlueWireStatStr(), root );
|
2019-06-06 01:32:43 +00:00
|
|
|
bSend |= moderator.addJson("TempMode", NVstore.getUserSettings().degF, root);
|
2018-12-15 09:34:58 +00:00
|
|
|
|
|
|
|
if(bSend) {
|
|
|
|
root.printTo(opStr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSend;
|
|
|
|
}
|
2018-12-13 12:19:10 +00:00
|
|
|
|
2019-03-15 08:08:05 +00:00
|
|
|
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
|
|
|
|
|
2019-06-06 01:32:43 +00:00
|
|
|
bSend |= moderator.addJson("ThermostatMethod", NVstore.getUserSettings().ThermostatMethod, root);
|
|
|
|
bSend |= moderator.addJson("ThermostatWindow", NVstore.getUserSettings().ThermostatWindow, root);
|
2019-07-03 13:01:36 +00:00
|
|
|
int stop = NVstore.getUserSettings().cyclic.Stop;
|
2019-06-30 12:39:40 +00:00
|
|
|
if(stop) stop++; // deliver effective threshold, not internal working value
|
|
|
|
bSend |= moderator.addJson("ThermostatOvertemp", stop, root);
|
2019-07-03 13:01:36 +00:00
|
|
|
bSend |= moderator.addJson("ThermostatUndertemp", NVstore.getUserSettings().cyclic.Start, root);
|
|
|
|
bSend |= moderator.addJson("CyclicTemp", getDemandDegC(), root); // actual pivot point for cyclic mode
|
|
|
|
bSend |= moderator.addJson("CyclicOff", stop, root); // threshold of over temp for cyclic mode
|
2019-07-21 11:17:54 +00:00
|
|
|
bSend |= moderator.addJson("CyclicOn", NVstore.getUserSettings().cyclic.Start, root); // threshold of under temp for cyclic mode
|
|
|
|
bSend |= moderator.addJson("PumpCount", RTC_Store.getFuelGauge(), root); // running count of pump strokes
|
|
|
|
bSend |= moderator.addJson("PumpCal", NVstore.getHeaterTuning().pumpCal, root); // mL/stroke
|
|
|
|
bSend |= moderator.addJson("TempOffset", NVstore.getHeaterTuning().tempOfs, root); // degC offset
|
2019-07-21 20:30:08 +00:00
|
|
|
bSend |= moderator.addJson("LowVoltCutout", NVstore.getHeaterTuning().getLVC(), root); // low volatge cutout
|
2019-03-15 08:08:05 +00:00
|
|
|
|
|
|
|
if(bSend) {
|
|
|
|
root.printTo(opStr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSend;
|
|
|
|
}
|
|
|
|
|
2019-03-03 08:48:52 +00:00
|
|
|
// 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
|
|
|
|
// Only timer parameters that have changed will be sent, after reset the typical string will be
|
|
|
|
// {"TimerStart":XX:XX,"TimerStop":XX:XX,"TimerDays":XX,"TimerRepeat":X}
|
2019-03-14 10:52:59 +00:00
|
|
|
bool makeJSONTimerString(int channel, char* opStr, int len)
|
2019-03-03 08:48:52 +00:00
|
|
|
{
|
2019-06-04 20:15:12 +00:00
|
|
|
bool bSend = false; // reset should send flag
|
2019-03-03 08:48:52 +00:00
|
|
|
StaticJsonBuffer<800> jsonBuffer; // create a JSON buffer on the stack
|
|
|
|
JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to
|
|
|
|
|
|
|
|
|
|
|
|
sTimer timerInfo;
|
|
|
|
NVstore.getTimerInfo(channel, timerInfo);
|
|
|
|
bSend |= TimerModerator.addJson(channel, timerInfo, root );
|
|
|
|
|
|
|
|
if(bSend) {
|
|
|
|
root.printTo(opStr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSend;
|
|
|
|
}
|
|
|
|
|
2019-06-04 20:15:12 +00:00
|
|
|
bool makeJSONStringGPIO(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
|
|
|
|
|
|
|
|
sGPIO info;
|
|
|
|
getGPIOinfo(info);
|
|
|
|
|
|
|
|
bSend |= moderator.addJson("GPin1", info.inState[0], root);
|
|
|
|
bSend |= moderator.addJson("GPin2", info.inState[1], root);
|
|
|
|
bSend |= moderator.addJson("GPout1", info.outState[0], root);
|
|
|
|
bSend |= moderator.addJson("GPout2", info.outState[1], root);
|
|
|
|
bSend |= moderator.addJson("GPanlg", info.algVal * 100 / 4096, root);
|
2019-08-07 12:04:20 +00:00
|
|
|
bSend |= moderator.addJson("GPmodeIn1", GPIOin1Names[info.in1Mode], root);
|
|
|
|
bSend |= moderator.addJson("GPmodeIn2", GPIOin2Names[info.in2Mode], root);
|
|
|
|
bSend |= moderator.addJson("GPmodeOut1", GPIOout1Names[info.out1Mode], root);
|
|
|
|
bSend |= moderator.addJson("GPmodeOut2", GPIOout2Names[info.out2Mode], root);
|
2019-06-04 20:15:12 +00:00
|
|
|
bSend |= moderator.addJson("GPmodeAnlg", GPIOalgNames[info.algMode], root);
|
|
|
|
|
|
|
|
if(bSend) {
|
|
|
|
root.printTo(opStr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSend;
|
|
|
|
}
|
2019-03-03 08:48:52 +00:00
|
|
|
|
2019-05-12 10:15:18 +00:00
|
|
|
bool makeJSONStringMQTT(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
|
2019-05-14 11:29:35 +00:00
|
|
|
sMQTTparams info = NVstore.getMQTTinfo();
|
2019-05-12 10:15:18 +00:00
|
|
|
|
|
|
|
bSend |= moderator.addJson("MEn", info.enabled, root);
|
|
|
|
bSend |= moderator.addJson("MPort", info.port, root);
|
|
|
|
bSend |= moderator.addJson("MHost", info.host, root);
|
|
|
|
bSend |= moderator.addJson("MUser", info.username, root);
|
|
|
|
bSend |= moderator.addJson("MPasswd", info.password, root);
|
|
|
|
|
|
|
|
if(bSend) {
|
|
|
|
root.printTo(opStr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSend;
|
|
|
|
}
|
|
|
|
|
2019-07-15 09:56:36 +00:00
|
|
|
|
|
|
|
bool makeJSONStringSysInfo(CModerator& moderator, char* opStr, int len)
|
|
|
|
{
|
|
|
|
bool bSend = false; // reset should send flag
|
|
|
|
|
2019-07-17 09:35:34 +00:00
|
|
|
if(bTriggerSysParams || bTriggerDateTime) {
|
2019-07-15 09:56:36 +00:00
|
|
|
|
2019-07-17 09:35:34 +00:00
|
|
|
StaticJsonBuffer<800> jsonBuffer; // create a JSON buffer on the stack
|
|
|
|
JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to
|
2019-07-15 09:56:36 +00:00
|
|
|
|
2019-07-17 09:35:34 +00:00
|
|
|
const BTCDateTime& now = Clock.get();
|
|
|
|
|
|
|
|
char str[32];
|
|
|
|
sprintf(str, "%d/%d/%d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
|
|
|
|
bSend |= moderator.addJson("DateTime", str, root);
|
|
|
|
if(bTriggerSysParams) {
|
2019-07-26 13:12:00 +00:00
|
|
|
bSend |= moderator.addJson("SysUpTime", sysUptime(), root);
|
2019-07-17 09:35:34 +00:00
|
|
|
bSend |= moderator.addJson("SysVer", getVersionStr(), root);
|
|
|
|
bSend |= moderator.addJson("SysDate", getVersionDate(), root);
|
|
|
|
bSend |= moderator.addJson("SysFreeMem", ESP.getFreeHeap(), root);
|
2019-07-24 20:06:47 +00:00
|
|
|
bSend |= moderator.addJson("SysRunTime", pHourMeter->getRunTime(), root);
|
|
|
|
bSend |= moderator.addJson("SysGlowTime", pHourMeter->getGlowTime(), root);
|
2019-07-17 09:35:34 +00:00
|
|
|
}
|
|
|
|
if(bSend) {
|
|
|
|
root.printTo(opStr, len);
|
|
|
|
}
|
2019-07-15 09:56:36 +00:00
|
|
|
}
|
|
|
|
|
2019-07-17 09:35:34 +00:00
|
|
|
bTriggerSysParams = false;
|
|
|
|
bTriggerDateTime = false;
|
|
|
|
|
2019-07-15 09:56:36 +00:00
|
|
|
return bSend;
|
|
|
|
}
|
|
|
|
|
2019-07-11 12:03:27 +00:00
|
|
|
bool makeJSONStringIP(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("IP_AP", getWifiAPAddrStr(), root);
|
|
|
|
bSend |= moderator.addJson("IP_APMAC", getWifiAPMACStr(), root);
|
|
|
|
bSend |= moderator.addJson("IP_STA", getWifiSTAAddrStr(), root);
|
|
|
|
bSend |= moderator.addJson("IP_STAMAC", getWifiSTAMACStr(), root);
|
|
|
|
bSend |= moderator.addJson("IP_STASSID", getSSID().c_str(), root);
|
|
|
|
bSend |= moderator.addJson("IP_OTA", NVstore.getUserSettings().enableOTA, root);
|
2019-07-27 02:47:16 +00:00
|
|
|
bSend |= moderator.addJson("BT_MAC", getBluetoothClient().getMAC(), root);
|
2019-07-11 12:03:27 +00:00
|
|
|
|
|
|
|
if(bSend) {
|
|
|
|
root.printTo(opStr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSend;
|
|
|
|
}
|
2018-12-13 12:19:10 +00:00
|
|
|
|
2018-12-20 04:19:59 +00:00
|
|
|
void updateJSONclients(bool report)
|
|
|
|
{
|
2019-03-03 08:48:52 +00:00
|
|
|
// update general parameters
|
2019-03-05 09:40:00 +00:00
|
|
|
char jsonStr[800];
|
2019-03-03 08:48:52 +00:00
|
|
|
{
|
2019-03-14 10:52:59 +00:00
|
|
|
if(makeJSONString(JSONmoderator, jsonStr, sizeof(jsonStr))) {
|
2019-03-03 08:48:52 +00:00
|
|
|
if (report) {
|
2019-05-12 10:15:18 +00:00
|
|
|
DebugPort.printf("JSON send: %s\r\n", jsonStr);
|
2019-03-03 08:48:52 +00:00
|
|
|
}
|
2019-07-07 07:18:38 +00:00
|
|
|
sendWebSocketString( jsonStr );
|
2019-06-06 01:32:43 +00:00
|
|
|
std::string expand = jsonStr;
|
|
|
|
Expand(expand);
|
|
|
|
getBluetoothClient().send( expand.c_str() );
|
2019-03-03 08:48:52 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-15 08:08:05 +00:00
|
|
|
// update extended params
|
|
|
|
{
|
|
|
|
if(makeJSONStringEx(JSONmoderator, jsonStr, sizeof(jsonStr))) {
|
|
|
|
if (report) {
|
2019-05-12 10:15:18 +00:00
|
|
|
DebugPort.printf("JSON send: %s\r\n", jsonStr);
|
2019-03-15 08:08:05 +00:00
|
|
|
}
|
2019-07-07 07:18:38 +00:00
|
|
|
sendWebSocketString( jsonStr );
|
2019-06-06 01:32:43 +00:00
|
|
|
std::string expand = jsonStr;
|
|
|
|
Expand(expand);
|
|
|
|
getBluetoothClient().send( expand.c_str() );
|
2019-03-15 08:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-03 08:48:52 +00:00
|
|
|
// update timer parameters
|
2019-03-05 09:40:00 +00:00
|
|
|
bool bNewTimerInfo = false;
|
2019-03-03 08:48:52 +00:00
|
|
|
for(int tmr=0; tmr<14; tmr++)
|
|
|
|
{
|
2019-05-08 20:30:26 +00:00
|
|
|
unsigned long tStart = millis();
|
2019-03-14 10:52:59 +00:00
|
|
|
if(makeJSONTimerString(tmr, jsonStr, sizeof(jsonStr))) {
|
2019-05-08 20:30:26 +00:00
|
|
|
unsigned long tJSON = millis() - tStart;
|
2019-03-03 08:48:52 +00:00
|
|
|
if (report) {
|
2019-05-12 10:15:18 +00:00
|
|
|
DebugPort.printf("JSON send: %s\r\n", jsonStr);
|
2019-03-03 08:48:52 +00:00
|
|
|
}
|
2019-05-08 20:30:26 +00:00
|
|
|
tStart = millis();
|
2019-07-07 07:18:38 +00:00
|
|
|
sendWebSocketString( jsonStr );
|
2019-05-08 20:30:26 +00:00
|
|
|
unsigned long tWF = millis() - tStart;
|
|
|
|
tStart = millis();
|
2019-06-06 01:32:43 +00:00
|
|
|
std::string expand = jsonStr;
|
|
|
|
Expand(expand);
|
|
|
|
getBluetoothClient().send( expand.c_str() );
|
2019-05-08 20:30:26 +00:00
|
|
|
unsigned long tBT = millis() - tStart;
|
2019-03-05 09:40:00 +00:00
|
|
|
bNewTimerInfo = true;
|
2019-07-28 07:40:12 +00:00
|
|
|
// DebugPort.printf("JSON times : %ld,%ld,%ld\r\n", tJSON, tBT, tWF);
|
2018-12-20 04:19:59 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-05 09:40:00 +00:00
|
|
|
// request timer refesh upon clients
|
|
|
|
if(bNewTimerInfo) {
|
|
|
|
StaticJsonBuffer<800> jsonBuffer; // create a JSON buffer on the stack
|
|
|
|
JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to
|
|
|
|
|
|
|
|
if(timerConflict) {
|
|
|
|
root.set("TimerConflict", timerConflict);
|
|
|
|
timerConflict = 0;
|
|
|
|
}
|
|
|
|
root.set("TimerRefresh", 1);
|
|
|
|
root.printTo(jsonStr, 800);
|
|
|
|
|
2019-07-28 07:40:12 +00:00
|
|
|
if (report) {
|
|
|
|
DebugPort.printf("JSON send: %s\r\n", jsonStr);
|
|
|
|
}
|
2019-07-07 07:18:38 +00:00
|
|
|
sendWebSocketString( jsonStr );
|
2019-06-15 23:09:29 +00:00
|
|
|
std::string expand = jsonStr;
|
|
|
|
Expand(expand);
|
|
|
|
getBluetoothClient().send( expand.c_str() );
|
2019-03-05 09:40:00 +00:00
|
|
|
}
|
2019-05-12 10:15:18 +00:00
|
|
|
|
|
|
|
// report MQTT params
|
|
|
|
{
|
|
|
|
if(makeJSONStringMQTT(MQTTmoderator, jsonStr, sizeof(jsonStr))) {
|
|
|
|
if (report) {
|
|
|
|
DebugPort.printf("JSON send: %s\r\n", jsonStr);
|
|
|
|
}
|
2019-07-07 07:18:38 +00:00
|
|
|
sendWebSocketString( jsonStr );
|
2019-06-06 01:32:43 +00:00
|
|
|
std::string expand = jsonStr;
|
|
|
|
Expand(expand);
|
|
|
|
getBluetoothClient().send( expand.c_str() );
|
2019-05-12 10:15:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-04 20:15:12 +00:00
|
|
|
|
2019-07-15 09:56:36 +00:00
|
|
|
// report IP params
|
2019-07-11 12:03:27 +00:00
|
|
|
{
|
|
|
|
if(makeJSONStringIP(IPmoderator, jsonStr, sizeof(jsonStr))) {
|
|
|
|
if (report) {
|
|
|
|
DebugPort.printf("JSON send: %s\r\n", jsonStr);
|
|
|
|
}
|
|
|
|
sendWebSocketString( jsonStr );
|
|
|
|
std::string expand = jsonStr;
|
|
|
|
Expand(expand);
|
|
|
|
getBluetoothClient().send( expand.c_str() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 09:56:36 +00:00
|
|
|
// report System info
|
|
|
|
{
|
2019-07-17 09:35:34 +00:00
|
|
|
if(makeJSONStringSysInfo(SysModerator, jsonStr, sizeof(jsonStr))) {
|
2019-07-15 09:56:36 +00:00
|
|
|
if (report) {
|
|
|
|
DebugPort.printf("JSON send: %s\r\n", jsonStr);
|
|
|
|
}
|
|
|
|
sendWebSocketString( jsonStr );
|
|
|
|
std::string expand = jsonStr;
|
|
|
|
Expand(expand);
|
|
|
|
getBluetoothClient().send( expand.c_str() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-04 20:15:12 +00:00
|
|
|
{
|
|
|
|
if(makeJSONStringGPIO(GPIOmoderator, jsonStr, sizeof(jsonStr))) {
|
|
|
|
if (report) {
|
|
|
|
DebugPort.printf("JSON send: %s\r\n", jsonStr);
|
|
|
|
}
|
2019-07-07 07:18:38 +00:00
|
|
|
sendWebSocketString( jsonStr );
|
2019-06-06 01:32:43 +00:00
|
|
|
std::string expand = jsonStr;
|
|
|
|
Expand(expand);
|
|
|
|
getBluetoothClient().send( expand.c_str() );
|
2019-06-04 20:15:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 04:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void resetJSONmoderator()
|
|
|
|
{
|
|
|
|
JSONmoderator.reset();
|
2019-06-02 09:19:08 +00:00
|
|
|
#ifdef SALWAYS_SEND_TIMERS
|
|
|
|
TimerModerator.reset();
|
|
|
|
#else
|
2019-05-30 10:31:34 +00:00
|
|
|
initTimerJSONmoderator();
|
2019-06-02 09:19:08 +00:00
|
|
|
#endif
|
2019-05-30 10:31:34 +00:00
|
|
|
initMQTTJSONmoderator();
|
2019-07-11 12:03:27 +00:00
|
|
|
initIPJSONmoderator();
|
2019-07-15 09:56:36 +00:00
|
|
|
initSysModerator();
|
2019-06-04 20:15:12 +00:00
|
|
|
GPIOmoderator.reset();
|
2018-12-20 04:19:59 +00:00
|
|
|
}
|
|
|
|
|
2019-05-12 10:15:18 +00:00
|
|
|
void initMQTTJSONmoderator()
|
|
|
|
{
|
|
|
|
char jsonStr[800];
|
|
|
|
makeJSONStringMQTT(MQTTmoderator, jsonStr, sizeof(jsonStr));
|
|
|
|
}
|
2018-12-20 04:19:59 +00:00
|
|
|
|
2019-07-11 12:03:27 +00:00
|
|
|
void initIPJSONmoderator()
|
|
|
|
{
|
|
|
|
char jsonStr[800];
|
|
|
|
makeJSONStringIP(IPmoderator, jsonStr, sizeof(jsonStr));
|
|
|
|
}
|
|
|
|
|
2019-07-15 09:56:36 +00:00
|
|
|
void initSysModerator()
|
|
|
|
{
|
|
|
|
char jsonStr[800];
|
|
|
|
makeJSONStringSysInfo(SysModerator, jsonStr, sizeof(jsonStr));
|
|
|
|
}
|
|
|
|
|
2019-05-30 10:31:34 +00:00
|
|
|
void initTimerJSONmoderator()
|
|
|
|
{
|
|
|
|
char jsonStr[800];
|
|
|
|
for(int tmr=0; tmr<14; tmr++)
|
|
|
|
makeJSONTimerString(tmr, jsonStr, sizeof(jsonStr));
|
|
|
|
}
|
2018-12-20 04:19:59 +00:00
|
|
|
|
2019-06-06 01:32:43 +00:00
|
|
|
|
|
|
|
void Expand(std::string& str)
|
|
|
|
{
|
2019-06-15 23:09:29 +00:00
|
|
|
const sUserSettings& userOptions = NVstore.getUserSettings();
|
|
|
|
|
|
|
|
if(userOptions.JSON.singleElement) {
|
|
|
|
size_t pos = str.find(",\"");
|
|
|
|
while(pos != std::string::npos) {
|
|
|
|
if(userOptions.JSON.LF)
|
|
|
|
str.replace(pos, 2, "}\n{\""); // converts {"name":value,"name2":value"} to {"name":value}\n{"name2":value}
|
|
|
|
else
|
|
|
|
str.replace(pos, 2, "}{\""); // converts {"name":value,"name2":value"} to {"name":value}{"name2":value}
|
|
|
|
pos = str.find(",\"");
|
|
|
|
}
|
|
|
|
if(userOptions.JSON.padding) { // converts {"name":value} to {"name": value}
|
|
|
|
pos = str.find("\":");
|
|
|
|
while(pos != std::string::npos) {
|
|
|
|
str.replace(pos, 2, "\": ");
|
|
|
|
pos = str.find("\":", pos+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(userOptions.JSON.LF)
|
|
|
|
str.append("\n");
|
2019-06-06 01:32:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|