From 3a19e05a680f6bb8d3c9c41e7e567b5d902812d8 Mon Sep 17 00:00:00 2001 From: Rousseau Vincent <vincent.rousseau@irstea.fr> Date: Mon, 18 Feb 2019 13:28:19 +0100 Subject: [PATCH] write multiple point with time --- sensors/ads1115/ads1115_influx.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sensors/ads1115/ads1115_influx.py b/sensors/ads1115/ads1115_influx.py index 46ad5a2..07700c3 100644 --- a/sensors/ads1115/ads1115_influx.py +++ b/sensors/ads1115/ads1115_influx.py @@ -1,5 +1,7 @@ import time import os +from datetime import datetime +import threading import ADS1115 as ads1115_lib from influxdb import InfluxDBClient @@ -12,11 +14,12 @@ adc = ads1115_lib.ADS1115() # Add timestamp to measurement # Accumulate measurement to write multiples points +measurement = [] -while True: - measurement = [ - { +def getMeasurements(): + new_measurement = { 'measurement': 'ads1115', + 'time': datetime.now(), 'fields': { 'ain0': adc.readADCSingleEnded(), 'ain1': adc.readADCSingleEnded(1), @@ -24,7 +27,12 @@ while True: '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) + measurement.clear() time.sleep(1) -- GitLab