Created
February 20, 2016 11:54
-
-
Save darkwave/ccdded8f486d106d854b to your computer and use it in GitHub Desktop.
DOMUSino Example of bridge with Arduino YUN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Bridge.h> | |
#include <BridgeServer.h> | |
#include <BridgeClient.h> | |
// Listen to the default port 5555, the Yún webserver | |
// will forward there all the HTTP requests you send | |
boolean rooms[14]; | |
BridgeServer server; | |
void setup() { | |
for (int i = 0; i <= 13; i++) | |
pinMode(i, OUTPUT); | |
Bridge.begin(); | |
server.listenOnLocalhost(); | |
server.begin(); | |
} | |
void loop() { | |
for (int i = 0; i <= 13; i++) { | |
if (rooms[i]) { | |
digitalWrite(i, HIGH); | |
} else { | |
digitalWrite(i, LOW); | |
} | |
} | |
// Get clients coming from server | |
BridgeClient client = server.accept(); | |
// There is a new client? | |
if (client) { | |
// Process request | |
lights(client); | |
// Close connection and free resources. | |
client.stop(); | |
} | |
delay(50); // Poll every 50ms | |
} | |
void lights(BridgeClient client) { | |
String command = client.readStringUntil('/'); | |
command.trim(); | |
if (command == "room") { | |
int pin = client.parseInt(); | |
rooms[pin] = !rooms[pin]; | |
} | |
for (int i = 0; i <= 13; i++) { | |
client.print(rooms[i]); | |
client.print(","); | |
} | |
client.println(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment