-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaircondition.ino
67 lines (62 loc) · 1.93 KB
/
aircondition.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
#include <Arduino.h>
#include <Ethernet.h>
#include <SPI.h>
#include <Streaming.h>
byte mac[ ] = { 0X00, 0XAA, 0XBB, 0XCC, 0XDE, 0X01};
IPAddress ip(192, 168, 0, 102); // arduino ip a/d
IPAddress server(192, 168, 0, 101); // localhost a/d, 127.0.0.1 is loopback a/d
EthernetClient client; // arduino as client
boolean requested = false;
int led = 8 ;
void connectServer() {
if (!client.connected()) {
if (client.connect(server, 80)) {
Serial << "connected"<< endl;
requested = false;
}
else {
Serial << "cant connect"<< endl;
}
}
}
boolean makeRequest() {
client << "GET /myscript.php HTTP/1.1\n"; // file in local server
client << "HOST:192.168.0.101\n\n"; // server a/d
// saying i need to request myscript.php file on server 192.168.0.101
client << endl; // sending linefeed
return true; // requested = true
}
void setup() {
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(2000);
connectServer();
pinMode(led, OUTPUT) ;
}
void loop() {
if (client.connected()) {
if (!requested) {
// i.e. client is connected but req. hasnt been sent
Serial << "sending request"<< endl;
requested = makeRequest(); // requesting server
}
else {
// i.e. client is connected and req. has been sent
delay(15);
if (client.find("Your result: ")) {
int airReadings = client.parseInt();
Serial << "Your result: "<< airReadings << endl; // sending to serial port, in other words to processing
if (airReadings == 1023) { // go urself to site and see value then use led for confirmation
digitalWrite(led, HIGH) ;
}
else {
digitalWrite(led ,LOW);
}
}
}
}
else {
client.stop();
connectServer();
}
}