summaryrefslogtreecommitdiff
path: root/include/pio/libs/mqtt_module_temphum
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-09-27 00:54:57 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-09-27 00:54:57 +0300
commitd3a295872c49defb55fc8e4e43e55550991e0927 (patch)
treeb9dca15454f9027d5a9dad0d4443a20de04dbc5d /include/pio/libs/mqtt_module_temphum
parentb7cbc2571c1870b4582ead45277d0aa7f961bec8 (diff)
parentbdbb296697f55f4c3a07af43c9aaf7a9ea86f3d0 (diff)
Merge branch 'master' of ch1p.io:homekit
Diffstat (limited to 'include/pio/libs/mqtt_module_temphum')
-rw-r--r--include/pio/libs/mqtt_module_temphum/homekit/mqtt/module/temphum.cpp23
-rw-r--r--include/pio/libs/mqtt_module_temphum/homekit/mqtt/module/temphum.h28
-rw-r--r--include/pio/libs/mqtt_module_temphum/library.json11
3 files changed, 62 insertions, 0 deletions
diff --git a/include/pio/libs/mqtt_module_temphum/homekit/mqtt/module/temphum.cpp b/include/pio/libs/mqtt_module_temphum/homekit/mqtt/module/temphum.cpp
new file mode 100644
index 0000000..409f38f
--- /dev/null
+++ b/include/pio/libs/mqtt_module_temphum/homekit/mqtt/module/temphum.cpp
@@ -0,0 +1,23 @@
+#include "temphum.h"
+
+namespace homekit::mqtt {
+
+static const char TOPIC_TEMPHUM_DATA[] = "temphum/data";
+
+void MqttTemphumModule::onConnect(Mqtt &mqtt) {}
+
+void MqttTemphumModule::tick(homekit::mqtt::Mqtt& mqtt) {
+ if (!tickElapsed())
+ return;
+
+ temphum::SensorData sd = sensor->read();
+ MqttTemphumPayload payload {
+ .temp = sd.temp,
+ .rh = sd.rh,
+ .error = sd.error
+ };
+
+ mqtt.publish(TOPIC_TEMPHUM_DATA, reinterpret_cast<uint8_t*>(&payload), sizeof(payload));
+}
+
+}
diff --git a/include/pio/libs/mqtt_module_temphum/homekit/mqtt/module/temphum.h b/include/pio/libs/mqtt_module_temphum/homekit/mqtt/module/temphum.h
new file mode 100644
index 0000000..7b28afc
--- /dev/null
+++ b/include/pio/libs/mqtt_module_temphum/homekit/mqtt/module/temphum.h
@@ -0,0 +1,28 @@
+#ifndef HOMEKIT_LIB_MQTT_MODULE_TEMPHUM_H
+#define HOMEKIT_LIB_MQTT_MODULE_TEMPHUM_H
+
+#include <homekit/mqtt/module.h>
+#include <homekit/temphum.h>
+
+namespace homekit::mqtt {
+
+struct MqttTemphumPayload {
+ double temp = 0;
+ double rh = 0;
+ uint8_t error = 0;
+} __attribute__((packed));
+
+
+class MqttTemphumModule : public MqttModule {
+private:
+ temphum::Sensor* sensor;
+
+public:
+ MqttTemphumModule(temphum::Sensor* _sensor) : MqttModule(10), sensor(_sensor) {}
+ void onConnect(Mqtt& mqtt) override;
+ void tick(Mqtt& mqtt) override;
+};
+
+}
+
+#endif //HOMEKIT_LIB_MQTT_MODULE_TEMPHUM_H
diff --git a/include/pio/libs/mqtt_module_temphum/library.json b/include/pio/libs/mqtt_module_temphum/library.json
new file mode 100644
index 0000000..c7ee7af
--- /dev/null
+++ b/include/pio/libs/mqtt_module_temphum/library.json
@@ -0,0 +1,11 @@
+{
+ "name": "homekit_mqtt_module_temphum",
+ "version": "1.0.10",
+ "build": {
+ "flags": "-I../../include"
+ },
+ "dependencies": {
+ "homekit_mqtt": "file://../../include/pio/libs/mqtt",
+ "homekit_temphum": "file://../../include/pio/libs/temphum"
+ }
+}