2016-02-13 14:27:50 +00:00
|
|
|
#! /usr/bin/python3
|
|
|
|
|
|
|
|
# haha, "daemon" :D
|
|
|
|
# aquí iré metiendo la lectura de datos y guardado en algún sitio
|
|
|
|
|
2016-02-26 19:44:39 +00:00
|
|
|
# alias arduinousb='sudo chmod a+rw /dev/ttyACM0'
|
|
|
|
|
2016-02-13 14:27:50 +00:00
|
|
|
import serial
|
2016-02-26 19:44:39 +00:00
|
|
|
import influxdb
|
2016-02-14 19:58:41 +00:00
|
|
|
import time
|
2016-02-26 21:14:21 +00:00
|
|
|
import os.path
|
2016-02-14 19:58:41 +00:00
|
|
|
|
2016-02-13 14:27:50 +00:00
|
|
|
while True:
|
2016-02-14 19:58:41 +00:00
|
|
|
try:
|
|
|
|
influx = influxdb.InfluxDBClient("localhost", 8086, "root", "root", "hometv")
|
|
|
|
|
2016-02-26 21:14:21 +00:00
|
|
|
ser = serial.Serial("/dev/ttyACM0" if os.path.exists("/dev/ttyACM0") else "/dev/ttyACM1", 9600) # 9600 bauds
|
2016-02-14 19:58:41 +00:00
|
|
|
while True:
|
|
|
|
line = ser.readline()
|
|
|
|
parts = line.decode('ascii').strip().split(" ")
|
2016-02-26 21:14:21 +00:00
|
|
|
print(time.ctime(), line, parts)
|
2016-02-14 19:58:41 +00:00
|
|
|
|
|
|
|
if parts[0] != "D":
|
|
|
|
continue
|
|
|
|
|
|
|
|
influx.write_points([
|
|
|
|
{
|
|
|
|
"measurement": "humedad",
|
|
|
|
"tags": {
|
|
|
|
"location": "home"
|
|
|
|
},
|
|
|
|
"fields": {
|
|
|
|
"v": float(parts[1][2:])
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"measurement": "temperatura",
|
|
|
|
"tags": {
|
|
|
|
"location": "home"
|
|
|
|
},
|
|
|
|
"fields": {
|
|
|
|
"real": float(parts[2][2:]),
|
|
|
|
"sensacion": float(parts[3][2:])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
time.sleep(60)
|