Merge pull request #1 from d3vyce/v1.1.0

V1.1.0
This commit is contained in:
d3vyce 2024-02-16 18:19:45 +01:00 committed by GitHub
commit 5da09093f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 6 deletions

View File

@ -1,5 +1,8 @@
# Changelog
## [1.0.0] - 12-19-2023
## 1.1.0 - 02-11-2024
add: Grafana dashboard to README
fix: MQTT brocker disconnection when client connection timeout
Initial release
## 1.0.0 - 12-19-2023
Initial release

View File

@ -1,8 +1,12 @@
# Teleinfo Exporter
![Grafana Dashboard](https://grafana.com/api/dashboards/20182/images/15332/image)
Simple prometheus exporter for Linky teleinfo.
Teleinfo Tasmota project :
https://github.com/NicolasBernaerts/tasmota/tree/master/teleinfo
Grafana Dashboard:
https://grafana.com/grafana/dashboards/20182-linky-teleinfo/
## Installation
### Pip

View File

@ -3,6 +3,7 @@
import json
import random
import string
import time
import bcrypt
import configargparse
@ -92,6 +93,7 @@ teleinfo_contract_type = Gauge("teleinfo_contract_type", "contract type", ["type
def on_connect(client, userdata, flags, rc): # pylint: disable=unused-argument
client.subscribe("teleinfo/tele/SENSOR")
if rc == 0:
print("Connected to broker")
else:
@ -146,6 +148,16 @@ def on_message(client, userdata, message): # pylint: disable=unused-argument
teleinfo_contract_type.labels(message["TIC"]["OPTARIF"]).set(0)
def on_disconnect(client, userdata, rc): # pylint: disable=unused-argument
print("Diconnected from broker, reconnecting...")
while True:
try:
if not client.reconnect():
break
except ConnectionRefusedError:
time.sleep(1)
@app.before_request
@auth.login_required()
def global_auth():
@ -186,7 +198,6 @@ def main():
p.add("--http_cert", help="HTTP Server Certificate", env_var="HTTP_CERT")
p.add("--http_key", help="HTTP Server Key", env_var="HTTP_KEY")
options = p.parse_args()
print(options)
if options.auth_user and options.auth_hash:
app.config["USERS"] = {options.auth_user: options.auth_hash.encode()}
@ -198,13 +209,12 @@ def main():
if options.broker_user and options.broker_password:
client.username_pw_set(options.broker_user, password=options.broker_password)
client.connect(options.broker_host, port=options.broker_port)
client.on_connect = on_connect
client.on_message = on_message
client.connect(options.broker_host, port=options.broker_port)
client.on_disconnect = on_disconnect
client.loop_start()
client.subscribe(options.broker_topic)
if options.http_cert and options.http_key:
ssl_context = (options.http_cert, options.http_key)
else: