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 @@ + + +