forked from switchdoclabs/SDL_Pi_SkyWeather2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeatherUnderground.py
69 lines (48 loc) · 2.53 KB
/
WeatherUnderground.py
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
# Send SkyWeather2 Information to the WeatherUnderground
#
# SwitchDoc Labs March, 2021
#
import sys
import requests
# import httplib
import traceback
import config
import state
def sendWeatherUndergroundData(Rain24Hour):
if ((config.WeatherUnderground_Present == True) and (state.lastMainReading != "Never")):
try:
# https://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=KCASANFR5&PASSWORD=XXXXXX&dateutc=2000-01-01+10%3A32%3A35&winddir=230&windspeedmph=12&windgustmph=12&tempf=70&rainin=0&baromin=29.1&dewptf=68.2&humidity=90&weather=&clouds=&softwaretype=vws%20versionxx&action=updateraw
# build the URL
myURL = "ID="+config.WeatherUnderground_StationID
myURL += "&PASSWORD="+config.WeatherUnderground_StationKey
myURL += "&dateutc=now"
# now weather station variables
myURL += "&winddir=%i" % state.WindDirection
myURL += "&windspeedmph=%0.2f" % (state.WindSpeed/0.447704)
myURL += "&windgustmph=%0.2f" % (state.WindGust/0.447704)
myURL += "&humidity=%i" % state.OutdoorHumidity
myURL += "&tempf=%0.2f" % ((state.OutdoorTemperature*9.0/5.0)+32.0)
dewpoint = state.OutdoorTemperature - ((100.0 - state.OutdoorHumidity) / 5.0);
dewpointf = ((dewpoint*9.0/5.0)+32.0)
myURL += "&dewptf=%0.2f" % dewpointf
myURL += "&rainin=%0.2f" % ((state.Rain60Minutes)/25.4)
myURL += "&dailyrainin=%0.2f" % ((Rain24Hour)/25.4)
myURL += "&baromin=%0.2f" % (((state.BarometricPressureSeaLevel) * 0.2953))
myURL += "&indoortempf=%0.2f" % ((state.IndoorTemperature*9.0/5.0)+32.0)
myURL += "&indoorhumidity%0.2f=" % state.IndoorHumidity
print("sv=", state.SunlightVisible)
print("svtype=", type(state.SunlightVisible) )
myURL += "&solarradiation=%0.2f"% (float(state.SunlightVisible)*0.0079)
myURL += "&UV=%0.2f"% state.SunlightUVIndex
myURL += "&software=SkyWeather2"
if (config.SWDEBUG):
print ("myURL=", myURL)
#send it
r = requests.get("https://rtupdate.wunderground.com/weatherstation/updateweatherstation.php", params=myURL)
if (config.SWDEBUG):
print(r.url)
print(r.text)
print( "GET sent")
except:
traceback.print_exc()
print( "--WeatherUnderground Data Send Failed")