diff options
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" - } -} |