Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #207 from peclik:dev
Browse files Browse the repository at this point in the history
more values published over MQTT
  • Loading branch information
proddy authored Oct 11, 2019
2 parents 3eb2637 + f6aafe8 commit 460b5fd
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/MyESP.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extern struct rst_info resetInfo;
#define MQTT_QOS 1
#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_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 MYESP_JSON_MAXSIZE 2000 // for large Dynamic json files
#define MYESP_MQTTLOG_MAX 60 // max number of log entries for MQTT publishes and subscribes
Expand Down
76 changes: 73 additions & 3 deletions src/ems-esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)

JsonObject rootBoiler = doc.to<JsonObject>();
Expand All @@ -781,6 +782,8 @@ void publishValues(bool force) {

if (EMS_Boiler.wWSelTemp != EMS_VALUE_INT_NOTSET)
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)
rootBoiler["selFlowTemp"] = EMS_Boiler.selFlowTemp;
if (EMS_Boiler.selBurnPow != EMS_VALUE_INT_NOTSET)
Expand All @@ -789,6 +792,8 @@ void publishValues(bool force) {
rootBoiler["curBurnPow"] = EMS_Boiler.curBurnPow;
if (EMS_Boiler.pumpMod != EMS_VALUE_INT_NOTSET)
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)
rootBoiler["outdoorTemp"] = (double)EMS_Boiler.extTemp / 10;
Expand All @@ -813,6 +818,9 @@ void publishValues(bool force) {
if (EMS_Boiler.burnGas != EMS_VALUE_INT_NOTSET)
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)
rootBoiler["heatPmp"] = _bool_to_char(s, EMS_Boiler.heatPmp);

Expand All @@ -825,9 +833,24 @@ void publishValues(bool force) {
if (EMS_Boiler.wWCirc != EMS_VALUE_INT_NOTSET)
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)
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
if (abs(EMS_Boiler.burnStarts) != EMS_VALUE_LONG_NOTSET)
rootBoiler["burnStarts"] = (double)EMS_Boiler.burnStarts;
Expand Down Expand Up @@ -942,8 +965,8 @@ void publishValues(bool force) {
crc.update(data[i]);
}
fchecksum = crc.finalize();
if ((previousThermostatPublishCRC != fchecksum) || force) {
previousThermostatPublishCRC = fchecksum;
if ((previousThermostatPublishCRC[hc_v - 1] != fchecksum) || force) {
previousThermostatPublishCRC[hc_v - 1] = fchecksum;
char thermostat_topicname[20];
char buffer[4];
// "thermostat_data" + Heating Cicruit #
Expand All @@ -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
if (ems_getSolarModuleEnabled()) {
// build new json object
Expand Down
3 changes: 3 additions & 0 deletions src/my_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#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

// MQTT for mixing device
#define TOPIC_MIXING_DATA "mixing_data" // for sending mixing device values to MQTT

// MQTT for SM10/SM100 Solar Module
#define TOPIC_SM_DATA "sm_data" // topic name
#define SM_COLLECTORTEMP "collectortemp" // collector temp
Expand Down

0 comments on commit 460b5fd

Please sign in to comment.