-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.ino
90 lines (78 loc) · 3.18 KB
/
start.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
83
84
85
86
87
88
89
90
#include <SPI.h>
#include <Ethernet.h>
// Your Arduino Ethernet's MAC address.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Your Arduino Ethernet's IP address (192.168.1.177). This is the URL that you type into the browser URL bar.
IPAddress ip(192,168,1,177);
// Tell your Ethernet server to listen on port 80 (the standard port for HTTP requests)
EthernetServer server(80);
void setup() {
Serial.begin(9600);
// Wait until serial is loaded.
while (!Serial) { }
// start the Ethernet connection and the server.
Ethernet.begin(mac, ip);
server.begin();
Serial.print("Server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
// If there is an incoming client
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
// While the client is connected and waiting for data
while (client.connected()) {
// Check for HTTP timeout
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// The standard HTTP response header for a successful request.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 5");
client.println();
client.println("<!DOCTYPE HTML>");
// ************************************************
// ************************************************
// BELOW IS WHERE YOU PRINT OUT YOUR HTML PAGE. ***
// ************************************************
// ************************************************
client.println("<html>");
client.println("<head>");
client.println("<title>Arduino Ethernet</title>");
client.println("<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script>");
client.println("<link href=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css\" rel=\"stylesheet\">");
client.println("<script src=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js\"></script>");
client.println("</head>");
client.println("<body>");
// Add your visible components here.
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}