-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYalerWebService2.ino
More file actions
90 lines (64 loc) · 1.84 KB
/
Copy pathYalerWebService2.ino
File metadata and controls
90 lines (64 loc) · 1.84 KB
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
// Copyright (c) 2014, Yaler GmbH, Switzerland
// All rights reserved
#include <SPI.h>
#include <Ethernet.h>
#include <YalerEthernetServer.h>
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
//String dataTemp;
String dataFinal;
//char y;
// Enter a MAC address for your controller below.
// Some Ethernet shields have a MAC address printed on a sticker
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x42, 0x63 };
// Local EthernetServer at http://LOCAL_IP/ (e.g. http://192.168.0.7/)
//EthernetServer server(80);
YalerEthernetServer server("try.yaler.net", 80, "gsiot-sw4f-0884");
void setup() {
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
Serial.println("Aquiring IP address...");
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP failed.");
}
else
{
Serial.println(Ethernet.localIP());
server.begin();
}
}
void loop() {
EthernetClient client = server.available();
// print the string when a newline arrives:
if (stringComplete)
{
Serial.print(inputString);
// clear the string:
dataFinal=inputString;
inputString = "";
stringComplete = false;
}
if (client && client.connected()) {
client.find("\r\n\r\n"); // Consume incoming request
sendResponse(client);
delay(100); // Give the Web browser time to receive the data
client.stop();
}
} // loop end brace
void sendResponse(EthernetClient client) {
client.print(dataFinal);
dataFinal="";
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
if (inChar == byte(0x0a)) {
stringComplete = true;
}
}
}