-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComEthernetHTTP.cpp
More file actions
91 lines (77 loc) · 2.05 KB
/
ComEthernetHTTP.cpp
File metadata and controls
91 lines (77 loc) · 2.05 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
91
/*
http://www.ardumote.com
Copyright (c) 2012 Suat Özgür
http://opensource.org/licenses/MIT
*/
#include "ComEthernetHTTP.h"
EthernetServer xserver(80);
ComEthernetHTTP::ComEthernetHTTP() {
}
void ComEthernetHTTP::setup(byte mac[6], byte ip[4], byte remoteIp[4]) {
Ethernet.begin(mac, ip);
serverIP[0] = remoteIp[0];
serverIP[1] = remoteIp[1];
serverIP[2] = remoteIp[2];
serverIP[3] = remoteIp[3];
}
bool ComEthernetHTTP::available() {
EthernetClient client = xserver.available();
if (client) {
int nCommandPos=-1;
sReturnCommand[0] = '\0';
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/plain");
client.println();
client.println("ok");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
if (nCommandPos>-1) {
sReturnCommand[nCommandPos++] = c;
}
if (c == '?' && nCommandPos == -1) {
nCommandPos = 0;
}
}
}
if (nCommandPos!=-1) {
sReturnCommand[nCommandPos] = '\0';
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}
char* ComEthernetHTTP::read() {
return "aaa";
}
bool ComEthernetHTTP::send(char* sCommand) {
EthernetClient client;
if (client.connect(serverIP, 80)) {
client.print("GET /input.php?d=");
client.print( sCommand );
client.println(" HTTP/1.0");
client.println("Host: ardumote.com");
client.println("Connection: close");
client.println();
while (client.connected()) {
if (client.available()) {
char c = client.read();
}
}
client.stop();
return true;
} else {
return false;
}
}