Mise au propre variables

This commit is contained in:
Gitouche 2023-01-08 16:44:21 +01:00
parent b500b3ec71
commit 9e076bd2eb
2 changed files with 11 additions and 10 deletions

View file

@ -1,5 +1,11 @@
#!/usr/bin/env python
# device port serie
SERIAL='/dev/ttyAMA0'
# Fichier de log
LOGFILE='/var/log/teleinfo-releve.log'
# Nombre de trames a sauter entre deux transmission des mesures (par défaut 0)
# SKIPPED_TRAMES = 0

View file

@ -50,13 +50,8 @@ INT_MESURE_KEYS = [
'UMOY',
]
if not cfg.SKIPPED_TRAMES:
framescount = 0
else:
framescount = cfg.SKIPPED_TRAMES
# création du logguer
logging.basicConfig(filename='/tmp/teleinfo-releve.log', level=logging.INFO, format='%(asctime)s %(message)s')
logging.basicConfig(filename=cfg.LOGFILE, level=logging.INFO, format='%(asctime)s %(message)s')
logging.info("Teleinfo starting..")
# connexion a la base de données InfluxDB
@ -110,9 +105,9 @@ def checksum(line:str) -> str:
return chr((sum(list(line)) & 0x3F) + 0x20)
def main():
with serial.Serial(port='/dev/ttyAMA0', baudrate=9600, parity=serial.PARITY_EVEN, bytesize=serial.SEVENBITS, timeout=1) as ser:
with serial.Serial(port=cfg.SERIAL, baudrate=9600, parity=serial.PARITY_EVEN, bytesize=serial.SEVENBITS, timeout=1) as ser:
logging.info("Teleinfo is reading on /dev/ttyAMA0..")
logging.info("Teleinfo is reading on %s.." % cfg.SERIAL)
trame = dict()
# boucle pour partir sur un début de trame
@ -120,7 +115,7 @@ def main():
while b'\x02' not in line: # recherche du caractère de début de trame
line = ser.readline()
delaycounter = framescount
delaycounter = cfg.SKIPPED_TRAMES
while True:
line = ser.readline()
logging.debug(line)
@ -147,7 +142,7 @@ 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 >= framescount:
if delaycounter >= cfg.SKIPPED_TRAMES:
time_measure = time.time()
# insertion dans influxdb