mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 16:59:50 +03:00
Merge pull request #207 from peclik:dev
more values published over MQTT
This commit is contained in:
@@ -84,7 +84,7 @@ extern struct rst_info resetInfo;
|
|||||||
#define MQTT_QOS 1
|
#define MQTT_QOS 1
|
||||||
#define MQTT_WILL_TOPIC "status" // for last will & testament topic name
|
#define MQTT_WILL_TOPIC "status" // for last will & testament topic name
|
||||||
#define MQTT_MAX_TOPIC_SIZE 50 // max length of MQTT topic
|
#define MQTT_MAX_TOPIC_SIZE 50 // max length of MQTT topic
|
||||||
#define MQTT_MAX_PAYLOAD_SIZE 500 // max size of a JSON object. See https://arduinojson.org/v6/assistant/
|
#define MQTT_MAX_PAYLOAD_SIZE 700 // max size of a JSON object. See https://arduinojson.org/v6/assistant/
|
||||||
#define MQTT_MAX_PAYLOAD_SIZE_LARGE 2000 // max size of a large JSON object, like for sending MQTT log
|
#define MQTT_MAX_PAYLOAD_SIZE_LARGE 2000 // max size of a large JSON object, like for sending MQTT log
|
||||||
#define MYESP_JSON_MAXSIZE 2000 // for large Dynamic json files
|
#define MYESP_JSON_MAXSIZE 2000 // for large Dynamic json files
|
||||||
#define MYESP_MQTTLOG_MAX 60 // max number of log entries for MQTT publishes and subscribes
|
#define MYESP_MQTTLOG_MAX 60 // max number of log entries for MQTT publishes and subscribes
|
||||||
|
|||||||
@@ -766,7 +766,8 @@ void publishValues(bool force) {
|
|||||||
|
|
||||||
static uint8_t last_boilerActive = 0xFF; // for remembering last setting of the tap water or heating on/off
|
static uint8_t last_boilerActive = 0xFF; // for remembering last setting of the tap water or heating on/off
|
||||||
static uint32_t previousBoilerPublishCRC = 0; // CRC check for boiler values
|
static uint32_t previousBoilerPublishCRC = 0; // CRC check for boiler values
|
||||||
static uint32_t previousThermostatPublishCRC = 0; // CRC check for thermostat values
|
static uint32_t previousThermostatPublishCRC[EMS_THERMOSTAT_MAXHC]; // CRC check for thermostat values
|
||||||
|
static uint32_t previousMixingPublishCRC[EMS_THERMOSTAT_MAXHC]; // CRC check for mixing values
|
||||||
static uint32_t previousSMPublishCRC = 0; // CRC check for Solar Module values (e.g. SM10)
|
static uint32_t previousSMPublishCRC = 0; // CRC check for Solar Module values (e.g. SM10)
|
||||||
|
|
||||||
JsonObject rootBoiler = doc.to<JsonObject>();
|
JsonObject rootBoiler = doc.to<JsonObject>();
|
||||||
@@ -781,6 +782,8 @@ void publishValues(bool force) {
|
|||||||
|
|
||||||
if (EMS_Boiler.wWSelTemp != EMS_VALUE_INT_NOTSET)
|
if (EMS_Boiler.wWSelTemp != EMS_VALUE_INT_NOTSET)
|
||||||
rootBoiler["wWSelTemp"] = EMS_Boiler.wWSelTemp;
|
rootBoiler["wWSelTemp"] = EMS_Boiler.wWSelTemp;
|
||||||
|
if (EMS_Boiler.wWDesiredTemp != EMS_VALUE_INT_NOTSET)
|
||||||
|
rootBoiler["wWDesiredTemp"] = EMS_Boiler.wWDesiredTemp;
|
||||||
if (EMS_Boiler.selFlowTemp != EMS_VALUE_INT_NOTSET)
|
if (EMS_Boiler.selFlowTemp != EMS_VALUE_INT_NOTSET)
|
||||||
rootBoiler["selFlowTemp"] = EMS_Boiler.selFlowTemp;
|
rootBoiler["selFlowTemp"] = EMS_Boiler.selFlowTemp;
|
||||||
if (EMS_Boiler.selBurnPow != EMS_VALUE_INT_NOTSET)
|
if (EMS_Boiler.selBurnPow != EMS_VALUE_INT_NOTSET)
|
||||||
@@ -789,6 +792,8 @@ void publishValues(bool force) {
|
|||||||
rootBoiler["curBurnPow"] = EMS_Boiler.curBurnPow;
|
rootBoiler["curBurnPow"] = EMS_Boiler.curBurnPow;
|
||||||
if (EMS_Boiler.pumpMod != EMS_VALUE_INT_NOTSET)
|
if (EMS_Boiler.pumpMod != EMS_VALUE_INT_NOTSET)
|
||||||
rootBoiler["pumpMod"] = EMS_Boiler.pumpMod;
|
rootBoiler["pumpMod"] = EMS_Boiler.pumpMod;
|
||||||
|
if (EMS_Boiler.wWCircPump != EMS_VALUE_INT_NOTSET)
|
||||||
|
rootBoiler["wWCircPump"] = EMS_Boiler.wWCircPump;
|
||||||
|
|
||||||
if (EMS_Boiler.extTemp != EMS_VALUE_SHORT_NOTSET)
|
if (EMS_Boiler.extTemp != EMS_VALUE_SHORT_NOTSET)
|
||||||
rootBoiler["outdoorTemp"] = (double)EMS_Boiler.extTemp / 10;
|
rootBoiler["outdoorTemp"] = (double)EMS_Boiler.extTemp / 10;
|
||||||
@@ -813,6 +818,9 @@ void publishValues(bool force) {
|
|||||||
if (EMS_Boiler.burnGas != EMS_VALUE_INT_NOTSET)
|
if (EMS_Boiler.burnGas != EMS_VALUE_INT_NOTSET)
|
||||||
rootBoiler["burnGas"] = _bool_to_char(s, EMS_Boiler.burnGas);
|
rootBoiler["burnGas"] = _bool_to_char(s, EMS_Boiler.burnGas);
|
||||||
|
|
||||||
|
if (EMS_Boiler.flameCurr != EMS_VALUE_USHORT_NOTSET)
|
||||||
|
rootBoiler["flameCurr"] = (double)(int16_t)EMS_Boiler.flameCurr / 10;
|
||||||
|
|
||||||
if (EMS_Boiler.heatPmp != EMS_VALUE_INT_NOTSET)
|
if (EMS_Boiler.heatPmp != EMS_VALUE_INT_NOTSET)
|
||||||
rootBoiler["heatPmp"] = _bool_to_char(s, EMS_Boiler.heatPmp);
|
rootBoiler["heatPmp"] = _bool_to_char(s, EMS_Boiler.heatPmp);
|
||||||
|
|
||||||
@@ -825,9 +833,24 @@ void publishValues(bool force) {
|
|||||||
if (EMS_Boiler.wWCirc != EMS_VALUE_INT_NOTSET)
|
if (EMS_Boiler.wWCirc != EMS_VALUE_INT_NOTSET)
|
||||||
rootBoiler["wWCirc"] = _bool_to_char(s, EMS_Boiler.wWCirc);
|
rootBoiler["wWCirc"] = _bool_to_char(s, EMS_Boiler.wWCirc);
|
||||||
|
|
||||||
|
if (EMS_Boiler.heating_temp != EMS_VALUE_INT_NOTSET)
|
||||||
|
rootBoiler["heating_temp"] = EMS_Boiler.heating_temp;
|
||||||
|
if (EMS_Boiler.pump_mod_max != EMS_VALUE_INT_NOTSET)
|
||||||
|
rootBoiler["pump_mod_max"] = EMS_Boiler.pump_mod_max;
|
||||||
|
if (EMS_Boiler.pump_mod_min != EMS_VALUE_INT_NOTSET)
|
||||||
|
rootBoiler["pump_mod_min"] = EMS_Boiler.pump_mod_min;
|
||||||
|
|
||||||
if (EMS_Boiler.wWHeat != EMS_VALUE_INT_NOTSET)
|
if (EMS_Boiler.wWHeat != EMS_VALUE_INT_NOTSET)
|
||||||
rootBoiler["wWHeat"] = _bool_to_char(s, EMS_Boiler.wWHeat);
|
rootBoiler["wWHeat"] = _bool_to_char(s, EMS_Boiler.wWHeat);
|
||||||
|
|
||||||
|
// **** also add burnStarts, burnWorkMin, heatWorkMin
|
||||||
|
if (abs(EMS_Boiler.wWStarts) != EMS_VALUE_LONG_NOTSET)
|
||||||
|
rootBoiler["wWStarts"] = (double)EMS_Boiler.wWStarts;
|
||||||
|
if (abs(EMS_Boiler.wWWorkM) != EMS_VALUE_LONG_NOTSET)
|
||||||
|
rootBoiler["wWWorkM"] = (double)EMS_Boiler.wWWorkM;
|
||||||
|
if (abs(EMS_Boiler.UBAuptime) != EMS_VALUE_LONG_NOTSET)
|
||||||
|
rootBoiler["UBAuptime"] = (double)EMS_Boiler.UBAuptime;
|
||||||
|
|
||||||
// **** also add burnStarts, burnWorkMin, heatWorkMin
|
// **** also add burnStarts, burnWorkMin, heatWorkMin
|
||||||
if (abs(EMS_Boiler.burnStarts) != EMS_VALUE_LONG_NOTSET)
|
if (abs(EMS_Boiler.burnStarts) != EMS_VALUE_LONG_NOTSET)
|
||||||
rootBoiler["burnStarts"] = (double)EMS_Boiler.burnStarts;
|
rootBoiler["burnStarts"] = (double)EMS_Boiler.burnStarts;
|
||||||
@@ -942,8 +965,8 @@ void publishValues(bool force) {
|
|||||||
crc.update(data[i]);
|
crc.update(data[i]);
|
||||||
}
|
}
|
||||||
fchecksum = crc.finalize();
|
fchecksum = crc.finalize();
|
||||||
if ((previousThermostatPublishCRC != fchecksum) || force) {
|
if ((previousThermostatPublishCRC[hc_v - 1] != fchecksum) || force) {
|
||||||
previousThermostatPublishCRC = fchecksum;
|
previousThermostatPublishCRC[hc_v - 1] = fchecksum;
|
||||||
char thermostat_topicname[20];
|
char thermostat_topicname[20];
|
||||||
char buffer[4];
|
char buffer[4];
|
||||||
// "thermostat_data" + Heating Cicruit #
|
// "thermostat_data" + Heating Cicruit #
|
||||||
@@ -957,6 +980,53 @@ void publishValues(bool force) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle the thermostat values
|
||||||
|
if (ems_getMixingDeviceEnabled()) {
|
||||||
|
for (uint8_t hc_v = 1; hc_v <= EMS_THERMOSTAT_MAXHC; hc_v++) {
|
||||||
|
_EMS_Mixing_HC * mixing = &EMS_Mixing.hc[hc_v - 1];
|
||||||
|
|
||||||
|
// only send if we have an active Heating Circuit with real data
|
||||||
|
if (mixing->active) {
|
||||||
|
// build new json object
|
||||||
|
doc.clear();
|
||||||
|
JsonObject rootMixing = doc.to<JsonObject>();
|
||||||
|
|
||||||
|
if (mixing->flowTemp != EMS_VALUE_SHORT_NOTSET)
|
||||||
|
rootMixing["flowTemp"] = (double)mixing->flowTemp / 10;
|
||||||
|
if (mixing->pumpMod != EMS_VALUE_INT_NOTSET)
|
||||||
|
rootMixing["pumpMod"] = mixing->pumpMod;
|
||||||
|
if (mixing->valveStatus != EMS_VALUE_INT_NOTSET)
|
||||||
|
rootMixing["valveStatus"] = mixing->valveStatus;
|
||||||
|
|
||||||
|
data[0] = '\0'; // reset data for next package
|
||||||
|
serializeJson(doc, data, sizeof(data));
|
||||||
|
|
||||||
|
// check for empty json
|
||||||
|
jsonSize = measureJson(doc);
|
||||||
|
if (jsonSize > 2) {
|
||||||
|
// calculate new CRC
|
||||||
|
crc.reset();
|
||||||
|
for (uint8_t i = 0; i < (jsonSize - 1); i++) {
|
||||||
|
crc.update(data[i]);
|
||||||
|
}
|
||||||
|
fchecksum = crc.finalize();
|
||||||
|
if ((previousMixingPublishCRC[hc_v - 1] != fchecksum) || force) {
|
||||||
|
previousMixingPublishCRC[hc_v - 1] = fchecksum;
|
||||||
|
char mixing_topicname[20];
|
||||||
|
char buffer[4];
|
||||||
|
// "mixingt_data" + Heating Cicruit #
|
||||||
|
strlcpy(mixing_topicname, TOPIC_MIXING_DATA, sizeof(mixing_topicname));
|
||||||
|
strlcat(mixing_topicname, itoa(hc_v, buffer, 10), sizeof(mixing_topicname));
|
||||||
|
myDebugLog("Publishing mixing device data via MQTT");
|
||||||
|
myESP.mqttPublish(mixing_topicname, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// For SM10 and SM100 Solar Modules
|
// For SM10 and SM100 Solar Modules
|
||||||
if (ems_getSolarModuleEnabled()) {
|
if (ems_getSolarModuleEnabled()) {
|
||||||
// build new json object
|
// build new json object
|
||||||
|
|||||||
@@ -40,6 +40,9 @@
|
|||||||
#define TOPIC_BOILER_CMD_COMFORT "boiler_cmd_comfort" // ww comfort setting via MQTT
|
#define TOPIC_BOILER_CMD_COMFORT "boiler_cmd_comfort" // ww comfort setting via MQTT
|
||||||
#define TOPIC_BOILER_CMD_FLOWTEMP "boiler_cmd_flowtemp" // flowtemp value via MQTT
|
#define TOPIC_BOILER_CMD_FLOWTEMP "boiler_cmd_flowtemp" // flowtemp value via MQTT
|
||||||
|
|
||||||
|
// MQTT for mixing device
|
||||||
|
#define TOPIC_MIXING_DATA "mixing_data" // for sending mixing device values to MQTT
|
||||||
|
|
||||||
// MQTT for SM10/SM100 Solar Module
|
// MQTT for SM10/SM100 Solar Module
|
||||||
#define TOPIC_SM_DATA "sm_data" // topic name
|
#define TOPIC_SM_DATA "sm_data" // topic name
|
||||||
#define SM_COLLECTORTEMP "collectortemp" // collector temp
|
#define SM_COLLECTORTEMP "collectortemp" // collector temp
|
||||||
|
|||||||
Reference in New Issue
Block a user