Gbox 4.20
Grow box automation and monitoring - <a href='https://sites.google.com/site/growboxguy/'>https://sites.google.com/site/growboxguy/</a>
 
Loading...
Searching...
No Matches
webserver_led.ino
Go to the documentation of this file.
1
15#include <ELClient.h>
16#include <ELClientWebServer.h>
17
18// flash LED on PIN 13
19#define LED_PIN 13
20
21// Initialize a connection to esp-link using the normal hardware serial port
22//
23// DEBUG is disasbled as
24// - packet logging is slow and UART receive buffer can overrun (HTML form submission)
26
27// Initialize the Web-Server client
29
31{
32 if( digitalRead(LED_PIN) )
33 webServer.setArgString(F("text"), F("LED is on"));
34 else
35 webServer.setArgString(F("text"), F("LED is off"));
36}
37
38void ledButtonPressCb(char * btnId)
39{
40 String id = btnId;
41 if( id == F("btn_on") )
42 digitalWrite(LED_PIN, true);
43 else if( id == F("btn_off") )
44 digitalWrite(LED_PIN, false);
45}
46
47// Callback made form esp-link to notify that it has just come out of a reset. This means we
48// need to initialize it!
49void resetCb(void) {
50 Serial.println("EL-Client (re-)starting!");
51 bool ok = false;
52 do {
53 ok = esp.Sync(); // sync up with esp-link, blocks for up to 2 seconds
54 if (!ok) Serial.println("EL-Client sync failed!");
55 } while(!ok);
56 Serial.println("EL-Client synced!");
57
58 webServer.setup();
59}
60
61void setup()
62{
63 Serial.begin(115200);
64
65 URLHandler *ledHandler = webServer.createURLHandler(F("/SimpleLED.html.json"));
68 ledHandler->buttonCb.attach(&ledButtonPressCb);
69
70 esp.resetCb = resetCb;
71 resetCb();
72}
73
74void loop()
75{
76 esp.Process();
77}
Definitions for ELClientWebServer.
Definitions for ELClient.
void attach(T *item, retT(T::*method)(argT))
Definition FP.h:147
FP< void, char * > loadCb
Callback for HTML page loading.
FP< void, char * > buttonCb
callback for a HTML button press
FP< void, char * > refreshCb
Callback for HTML page refresh.
void ledPageLoadAndRefreshCb(char *url)
void setup()
void ledButtonPressCb(char *btnId)
#define LED_PIN
ELClientWebServer webServer & esp
ELClient esp & Serial
void resetCb(void)
void loop()