31 lines
868 B
Python
31 lines
868 B
Python
#!/usr/bin/env python3
|
|
from flask import current_app as app
|
|
import config
|
|
|
|
"""
|
|
MQTT Stuff
|
|
"""
|
|
|
|
__author__ = "@tormakris"
|
|
__copyright__ = "Copyright 2020, Birbnetes Team"
|
|
__module_name__ = "mqtt_methods"
|
|
__version__text__ = "1"
|
|
|
|
|
|
def handle_status_message(client, userdata, message):
|
|
data = dict(
|
|
topic=message.topic,
|
|
payload=message.payload.decode()
|
|
)
|
|
app.logger.info(data)
|
|
try:
|
|
ids = data['topic'].replace(f"{config.MQTT_STATUS_TOPIC}/", "").split("/")
|
|
if len(ids) == 1:
|
|
app.logger.info(f"Recieved status message from {ids[0]} it was: {data['payload']}.")
|
|
else:
|
|
if len(ids) == 2:
|
|
app.logger.info(
|
|
f"Recieved status message from sensor {ids[1]} on device {ids[0]} it was: {data['payload']}.")
|
|
except Exception as e:
|
|
app.logger.exception(e)
|