update to docker version

This commit is contained in:
robert 2021-08-13 15:24:35 +02:00
parent d56a0afcf6
commit 646947df31

View File

@ -1,6 +1,7 @@
import json import json
import sys import sys
import os import os
import docker
# Import MQTT client. # Import MQTT client.
import paho.mqtt.publish as publish import paho.mqtt.publish as publish
@ -22,23 +23,19 @@ client = paho.Client(protocol=paho.MQTTv31) # * set a random string (max 23 cha
#client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials #client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials
client.connect(mqtt_broker, 1883, 60) # MQTT server address client.connect(mqtt_broker, 1883, 60) # MQTT server address
#client.loop_start()
# -R 42 HIDEKI TS04 Temperature, Humidity, Wind and Rain Sensor (garden sensor) # -R 42 HIDEKI TS04 Temperature, Humidity, Wind and Rain Sensor (garden sensor)
# -R 187 Inkbird ITH-20R temperature humidity sensor (pool sensor) # -R 187 Inkbird ITH-20R temperature humidity sensor (pool sensor)
process = os.popen('docker run --device /dev/bus/usb/001/004 rtl_433:inkbird -R 42 -R 187 -F json -T 65 -M time:utc:usec') docker = docker.from_env()
processData = process.read().split('\n') container = docker.containers.run("rtl_433:inkbird", "-R 42 -R 187 -F json -T 40 -M time:utc:usec", devices={'/dev/bus/usb/001/004:/dev/bus/usb/001/004:rwm'})
print("processData: ") for line in container.split('\n'):
print(processData)
for i in processData: print("line: " + line)
print("i: ") print("line length: " + str(len(line)))
print(len(i))
print(i)
if len(i) > 0: if len(line) > 0:
jsonData = (json.loads(i)) jsonData = (json.loads(line))
model = str(jsonData['model']) model = str(jsonData['model'])
if model == "Hideki-TS04": if model == "Hideki-TS04":
@ -47,7 +44,11 @@ for i in processData:
topic = 'weathersensors/pool' topic = 'weathersensors/pool'
time = str(jsonData['time']) time = str(jsonData['time'])
battery = str(jsonData['battery_ok']) if model == "Inkbird ITH-20R":
battery_json_key = "battery"
else:
battery_json_key = "battery_ok"
battery = str(jsonData[battery_json_key])
temperature = str(jsonData['temperature_C']) temperature = str(jsonData['temperature_C'])
humidity = str(jsonData['humidity']) humidity = str(jsonData['humidity'])
@ -55,5 +56,3 @@ for i in processData:
client.publish(topic + "/battery", "" + battery) client.publish(topic + "/battery", "" + battery)
client.publish(topic + "/temperature", "" + temperature) client.publish(topic + "/temperature", "" + temperature)
client.publish(topic + "/humidity", "" + humidity) client.publish(topic + "/humidity", "" + humidity)
process.close()