mirror of https://github.com/jeelabs/esp-link.git
parent
31a21a9905
commit
ceea292802
@ -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(); |
||||
} |
||||
|
@ -0,0 +1,7 @@ |
||||
<!-- EspLink will add header here --> |
||||
|
||||
<h1 class="header">Simple LED control</h1> |
||||
<h2><div id="text"/></h2> |
||||
<button id="btn_on" type="button">Turn on</button> |
||||
<button id="btn_off" type="button">Turn off</button> |
||||
</body></html> |
Loading…
Reference in new issue