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