testing MQTT hc

This commit is contained in:
proddy
2020-09-02 23:16:20 +02:00
parent e1df59911f
commit 66d105f99f
4 changed files with 141 additions and 125 deletions

View File

@@ -24,7 +24,7 @@ class DummySettings {
bool shower_alert = false; bool shower_alert = false;
bool hide_led = false; bool hide_led = false;
uint16_t publish_time = 10; // seconds uint16_t publish_time = 10; // seconds
uint8_t mqtt_format = 1; // 1=single, 2=nested, 3=ha, 4=custom uint8_t mqtt_format = 3; // 1=single, 2=nested, 3=ha, 4=custom
uint8_t mqtt_qos = 0; uint8_t mqtt_qos = 0;
String hostname = "ems-esp"; String hostname = "ems-esp";
String jwtSecret = "ems-esp"; String jwtSecret = "ems-esp";

View File

@@ -270,7 +270,6 @@ void Thermostat::publish_values() {
} }
uint8_t flags = this->model(); uint8_t flags = this->model();
bool has_data = false;
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc; StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc;
JsonObject rootThermostat = doc.to<JsonObject>(); JsonObject rootThermostat = doc.to<JsonObject>();
@@ -324,12 +323,11 @@ void Thermostat::publish_values() {
} }
// go through all the heating circuits // go through all the heating circuits
bool has_data = false;
for (const auto & hc : heating_circuits_) { for (const auto & hc : heating_circuits_) {
if (!Helpers::hasValue(hc->setpoint_roomTemp)) { if (hc->is_active()) {
break; // skip this HC
}
has_data = true; has_data = true;
// if the MQTT format is 'nested' or 'ha' then create the parent object hc<n> // if the MQTT format is 'nested' or 'ha' then create the parent object hc<n>
// if (mqtt_format_ != MQTT_format::SINGLE) { // if (mqtt_format_ != MQTT_format::SINGLE) {
if ((mqtt_format_ == MQTT_format::NESTED) || (mqtt_format_ == MQTT_format::HA)) { if ((mqtt_format_ == MQTT_format::NESTED) || (mqtt_format_ == MQTT_format::HA)) {
@@ -445,6 +443,7 @@ void Thermostat::publish_values() {
// see if we have already registered this with HA MQTT Discovery, if not send the config // see if we have already registered this with HA MQTT Discovery, if not send the config
if (!hc->ha_registered()) { if (!hc->ha_registered()) {
register_mqtt_ha_config(hc->hc_num()); register_mqtt_ha_config(hc->hc_num());
hc->ha_registered(true);
} }
// send the thermostat topic and payload data // send the thermostat topic and payload data
std::string topic(100, '\0'); std::string topic(100, '\0');
@@ -452,13 +451,13 @@ void Thermostat::publish_values() {
Mqtt::publish(topic, doc); Mqtt::publish(topic, doc);
} }
} }
}
if (!has_data) { if (!has_data) {
return; // nothing to send, quit return; // nothing to send, quit
} }
// if we're using nested json, send all in one go under one topic called thermostat_data // if we're using nested json, send all in one go under one topic called thermostat_data
// if ((mqtt_format_ == MQTT_format::NESTED) || (mqtt_format_ == MQTT_format::CUSTOM)) {
if (mqtt_format_ == MQTT_format::NESTED) { if (mqtt_format_ == MQTT_format::NESTED) {
Mqtt::publish("thermostat_data", doc); Mqtt::publish("thermostat_data", doc);
} }
@@ -824,9 +823,10 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
} }
for (const auto & hc : heating_circuits_) { for (const auto & hc : heating_circuits_) {
if (!Helpers::hasValue(hc->setpoint_roomTemp)) { if (!hc->is_active()) {
break; // skip this HC break; // skip this HC
} }
shell.printfln(F(" Heating Circuit %d:"), hc->hc_num()); shell.printfln(F(" Heating Circuit %d:"), hc->hc_num());
// different thermostat types store their temperature values differently // different thermostat types store their temperature values differently

View File

@@ -70,6 +70,15 @@ class Thermostat : public EMSdevice {
return ha_registered_; return ha_registered_;
} }
void ha_registered(bool b) {
ha_registered_ = b;
}
// determines if the heating circuit is actually present and has data
bool is_active() {
return Helpers::hasValue(setpoint_roomTemp);
}
uint8_t get_mode(uint8_t flags) const; uint8_t get_mode(uint8_t flags) const;
uint8_t get_mode_type(uint8_t flags) const; uint8_t get_mode_type(uint8_t flags) const;
@@ -275,7 +284,7 @@ class Thermostat : public EMSdevice {
void set_display(const char * value, const int8_t id); void set_display(const char * value, const int8_t id);
void set_building(const char * value, const int8_t id); void set_building(const char * value, const int8_t id);
void set_language(const char * value, const int8_t id); void set_language(const char * value, const int8_t id);
}; }; // namespace emsesp
} // namespace emsesp } // namespace emsesp

View File

@@ -28,7 +28,7 @@ namespace emsesp {
// used with the 'test' command, under su/admin // used with the 'test' command, under su/admin
void Test::run_test(uuid::console::Shell & shell, const std::string & command) { void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
if (command == "default") { if (command == "default") {
run_test(shell, "mqtt"); // add the default test case here run_test(shell, "thermostat"); // add the default test case here
} }
if (command.empty()) { if (command.empty()) {
@@ -223,11 +223,18 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
// EMSESP::add_device(0x08, 123, version, EMSdevice::Brand::BUDERUS); // Nefit Trendline // EMSESP::add_device(0x08, 123, version, EMSdevice::Brand::BUDERUS); // Nefit Trendline
// add a thermostat // add a thermostat
EMSESP::add_device(0x18, 157, version, EMSdevice::Brand::BOSCH); // Bosch CR100 - https://github.com/proddy/EMS-ESP/issues/355 EMSESP::add_device(0x10, 192, version, EMSdevice::Brand::JUNKERS); // FW120
// RCPLUSStatusMessage_HC1(0x01A5) // HC1
uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, uart_telegram({0x90, 0x00, 0xFF, 0x00, 0x00, 0x6F, 0x00, 0xCF, 0x21, 0x2E, 0x20, 0x00, 0x2E, 0x24,
0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03});
// HC2
uart_telegram({0x90, 0x00, 0xFF, 0x00, 0x00, 0x70, 0x00, 0xCF, 0x22, 0x2F, 0x10, 0x00, 0x2E, 0x24,
0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03});
// HC3
uart_telegram({0x90, 0x00, 0xFF, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});
} }
if (command == "tc100") { if (command == "tc100") {
@@ -393,7 +400,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03});
uart_telegram("98 00 FF 00 01 A5 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03"); // without CRC uart_telegram("98 00 FF 00 01 A5 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03"); // without CRC
uart_telegram_withCRC("98 00 FF 00 01 A5 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03 13"); // with CRC uart_telegram_withCRC("98 00 FF 00 01 A6 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03 6B"); // with CRC
EMSESP::txservice_.flush_tx_queue(); EMSESP::txservice_.flush_tx_queue();
shell.loop_all(); shell.loop_all();