mirror of https://github.com/jeelabs/esp-link.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.0 KiB
50 lines
1.0 KiB
9 years ago
|
#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();
|
||
|
}
|
||
|
|