Mise au propre
This commit is contained in:
parent
865801ad7c
commit
cee71782a1
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -102,3 +102,6 @@ venv.bak/
|
|||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
# config
|
||||
settings.py
|
13
settings-example.py
Normal file
13
settings-example.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Nombre de trames a sauter entre deux transmission des mesures (par défaut 0)
|
||||
# SKIPPED_TRAMES = 0
|
||||
|
||||
# Configuration influxdb
|
||||
influxdb = {
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': '8086',
|
||||
'USER': 'teleinfo',
|
||||
# 'PASSWORD': 'password',
|
||||
'DB_NAME': 'teleinfo',
|
||||
}
|
33
teleinfo.py
33
teleinfo.py
|
@ -15,8 +15,7 @@ import requests
|
|||
import serial
|
||||
from influxdb import InfluxDBClient
|
||||
|
||||
# Nombre de trames a sauter entre deux transmission des mesures (0 = nodelay)
|
||||
SKIPPED_TRAMES = 4
|
||||
import settings as cfg
|
||||
|
||||
# clés à utiliser - les autres ne seront pas transmises
|
||||
USED_MESURE_KEYS = [
|
||||
|
@ -51,23 +50,31 @@ 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.info("Teleinfo starting..")
|
||||
|
||||
# connexion a la base de données InfluxDB
|
||||
client = InfluxDBClient(host='192.168.0.10', port=8086, username='teleinfo', password='CLnXahFiUHjVF8xIjsLS')
|
||||
DB_NAME = "teleinfo"
|
||||
if cfg.influxdb["PASSWORD"]:
|
||||
client = InfluxDBClient(host=cfg.influxdb["HOST"], port=cfg.influxdb["PORT"], username=cfg.influxdb["USER"], password=cfg.influxdb["PASSWORD"])
|
||||
else:
|
||||
client = InfluxDBClient(host=cfg.influxdb["HOST"], port=cfg.influxdb["PORT"], username=cfg.influxdb["USER"])
|
||||
|
||||
connected = False
|
||||
while not connected:
|
||||
try:
|
||||
logging.info("Database %s exists?" % DB_NAME)
|
||||
if not {'name': DB_NAME} in client.get_list_database():
|
||||
logging.info("Database %s creation.." % DB_NAME)
|
||||
client.create_database(DB_NAME)
|
||||
logging.info("Database %s created!" % DB_NAME)
|
||||
client.switch_database(DB_NAME)
|
||||
logging.info("Connected to %s!" % DB_NAME)
|
||||
logging.info("Database %s exists?" % cfg.influxdb["DB_NAME"])
|
||||
if not {'name': cfg.influxdb["DB_NAME"]} in client.get_list_database():
|
||||
logging.info("Database %s creation.." % cfg.influxdb["DB_NAME"])
|
||||
client.create_database(cfg.influxdb["DB_NAME"])
|
||||
logging.info("Database %s created!" % cfg.influxdb["DB_NAME"])
|
||||
client.switch_database(cfg.influxdb["DB_NAME"])
|
||||
logging.info("Connected to %s!" % cfg.influxdb["DB_NAME"])
|
||||
except requests.exceptions.ConnectionError:
|
||||
logging.info('InfluxDB is not reachable. Waiting 5 seconds to retry.')
|
||||
time.sleep(5)
|
||||
|
@ -113,7 +120,7 @@ def main():
|
|||
while b'\x02' not in line: # recherche du caractère de début de trame
|
||||
line = ser.readline()
|
||||
|
||||
delaycounter = SKIPPED_TRAMES
|
||||
delaycounter = framescount
|
||||
while True:
|
||||
line = ser.readline()
|
||||
logging.debug(line)
|
||||
|
@ -140,7 +147,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 >= SKIPPED_TRAMES:
|
||||
if delaycounter >= framescount:
|
||||
time_measure = time.time()
|
||||
|
||||
# insertion dans influxdb
|
||||
|
|
Loading…
Reference in a new issue