Skip to content

Commit

Permalink
don't publish dallas if there are none
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Apr 21, 2021
1 parent a633225 commit 8ea48f7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/dallassensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class DallasSensor {
return sensorfails_;
}

bool dallas_enabled() {
return (dallas_gpio_ != 0);
}

private:
static constexpr uint8_t MAX_SENSORS = 20;

Expand Down
4 changes: 4 additions & 0 deletions src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ void EMSESP::publish_other_values() {
}

void EMSESP::publish_sensor_values(const bool time, const bool force) {
if (!dallas_enabled()) {
return;
}

if (dallassensor_.updated_values() || time || force) {
dallassensor_.publish_values(force);
}
Expand Down
4 changes: 4 additions & 0 deletions src/emsesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ class EMSESP {
return dallassensor_.fails();
}

static bool dallas_enabled() {
return (dallassensor_.dallas_enabled());
}

enum Watch : uint8_t { WATCH_OFF, WATCH_ON, WATCH_RAW, WATCH_UNKNOWN };
static void watch_id(uint16_t id);
static uint16_t watch_id() {
Expand Down
33 changes: 21 additions & 12 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,20 @@ void System::send_heartbeat() {
if (!ethernet_connected_) {
doc["rssi"] = rssi;
}
doc["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
doc["uptime_sec"] = uuid::get_uptime_sec();
doc["mqttfails"] = Mqtt::publish_fails();
doc["rxreceived"] = EMSESP::rxservice_.telegram_count();
doc["rxfails"] = EMSESP::rxservice_.telegram_error_count();
doc["txread"] = EMSESP::txservice_.telegram_read_count();
doc["txwrite"] = EMSESP::txservice_.telegram_write_count();
doc["txfails"] = EMSESP::txservice_.telegram_fail_count();
doc["dallasfails"] = EMSESP::sensor_fails();
doc["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
doc["uptime_sec"] = uuid::get_uptime_sec();

doc["rxreceived"] = EMSESP::rxservice_.telegram_count();
doc["rxfails"] = EMSESP::rxservice_.telegram_error_count();
doc["txread"] = EMSESP::txservice_.telegram_read_count();
doc["txwrite"] = EMSESP::txservice_.telegram_write_count();
doc["txfails"] = EMSESP::txservice_.telegram_fail_count();
if (Mqtt::enabled()) {
doc["mqttfails"] = Mqtt::publish_fails();
}
if (EMSESP::dallas_enabled()) {
doc["dallasfails"] = EMSESP::sensor_fails();
}
#ifndef EMSESP_STANDALONE
doc["freemem"] = ESP.getFreeHeap();
#endif
Expand Down Expand Up @@ -878,9 +883,13 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & json
node["#tx fails"] = EMSESP::txservice_.telegram_fail_count();
node["rx line quality"] = EMSESP::rxservice_.quality();
node["tx line quality"] = EMSESP::txservice_.quality();
node["#MQTT publish fails"] = Mqtt::publish_fails();
node["#dallas sensors"] = EMSESP::sensor_devices().size();
node["#dallas fails"] = EMSESP::sensor_fails();
if (Mqtt::enabled()) {
node["#MQTT publish fails"] = Mqtt::publish_fails();
}
if (EMSESP::dallas_enabled()) {
node["#dallas sensors"] = EMSESP::sensor_devices().size();
node["#dallas fails"] = EMSESP::sensor_fails();
}
}

JsonArray devices2 = json.createNestedArray("Devices");
Expand Down

0 comments on commit 8ea48f7

Please sign in to comment.