-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ino
82 lines (66 loc) · 1.75 KB
/
test.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
int LEDPIN = 13; // your LED PIN
YunServer server;
void setup() {
// Start our connection
Serial.begin(9600);
pinMode(LEDPIN,OUTPUT);
digitalWrite(LEDPIN,HIGH); // turn on Led while connecting
Bridge.begin();
// Show a fancy flash pattern once connected
digitalWrite(LEDPIN,LOW);
delay(150);
digitalWrite(LEDPIN,HIGH);
delay(150);
digitalWrite(LEDPIN,LOW);
delay(150);
digitalWrite(LEDPIN,HIGH);
delay(150);
digitalWrite(LEDPIN,LOW);
delay(150);
// Disable for some connections:
// Start listening for connections
// server.listenOnLocalhost();
server.begin();
}
void loop() {
// Listen for clients
YunClient client = server.accept();
// Client exists?
if (client) {
// Lets process the request!
process(client);
client.stop();
}
delay(50);
}
void process(YunClient client) {
// Collect user commands
String command = client.readStringUntil('\\'); // load whole string
command.trim();
// Enable HTML
client.println("Status: 200");
client.println("Content-type: text/html");
client.println();
// Show UI
client.println("<B><Center>");
client.println("<a href='http://arduinoania.local/arduino/on\\'>Turn ON LED</a><br>");
client.println("<a href='http://arduinoania.local/arduino/off\\'>Turn OFF LED</a><br>");
client.print("Command: ");
client.println(command);
client.println("</B></Center>");
// Check what the user entered ...
// Turn on
if (command == "on") {
digitalWrite(13,HIGH);
delay(1000);
}
// Turn off
if (command == "off")
{
digitalWrite(13,LOW);
delay(1000);
}
}