merge dallas from #494, add mqtt response for raw telegrams, add read to root, watch-command flexible

This commit is contained in:
MichaelDvP
2020-09-12 17:52:41 +02:00
parent 2580049b48
commit 5b772985bb
6 changed files with 73 additions and 42 deletions

View File

@@ -316,6 +316,25 @@ void EMSESP::publish_sensor_values(const bool force) {
}
}
void EMSESP::publish_response(std::shared_ptr<const Telegram> telegram) {
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc;
char buffer[100];
doc["src"] = Helpers::hextoa(buffer, telegram->src);
doc["dest"] = Helpers::hextoa(buffer, telegram->dest);
doc["type"] = Helpers::hextoa(buffer, telegram->type_id);
doc["offset"] = Helpers::hextoa(buffer, telegram->offset);
strcpy(buffer, Helpers::data_to_hex(telegram->message_data, telegram->message_length).c_str());
doc["data"] = buffer;
if (telegram->message_length <= 4) {
uint32_t value = 0;
for (uint8_t i = 0; i < telegram->message_length; i++) {
value = (value << 8) + telegram->message_data[i];
}
doc["value"] = value;
}
Mqtt::publish("response", doc);
}
// search for recognized device_ids : Me, All, otherwise print hex value
std::string EMSESP::device_tostring(const uint8_t device_id) {
if ((device_id & 0x7F) == rxservice_.ems_bus_id()) {
@@ -484,6 +503,7 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
// if watching...
if (telegram->type_id == read_id_) {
LOG_NOTICE(pretty_telegram(telegram).c_str());
publish_response(telegram);
read_id_ = WATCH_ID_NONE;
} else if (watch() == WATCH_ON) {
if ((watch_id_ == WATCH_ID_NONE) || (telegram->type_id == watch_id_)