simplification skipping frames
This commit is contained in:
parent
248b50c76c
commit
865801ad7c
20
teleinfo.py
20
teleinfo.py
|
@ -4,6 +4,8 @@
|
|||
# __licence__ = "Apache License 2.0"
|
||||
|
||||
# Python 3, prérequis : pip install pySerial influxdb
|
||||
# TIC Enedis référence : Enedis-NOI-CPT_54E.pdf
|
||||
# https://www.enedis.fr/media/2035/download
|
||||
|
||||
import logging
|
||||
import time
|
||||
|
@ -13,8 +15,8 @@ import requests
|
|||
import serial
|
||||
from influxdb import InfluxDBClient
|
||||
|
||||
# Nombre de trames entre deux transmission des mesures (0 = nodelay)
|
||||
DELAY_MESURE = 10
|
||||
# Nombre de trames a sauter entre deux transmission des mesures (0 = nodelay)
|
||||
SKIPPED_TRAMES = 4
|
||||
|
||||
# clés à utiliser - les autres ne seront pas transmises
|
||||
USED_MESURE_KEYS = [
|
||||
|
@ -111,14 +113,8 @@ def main():
|
|||
while b'\x02' not in line: # recherche du caractère de début de trame
|
||||
line = ser.readline()
|
||||
|
||||
delaycounter = DELAY_MESURE
|
||||
delaycounter = SKIPPED_TRAMES
|
||||
while True:
|
||||
while delaycounter < DELAY_MESURE:
|
||||
logging.debug(delaycounter)
|
||||
line = ser.readline()
|
||||
while b'\x02' not in line: # recherche du caractère de début de trame
|
||||
line = ser.readline()
|
||||
delaycounter+=1
|
||||
line = ser.readline()
|
||||
logging.debug(line)
|
||||
try:
|
||||
|
@ -144,17 +140,19 @@ def main():
|
|||
else:
|
||||
logging.debug('Checksum error, aborting frame')
|
||||
if b'\x03' in line: # si caractère de fin dans la ligne, on insère la trame dans influx
|
||||
if delaycounter >= SKIPPED_TRAMES:
|
||||
time_measure = time.time()
|
||||
|
||||
# insertion dans influxdb
|
||||
add_measures(trame)
|
||||
|
||||
# ajout timestamp pour debugger
|
||||
trame["timestamp"] = int(time_measure)
|
||||
logging.debug(trame)
|
||||
delaycounter = 0
|
||||
else:
|
||||
delaycounter += 1
|
||||
|
||||
trame = dict() # on repart sur une nouvelle trame
|
||||
delaycounter=0
|
||||
except Exception as e:
|
||||
logging.error("Exception : %s" % e, exc_info=True)
|
||||
logging.error("%s" % (line))
|
||||
|
|
Loading…
Reference in a new issue