forked from hnrkp/pyWeatherLink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_influxdb.py
More file actions
76 lines (60 loc) · 2.95 KB
/
Copy pathsend_influxdb.py
File metadata and controls
76 lines (60 loc) · 2.95 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
#!/usr/bin/env python
# encoding: utf-8
from communication import Link
from influxdb import InfluxDBClient
from config import *
from conversions import *
import urllib2
WUNDERGROUND_BASEURL = 'http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php'
WUNDERGROUND_UPDATEURL = '%s?ID=%s&PASSWORD=%s&action=updateraw&dateutc=now' % (WUNDERGROUND_BASEURL, WUNDERGROUND_ID, WUNDERGROUND_PASSWORD)
l = Link('/dev/ttyUSB0')
inClient = InfluxDBClient(host=INFLUXDB_HOST, database=INFLUXDB_DATABASE)
def upload_to_influxdb(measurement, tags, fields, time=None):
_ = {
"measurement": measurement,
"tags": tags,
"fields": fields
}
if time:
_['time'] = time
data = []
data.append(_)
inClient.write_points(data)
if __name__ == "__main__":
simg = l.getSensorImage()
# print dir(simg)
# ['AverageWindSpeed', 'Forecast', 'IndoorRelativeHumidity', 'IndoorTemperature', 'OutdoorDewpoint', 'OutdoorRelativeHumidity', 'OutdoorTemperature', 'QFE', 'QFETrend', 'RainDay', 'RainRate', 'Timestamp', 'WindDirection', 'WindSpeed', '_SensorImage__getitemp', '_SensorImage__getotemp', '_SensorImage__getwd', '_SensorImage__getws', '_SensorImage__itemp', '_SensorImage__otemp', '_SensorImage__setitemp', '_SensorImage__setotemp', '_SensorImage__setwd', '_SensorImage__setws', '_SensorImage__wd', '_SensorImage__ws', '__doc__', '__init__', '__module__', '__str__']
print 'Outdoor Temperature', f2c(simg.OutdoorTemperature)
print 'Outdoor Relative Humidity:', simg.OutdoorRelativeHumidity
print 'QFE:', round(inHg2hPa(simg.QFE), 2)
print 'Wind Speed:', mph2ms(simg.WindSpeed)
print 'Average Wind Speed:', mph2ms(simg.AverageWindSpeed)
print 'Wind Direction:', simg.WindDirection
print 'Outdoor Dewpoint:', simg.OutdoorDewpoint
print 'Rain Rate:', simg.RainRate
print 'Rain Day:', simg.RainDay
print 'Solar Radiation:', simg.SolarRadiation
print 'UVI:', simg.UVI
tags = {
"name": STATION_NAME,
"device": STATION_DEVICE,
"model": STATION_MODEL,
}
fields = {
"pressure_hpa": round(inHg2hPa(simg.QFE), 2),
"temperature_c": f2c(simg.OutdoorTemperature),
"dew_point_c": simg.OutdoorDewpoint,
"humidity": simg.OutdoorRelativeHumidity,
"wind_speed_ms": mph2ms(simg.WindSpeed),
"wind_degree": simg.WindDirection,
"rain_1hr_mm": simg.RainRate,
"rain_24hr_mm": simg.RainDay,
"radiation_Wm2": simg.SolarRadiation,
"UVI": int(round(simg.UVI))
}
upload_to_influxdb(INFLUXDB_MEASUREMENT, tags, fields)
# upload to weather underground
w = urllib2.urlopen(WUNDERGROUND_UPDATEURL +
"&humidity=%s&tempf=%s&UV=%s&baromin=%s&winddir=%s&windspeedmph=%s&rainin=%s&solarradiation=%s" % (simg.OutdoorRelativeHumidity, simg.OutdoorTemperature, simg.UVI, simg.QFE, simg.WindDirection, simg.WindSpeed, simg.RainRate, simg.SolarRadiation))
print w.read()
w.close()