Skip to content
Permalink
Browse files

API for reading and updating the LED state

  • Loading branch information...
lasselukkari committed Mar 19, 2019
1 parent 1091a2e commit 6ba32f6e119cec62ec84e0a6cb3572010b9fc2cd
Showing with 17 additions and 1 deletion.
  1. +17 −1 BlinkServer/BlinkServer.ino
@@ -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);
@@ -17,6 +31,8 @@ void setup() {
}
Serial.println(WiFi.localIP());

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

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

0 comments on commit 6ba32f6

Please sign in to comment.
You can’t perform that action at this time.