From 36672200b59883cb2dd92b8c05f5a2fdd811f6b1 Mon Sep 17 00:00:00 2001 From: Karai Csaba Date: Sat, 21 May 2016 07:22:54 +0200 Subject: [PATCH] Simple LED control sample --- .../EspLinkWebSimpleLedControl.ino | 49 +++++++++++++++++++ .../EspLinkWebSimpleLedControl/SimpleLED.html | 7 +++ 2 files changed, 56 insertions(+) create mode 100644 examples/arduino/libraries/EspLink/examples/EspLinkWebSimpleLedControl/EspLinkWebSimpleLedControl.ino create mode 100644 examples/arduino/libraries/EspLink/examples/EspLinkWebSimpleLedControl/SimpleLED.html diff --git a/examples/arduino/libraries/EspLink/examples/EspLinkWebSimpleLedControl/EspLinkWebSimpleLedControl.ino b/examples/arduino/libraries/EspLink/examples/EspLinkWebSimpleLedControl/EspLinkWebSimpleLedControl.ino new file mode 100644 index 0000000..516a2ae --- /dev/null +++ b/examples/arduino/libraries/EspLink/examples/EspLinkWebSimpleLedControl/EspLinkWebSimpleLedControl.ino @@ -0,0 +1,49 @@ +#include "EspLink.h" +#include "WebServer.h" + +#define LED_PIN 13 + +void simpleLedHtmlCallback(WebServerCommand command, char * data, int dataLen); +const char simpleLedURL[] PROGMEM = "/SimpleLED.html.json"; + +const WebMethod PROGMEM methods[] = { + { simpleLedURL, simpleLedHtmlCallback }, + { NULL, NULL }, +}; + +WebServer webServer(Serial, methods); + +void simpleLedHtmlCallback(WebServerCommand command, char * data, int dataLen) +{ + switch(command) + { + case BUTTON_PRESS: + if( strcmp_P(data, PSTR("btn_on") ) == 0 ) + digitalWrite(LED_PIN, true); + else if( strcmp_P(data, PSTR("btn_off") ) == 0 ) + digitalWrite(LED_PIN, false); + break; + case SET_FIELD: + // no fields to set + break; + case LOAD: + case REFRESH: + if( digitalRead(LED_PIN) ) + webServer.setArgString("text", "LED is on"); + else + webServer.setArgString("text", "LED is off"); + break; + } +} + +void setup() +{ + Serial.begin(57600); + webServer.init(); +} + +void loop() +{ + webServer.loop(); +} + diff --git a/examples/arduino/libraries/EspLink/examples/EspLinkWebSimpleLedControl/SimpleLED.html b/examples/arduino/libraries/EspLink/examples/EspLinkWebSimpleLedControl/SimpleLED.html new file mode 100644 index 0000000..27dc359 --- /dev/null +++ b/examples/arduino/libraries/EspLink/examples/EspLinkWebSimpleLedControl/SimpleLED.html @@ -0,0 +1,7 @@ + + +

Simple LED control

+

+ + +