Skip to content

Commit

Permalink
Feature: Allow reset of radio statistics via mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Sep 23, 2024
1 parent 0c012bf commit 181802a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/MqttHandleInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ class MqttHandleInverterClass {
LimitNonPersistentAbsolute,
Power,
Restart,
ResetRfStats,
};

static constexpr frozen::string _cmdtopic = "+/cmd/";
static constexpr frozen::map<frozen::string, Topic, 6> _subscriptions = {
static constexpr frozen::map<frozen::string, Topic, 7> _subscriptions = {
{ "limit_persistent_relative", Topic::LimitPersistentRelative },
{ "limit_persistent_absolute", Topic::LimitPersistentAbsolute },
{ "limit_nonpersistent_relative", Topic::LimitNonPersistentRelative },
{ "limit_nonpersistent_absolute", Topic::LimitNonPersistentAbsolute },
{ "power", Topic::Power },
{ "restart", Topic::Restart },
{ "reset_rf_stats", Topic::ResetRfStats },
};

void onMqttMessage(Topic t, const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, const size_t len, const size_t index, const size_t total);
Expand Down
1 change: 1 addition & 0 deletions src/MqttHandleHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void MqttHandleHassClass::publishConfig()
publishInverterButton(inv, "Turn Inverter Off", "mdi:power-plug-off", "config", "", "cmd/power", "0");
publishInverterButton(inv, "Turn Inverter On", "mdi:power-plug", "config", "", "cmd/power", "1");
publishInverterButton(inv, "Restart Inverter", "", "config", "restart", "cmd/restart", "1");
publishInverterButton(inv, "Reset Radio Statistics", "", "config", "", "cmd/reset_rf_stats", "1");

publishInverterNumber(inv, "Limit NonPersistent Relative", "mdi:speedometer", "config", "cmd/limit_nonpersistent_relative", "status/limit_relative", "%", 0, 100, 0.1);
publishInverterNumber(inv, "Limit Persistent Relative", "mdi:speedometer", "config", "cmd/limit_persistent_relative", "status/limit_relative", "%", 0, 100, 0.1);
Expand Down
10 changes: 10 additions & 0 deletions src/MqttHandleInverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ void MqttHandleInverterClass::onMqttMessage(Topic t, const espMqttClientTypes::M
} else {
MessageOutput.println("Ignored because retained or numeric value not '1'");
}
break;

case Topic::ResetRfStats:
// Reset RF Stats
MessageOutput.printf("Reset RF stats\r\n");
if (!properties.retain && payload_val == 1) {
inv->resetRadioStats();
} else {
MessageOutput.println("Ignored because retained or numeric value not '1'");
}
}
}

Expand Down

0 comments on commit 181802a

Please sign in to comment.