Commit 3a19e05a authored by Rousseau Vincent's avatar Rousseau Vincent
Browse files

write multiple point with time

parent e4e8bc31
No related merge requests found
Showing with 12 additions and 4 deletions
+12 -4
import time import time
import os import os
from datetime import datetime
import threading
import ADS1115 as ads1115_lib import ADS1115 as ads1115_lib
from influxdb import InfluxDBClient from influxdb import InfluxDBClient
...@@ -12,11 +14,12 @@ adc = ads1115_lib.ADS1115() ...@@ -12,11 +14,12 @@ adc = ads1115_lib.ADS1115()
# Add timestamp to measurement # Add timestamp to measurement
# Accumulate measurement to write multiples points # Accumulate measurement to write multiples points
measurement = []
while True: def getMeasurements():
measurement = [ new_measurement = {
{
'measurement': 'ads1115', 'measurement': 'ads1115',
'time': datetime.now(),
'fields': { 'fields': {
'ain0': adc.readADCSingleEnded(), 'ain0': adc.readADCSingleEnded(),
'ain1': adc.readADCSingleEnded(1), 'ain1': adc.readADCSingleEnded(1),
...@@ -24,7 +27,12 @@ while True: ...@@ -24,7 +27,12 @@ while True:
'ain3': adc.readADCSingleEnded(channel=3, pga=1024, sps=16) 'ain3': adc.readADCSingleEnded(channel=3, pga=1024, sps=16)
} }
} }
] measurement.append(new_measurement)
threading.Timer(0.1, getMeasurements).start()
while True:
influx_client.write_points(measurement) influx_client.write_points(measurement)
measurement.clear()
time.sleep(1) time.sleep(1)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment