-
Notifications
You must be signed in to change notification settings - Fork 33
/
WeatherUnderground.h
96 lines (63 loc) · 2.25 KB
/
WeatherUnderground.h
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
92
93
94
95
//
// WeatherUnderground Interface
//
// SwitchDoc Labs, Spetember 2016
//
//
int sendWeatherUndergroundData()
{
WiFiClient client;
const char* host = "weatherstation.wunderground.com";
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return 1;
}
String myURL;
// = "/weatherstation/updateweatherstation.php?ID=KWALIBER14&PASSWORD=20mqkah7&dateutc=now&winddir=180&windspeedmph=3.45&humidity=14&tempf=91.04&rainin=0.00&baromin=27.83&indoortempf=32.00&indoorhumidity0.00=&software=OurWeather";
myURL = "/weatherstation/updateweatherstation.php?";
myURL += "ID=" + WeatherUnderground_StationID;
myURL += "&PASSWORD=" + WeatherUnderground_StationKey;
myURL += "&dateutc=now";
// now weather station variables
myURL += "&winddir=" + String(currentWindDirection);
myURL += "&windspeedmph=" + String(currentWindSpeed / 1.6);
myURL += "&windgustmph=" + String(currentWindGust / 1.6);
myURL += "&humidity=" + String(AM2315_Humidity);
myURL += "&tempf=" + String((AM2315_Temperature * 9.0 / 5.0) + 32.0);
myURL += "&dewptf=" + String((dewpoint * 9.0 / 5.0) + 32.0);
myURL += "&rainin=" + String((rain60Minutes) / 25.4);
myURL += "&dailyrainin=" + String(( rainCalendarDay) / 25.4);
myURL += "&baromin=" + String((BMP180_Pressure / 1000.0) * 0.2953, 4);
myURL += "&indoortempf=" + String((BMP180_Temperature * 9.0 / 5.0) + 32.0);
//myURL += "&indoorhumidity%0.2f=" % HTUhumidity
myURL += "&software=OurWeather";
Serial.print("Requesting URL: ");
Serial.println(myURL);
// This will send the request to the server
client.print(String("GET ") + myURL + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(1500);
String WUResult;
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
WUResult = line;
yield();
}
Serial.print("WUResult=");
Serial.println(WUResult);
if (WUResult.indexOf("success") != -1)
{
Serial.println("WU Successful Write");
return 1;
}
else
{
Serial.println("WU NOT Successful Write");
}
client.stop();
return 0;
}