Skip to content

Commit 0ff9d17

Browse files
authored
Merge pull request #1 from RUGSoftEng/feature/BasicCommunication
Lock is now able to receive commands. Light is turned on or off indic…
2 parents 478016c + 09853da commit 0ff9d17

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Arduino Yun/Main.ino

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <Bridge.h>
2+
#include <BridgeServer.h>
3+
#include <BridgeClient.h>
4+
#include <Servo.h>
5+
6+
BridgeServer server;
7+
8+
void setup() {
9+
pinMode(13, OUTPUT);
10+
11+
Serial.begin(9600);
12+
Bridge.begin();
13+
14+
server.listenOnLocalhost();
15+
server.begin();
16+
}
17+
18+
void loop() {
19+
BridgeClient client = server.accept();
20+
if(client){
21+
process(client);
22+
client.stop();
23+
}
24+
delay(50);
25+
}
26+
27+
void process(BridgeClient client){
28+
String command = client.readStringUntil('/');
29+
command = command.substring(0,command.length()-2);
30+
if(command.equals("openlock")){
31+
openLock(client);
32+
}
33+
else if(command.equals("closelock")){
34+
closeLock(client);
35+
}
36+
else {
37+
invalidArgument(client, command);
38+
}
39+
}
40+
41+
void openLock(BridgeClient client){
42+
digitalWrite(13, HIGH);
43+
client.print(F("Lock open"));
44+
}
45+
46+
void closeLock(BridgeClient client){
47+
digitalWrite(13, LOW);
48+
client.print(F("Lock close"));
49+
}
50+
51+
void invalidArgument(BridgeClient client, String command){
52+
client.print(F("Invalid Argument: "));
53+
client.print(command);
54+
}
55+

0 commit comments

Comments
 (0)