Module mqtt implemented
This commit is contained in:
parent
fe789d96d1
commit
e1f97c4a4e
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -4,3 +4,6 @@
|
||||
[submodule "report"]
|
||||
path = report
|
||||
url = https://git.mount-mockery.de/pylib/report.git
|
||||
[submodule "mqtt"]
|
||||
path = mqtt
|
||||
url = https://git.mount-mockery.de/pylib/mqtt.git
|
||||
|
@ -1,6 +1,6 @@
|
||||
import config
|
||||
import logging
|
||||
import paho.mqtt.client as paho
|
||||
import mqtt
|
||||
import socket
|
||||
import report
|
||||
import time
|
||||
@ -15,18 +15,13 @@ except ImportError:
|
||||
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main')
|
||||
|
||||
|
||||
def send_data_to_mqtt(data):
|
||||
client= paho.Client(config.APP_NAME)
|
||||
client.username_pw_set(config.MQTT_USER, config.MQTT_PASS)
|
||||
try:
|
||||
client.connect(config.MQTT_SERVER, 1883)
|
||||
for key in data:
|
||||
topic = config.MQTT_TOPIC + "/" + key
|
||||
logger.info("Sending Ambient Information to mqtt %s=%s", topic, str(data[key]))
|
||||
client.publish(topic, data[key])
|
||||
except (socket.timeout, OSError) as e:
|
||||
logger.warning("Erro while sending ambient information")
|
||||
mc = mqtt.mqtt_client(config.APP_NAME, config.MQTT_SERVER, 1883, config.MQTT_USER, config.MQTT_PASS)
|
||||
|
||||
def send_data_to_mqtt(data):
|
||||
for key in data:
|
||||
topic = config.MQTT_TOPIC + "/" + key
|
||||
logger.info("Sending Ambient Information to mqtt %s=%s", topic, str(data[key]))
|
||||
mc.send(topic, data[key])
|
||||
|
||||
def dht_callback(**data):
|
||||
del(data["time"])
|
||||
|
1
mqtt
Submodule
1
mqtt
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit cf97fa066cdff0e2f7eda0ff4d3c8c0f59c3f2ec
|
Loading…
x
Reference in New Issue
Block a user