diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-09-27 00:54:57 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-09-27 00:54:57 +0300 |
commit | d3a295872c49defb55fc8e4e43e55550991e0927 (patch) | |
tree | b9dca15454f9027d5a9dad0d4443a20de04dbc5d /platformio/common/libs/mqtt_module_relay | |
parent | b7cbc2571c1870b4582ead45277d0aa7f961bec8 (diff) | |
parent | bdbb296697f55f4c3a07af43c9aaf7a9ea86f3d0 (diff) |
Merge branch 'master' of ch1p.io:homekit
Diffstat (limited to 'platformio/common/libs/mqtt_module_relay')
3 files changed, 0 insertions, 77 deletions
diff --git a/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.cpp b/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.cpp deleted file mode 100644 index ab40727..0000000 --- a/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "./relay.h" -#include <homekit/relay.h> -#include <homekit/logging.h> - -namespace homekit::mqtt { - -static const char TOPIC_RELAY_SWITCH[] = "relay/switch"; - -void MqttRelayModule::init(Mqtt &mqtt) { - String topic(TOPIC_RELAY_SWITCH); - mqtt.subscribeModule(topic, this, 1); -} - -void MqttRelayModule::tick(homekit::mqtt::Mqtt& mqtt) {} - -void MqttRelayModule::handlePayload(Mqtt& mqtt, String& topic, uint16_t packetId, const uint8_t *payload, size_t length, size_t index, size_t total) { - if (topic != TOPIC_RELAY_SWITCH) - return; - - if (length != sizeof(MqttRelaySwitchPayload)) { - PRINTF("error: size of payload (%ul) does not match expected (%ul)\n", - length, sizeof(MqttRelaySwitchPayload)); - return; - } - - auto pd = reinterpret_cast<const struct MqttRelaySwitchPayload*>(payload); - if (strncmp(pd->secret, MQTT_SECRET, sizeof(pd->secret)) != 0) { - PRINTLN("error: invalid secret"); - return; - } - - if (pd->state == 1) { - PRINTLN("mqtt: turning relay on"); - relay::on(); - } else if (pd->state == 0) { - PRINTLN("mqtt: turning relay off"); - relay::off(); - } else { - PRINTLN("error: unexpected state value"); - } -} - -} diff --git a/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h b/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h deleted file mode 100644 index 6420de1..0000000 --- a/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef HOMEKIT_LIB_MQTT_MODULE_RELAY_H -#define HOMEKIT_LIB_MQTT_MODULE_RELAY_H - -#include <homekit/mqtt/module.h> - -namespace homekit::mqtt { - -struct MqttRelaySwitchPayload { - char secret[12]; - uint8_t state; -} __attribute__((packed)); - -class MqttRelayModule : public MqttModule { -public: - MqttRelayModule() : MqttModule(0) {} - void init(Mqtt& mqtt) override; - void tick(Mqtt& mqtt) override; - void handlePayload(Mqtt& mqtt, String& topic, uint16_t packetId, const uint8_t *payload, size_t length, size_t index, size_t total) override; -}; - -} - -#endif //HOMEKIT_LIB_MQTT_MODULE_RELAY_H diff --git a/platformio/common/libs/mqtt_module_relay/library.json b/platformio/common/libs/mqtt_module_relay/library.json deleted file mode 100644 index e71cf95..0000000 --- a/platformio/common/libs/mqtt_module_relay/library.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "homekit_mqtt_module_relay", - "version": "1.0.3", - "build": { - "flags": "-I../../include" - }, - "dependencies": { - "homekit_mqtt": "file://../common/libs/mqtt", - "homekit_relay": "file://../common/libs/relay" - } -} |