File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments