Skip to content

Instantly share code, notes, and snippets.

@darkwave
Created February 20, 2016 11:54
Show Gist options
  • Save darkwave/ccdded8f486d106d854b to your computer and use it in GitHub Desktop.
Save darkwave/ccdded8f486d106d854b to your computer and use it in GitHub Desktop.
DOMUSino Example of bridge with Arduino YUN
#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