-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinflux_handler.py
More file actions
33 lines (27 loc) · 1.01 KB
/
influx_handler.py
File metadata and controls
33 lines (27 loc) · 1.01 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
from influxdb import InfluxDBClient
from core.config import INFLUX_PASSWORD, INFLUX_USER, INFLUX_HOST, INFLUX_DB
client = InfluxDBClient(host=INFLUX_HOST, port=8086, username=INFLUX_USER, password=INFLUX_PASSWORD)
client.switch_database(INFLUX_DB)
def write_to_influx(timestamp, x, y, z, device_id, label):
try:
data = [
{
"measurement": "motionUserAcceleration",
"tags": {
"device_id": device_id,
"label": label
},
"time": timestamp,
"fields": {
"motionUserAccelerationX": x,
"motionUserAccelerationY": y,
"motionUserAccelerationZ": z
}
}
]
#results = client.query('SELECT * FROM "iphone"."autogen"."motionUserAcceleration" WHERE time > now() - 4d')
#print(results.raw)
client.write_points(data)
return True
except Exception as e:
print(e)