diff --git a/ReadMe.md b/ReadMe.md index 0da37bc..b635c6c 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -37,4 +37,4 @@ Set the following parameter: * Base Topic - ```docker run -e MQTT_SERVER="192.168.x.y" -e MQTT_TOPIC="testtopic/" sha256:``` + ```docker run -t -i --device=/dev/ttyUSB0 -e SERIAL_DEVICE="/dev/ttyUSB0" -e MQTT_SERVER="192.168.x.y" -e MQTT_TOPIC="testtopic/" sha256:``` diff --git a/mqttclient/fanATserial2mqtt.py b/mqttclient/fanATserial2mqtt.py index 44b808c..f5fc23d 100644 --- a/mqttclient/fanATserial2mqtt.py +++ b/mqttclient/fanATserial2mqtt.py @@ -3,8 +3,13 @@ import time import sys from paho.mqtt import client as mqtt_client import os +import serial + +# MQTT Settings mqtt_server=os.environ['MQTT_SERVER'] mqtt_topic=os.environ['MQTT_TOPIC'] +# SERIAL Port +serial_device=os.environ['SERIAL_DEVICE'] # The callback for when a PUBLISH message is received from the server. def on_message(client, userdata, msg): @@ -27,6 +32,12 @@ val=0 client.loop_start() +ser = serial.Serial(serial_device, 115200, timeout=1) # open serial port +client.publish(mqtt_topic + "device", ser.name) # check which port was really used + +line = ser.readline() # read a '\n' terminated line +client.publish(mqtt_topic + "debug", line) # check which port was really used + # Endless Loop while True: try: