From 96693cba649b792c2a215948a8514c8938213abb Mon Sep 17 00:00:00 2001 From: Ronald Schaten Date: Thu, 31 Mar 2016 21:08:43 +0200 Subject: [PATCH] handler for switching LED on or off --- things.ino | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/things.ino b/things.ino index b00b8a9..c53e485 100644 --- a/things.ino +++ b/things.ino @@ -50,6 +50,25 @@ void setupHandler() { #endif } +bool ledOnHandler(String value) { + if (value == "true") { + analogWrite(PIN_LED_RED, led_red); + analogWrite(PIN_LED_GREEN, led_green); + analogWrite(PIN_LED_BLUE, led_blue); + Homie.setNodeProperty(ledNode, "on", "true"); + Serial.println("led is on"); + } else if (value == "false") { + analogWrite(PIN_LED_RED, 0); + analogWrite(PIN_LED_GREEN, 0); + analogWrite(PIN_LED_BLUE, 0); + Homie.setNodeProperty(ledNode, "on", "false"); + Serial.println("led is off"); + } else { + return false; + } + return true; +} + bool ledColorHandler(String message) { DynamicJsonBuffer json_inBuffer; JsonObject& json_in = json_inBuffer.parseObject(message); @@ -170,6 +189,7 @@ void setup() { Homie.registerNode(ldrNode); #endif #ifdef HAS_LED + ledNode.subscribe("on", ledOnHandler); ledNode.subscribe("color", ledColorHandler); Homie.registerNode(ledNode); #endif