summaryrefslogtreecommitdiff
path: root/platformio/relayctl/src
diff options
context:
space:
mode:
Diffstat (limited to 'platformio/relayctl/src')
-rw-r--r--platformio/relayctl/src/main.cpp4
-rw-r--r--platformio/relayctl/src/mqtt.cpp28
-rw-r--r--platformio/relayctl/src/mqtt.h16
3 files changed, 24 insertions, 24 deletions
diff --git a/platformio/relayctl/src/main.cpp b/platformio/relayctl/src/main.cpp
index 8c3a0cb..3dab38b 100644
--- a/platformio/relayctl/src/main.cpp
+++ b/platformio/relayctl/src/main.cpp
@@ -140,8 +140,8 @@ void loop() {
if (mqtt->ota.readyToRestart) {
mqtt->disconnect();
- } else if (mqtt->statStopWatch.elapsed(10000)) {
- mqtt->sendStat();
+ } else if (mqtt->diagnosticsStopWatch.elapsed(10000)) {
+ mqtt->sendDiagnostics();
}
#if MQTT_BLINK
diff --git a/platformio/relayctl/src/mqtt.cpp b/platformio/relayctl/src/mqtt.cpp
index e1f70c3..0314c75 100644
--- a/platformio/relayctl/src/mqtt.cpp
+++ b/platformio/relayctl/src/mqtt.cpp
@@ -19,8 +19,8 @@ static const char MQTT_PASSWORD[] = DEFAULT_MQTT_PASSWORD;
static const char MQTT_CLIENT_ID[] = DEFAULT_MQTT_CLIENT_ID;
static const char MQTT_SECRET[HOME_SECRET_SIZE+1] = HOME_SECRET;
-static const char TOPIC_STAT[] = "stat";
-static const char TOPIC_INITIAL_STAT[] = "stat1";
+static const char TOPIC_DIAGNOSTICS[] = "stat";
+static const char TOPIC_INITIAL_DIAGNOSTICS[] = "stat1";
static const char TOPIC_OTA_RESPONSE[] = "otares";
static const char TOPIC_RELAY_POWER[] = "power";
static const char TOPIC_ADMIN_OTA[] = "admin/ota";
@@ -45,7 +45,7 @@ MQTT::MQTT() {
client.onConnect([&](bool sessionPresent) {
PRINTLN("mqtt: connected");
- sendInitialStat();
+ sendInitialDiagnostics();
subscribe(TOPIC_RELAY_POWER, 1);
subscribe(TOPIC_ADMIN_OTA);
@@ -174,36 +174,36 @@ uint16_t MQTT::subscribe(const String &topic, uint8_t qos) {
return packetId;
}
-void MQTT::sendInitialStat() {
+void MQTT::sendInitialDiagnostics() {
auto cfg = config::read();
- InitialStatPayload stat{
+ InitialDiagnosticsPayload stat{
.ip = wifi::getIPAsInteger(),
.fw_version = FW_VERSION,
.rssi = wifi::getRSSI(),
.free_heap = ESP.getFreeHeap(),
- .flags = StatFlags{
+ .flags = DiagnosticsFlags{
.state = static_cast<uint8_t>(relay::getState() ? 1 : 0),
.config_changed_value_present = 1,
.config_changed = static_cast<uint8_t>(cfg.flags.node_configured ||
cfg.flags.wifi_configured ? 1 : 0)
}
};
- publish(TOPIC_INITIAL_STAT, reinterpret_cast<uint8_t*>(&stat), sizeof(stat));
- statStopWatch.save();
+ publish(TOPIC_INITIAL_DIAGNOSTICS, reinterpret_cast<uint8_t*>(&stat), sizeof(stat));
+ diagnosticsStopWatch.save();
}
-void MQTT::sendStat() {
- StatPayload stat{
+void MQTT::sendDiagnostics() {
+ DiagnosticsPayload stat{
.rssi = wifi::getRSSI(),
.free_heap = ESP.getFreeHeap(),
- .flags = StatFlags{
+ .flags = DiagnosticsFlags{
.state = static_cast<uint8_t>(relay::getState() ? 1 : 0),
.config_changed_value_present = 0,
.config_changed = 0
}
};
- publish(TOPIC_STAT, reinterpret_cast<uint8_t*>(&stat), sizeof(stat));
- statStopWatch.save();
+ publish(TOPIC_DIAGNOSTICS, reinterpret_cast<uint8_t*>(&stat), sizeof(stat));
+ diagnosticsStopWatch.save();
}
uint16_t MQTT::sendOtaResponse(OTAResult status, uint8_t error_code) {
@@ -237,7 +237,7 @@ void MQTT::handleRelayPowerPayload(const uint8_t *payload, uint32_t length) {
PRINTLN("error: unexpected state value");
}
- sendStat();
+ sendDiagnostics();
}
void MQTT::handleAdminOtaPayload(uint16_t packetId, const uint8_t *payload, size_t length, size_t index, size_t total) {
diff --git a/platformio/relayctl/src/mqtt.h b/platformio/relayctl/src/mqtt.h
index f5ffdab..2afb2e0 100644
--- a/platformio/relayctl/src/mqtt.h
+++ b/platformio/relayctl/src/mqtt.h
@@ -52,11 +52,11 @@ private:
uint16_t publish(const String& topic, uint8_t* payload, size_t length);
uint16_t subscribe(const String& topic, uint8_t qos = 0);
- void sendInitialStat();
+ void sendInitialDiagnostics();
uint16_t sendOtaResponse(OTAResult status, uint8_t error_code = 0);
public:
- StopWatch statStopWatch;
+ StopWatch diagnosticsStopWatch;
OTAStatus ota;
MQTT();
@@ -64,28 +64,28 @@ public:
void disconnect();
void reconnect();
void loop();
- void sendStat();
+ void sendDiagnostics();
};
-struct StatFlags {
+struct DiagnosticsFlags {
uint8_t state: 1;
uint8_t config_changed_value_present: 1;
uint8_t config_changed: 1;
uint8_t reserved: 5;
} __attribute__((packed));
-struct InitialStatPayload {
+struct InitialDiagnosticsPayload {
uint32_t ip;
uint8_t fw_version;
int8_t rssi;
uint32_t free_heap;
- StatFlags flags;
+ DiagnosticsFlags flags;
} __attribute__((packed));
-struct StatPayload {
+struct DiagnosticsPayload {
int8_t rssi;
uint32_t free_heap;
- StatFlags flags;
+ DiagnosticsFlags flags;
} __attribute__((packed));
struct PowerPayload {