update to docker version
This commit is contained in:
parent
d56a0afcf6
commit
646947df31
@ -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,38 +23,36 @@ 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":
|
||||||
topic = 'weathersensors/garden'
|
topic = 'weathersensors/garden'
|
||||||
else:
|
else:
|
||||||
topic = 'weathersensors/pool'
|
topic = 'weathersensors/pool'
|
||||||
|
|
||||||
time = str(jsonData['time'])
|
time = str(jsonData['time'])
|
||||||
battery = str(jsonData['battery_ok'])
|
if model == "Inkbird ITH-20R":
|
||||||
temperature = str(jsonData['temperature_C'])
|
battery_json_key = "battery"
|
||||||
humidity = str(jsonData['humidity'])
|
else:
|
||||||
|
battery_json_key = "battery_ok"
|
||||||
|
battery = str(jsonData[battery_json_key])
|
||||||
|
temperature = str(jsonData['temperature_C'])
|
||||||
|
humidity = str(jsonData['humidity'])
|
||||||
|
|
||||||
client.publish(topic + "/time", "" + time)
|
client.publish(topic + "/time", "" + time)
|
||||||
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()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user