Skip to content

Commit

Permalink
API for reading and updating the LED state
Browse files Browse the repository at this point in the history
  • Loading branch information
lasselukkari committed Mar 19, 2019
1 parent 1091a2e commit 6ba32f6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion BlinkServer/BlinkServer.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#include <WiFi.h>
#include "aWOT.h"
#define LED_BUILTIN 2

#define WIFI_SSID "network"
#define WIFI_PASSWORD "password"

WiFiServer server(80);
Application app;

bool ledOn;

void readLed(Request &req, Response &res) {
res.print(ledOn);
}

void updateLed(Request &req, Response &res) {
ledOn = (req.read() != '0');
digitalWrite(LED_BUILTIN, ledOn);
return readLed(req, res);
}

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Expand All @@ -17,6 +31,8 @@ void setup() {
}
Serial.println(WiFi.localIP());

app.get("/led", &readLed);
app.put("/led", &updateLed);
app.route(staticFiles());

server.begin();
Expand All @@ -28,4 +44,4 @@ void loop() {
if (client.connected()) {
app.process(&client);
}
}
}

0 comments on commit 6ba32f6

Please sign in to comment.