From 53d7890a85abeb73d593f1097d577bc3ac55d427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Thu, 23 Mar 2017 23:16:21 +0100 Subject: [PATCH] Allow changing color via REST request --- code/espurna/light.ino | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 110713d6..9d31a24e 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -158,6 +158,24 @@ void lightMQTTCallback(unsigned int type, const char * topic, const char * paylo } +//------------------------------------------------------------------------------ +// REST API +//------------------------------------------------------------------------------ + +void lightSetupAPI() { + + // API entry points (protected with apikey) + apiRegister("/api/color", "color", + [](char * buffer, size_t len) { + snprintf(buffer, len, "%s", lightColor().c_str()); + }, + [](const char * payload) { + lightColor(payload, true, mqttForward()); + } + ); + +} + // ----------------------------------------------------------------------------- // SETUP // ----------------------------------------------------------------------------- @@ -181,6 +199,7 @@ void lightSetup() { lightColorRetrieve(); mqttRegister(lightMQTTCallback); + lightSetupAPI(); }