forked from lucas-vittaz/feed-my-plant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeed_my_plant_send_data_v2.ino
79 lines (59 loc) · 2.15 KB
/
Feed_my_plant_send_data_v2.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
//#include <ArduinoHttpClient.h>
#include <Ethernet.h>
#include <SPI.h>
int sensorPin = A0;
int sensorValue = 0;
//Feedmyplant
char server[] = "http://www.feedmyplant.com";
byte myMac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x0E, 0x03 };
int HTTP_PORT = 80;
String HTTP_METHOD = "GET"; //"GET" or "POST"
char HOST_NAME[] = "www.feedmyplant.com"; // hostname of web server:
String PATH_NAME = "/devices/c99dcd40/telemetry";
String external_id = "?external_id=";
String query = "sensor=";
String id = "c99dcd41";
EthernetClient client;
void setup() {
Serial.begin(9600);
// initialize the Ethernet shield using DHCP:
Serial.println("Obtaining an IP address using DHCP");
if (Ethernet.begin(myMac) == 0) {
Serial.println("Failed to obtaining an IP address");
// check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware)
Serial.println("Ethernet shield was not found");
// check for Ethernet cable
if (Ethernet.linkStatus() == LinkOFF)
Serial.println("Ethernet cable is not connected.");
while (true);
}
// print out Arduino's IP address, subnet mask, gateway's IP address, and DNS server's IP address
Serial.print("- Arduino's IP address : ");
Serial.println(Ethernet.localIP());
Serial.print("- Gateway's IP address : ");
Serial.println(Ethernet.gatewayIP());
Serial.print("- Network's subnet mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("- DNS server's IP address: ");
Serial.println(Ethernet.dnsServerIP());
}
void loop() {
if(client.connect(HOST_NAME, HTTP_PORT)) {
Serial.println("Connected to server");
} else {
Serial.println("connection failed");
}
//sensorValue = analogRead(sensorPin);
String sensor_read = String(analogRead(0));
client.println(HTTP_METHOD + " " + PATH_NAME + external_id + id + "&" + query + String(sensor_read) + " HTTP/1.1");
client.println("Host: " + String(HOST_NAME));
client.println("Connection: close");
client.println();
while(client.available())
{
char c = client.read();
Serial.print(c);
}
delay(2000);
}