Commit 7994c04e authored by 簡碩辰's avatar 簡碩辰

Update run.py

parent 6209b3fb
......@@ -34,14 +34,13 @@ ch = os.getenv("ED_CH")
topic = "dvr/{0}/{1}".format(name, ch)
while True:
payload = { 'status': 0, 'host': "", 'name': "", 'ch': "", 'msg': "" }
payload = { 'status': 0, 'host': "", 'name': "", 'ch': "", 'msg': "" }
host = os.getenv("MQTT_HOST")
host = os.getenv("MQTT_HOST")
port = os.getenv("MQTT_PORT")
port = os.getenv("MQTT_PORT")
if TryConnect('MQTT', host, port): # 測試連線到 MQTT
if TryConnect('MQTT', host, port): # 測試連線到 MQTT
client = MQTT()
client.connect(host, int(port), 3600)
......@@ -87,10 +86,14 @@ while True:
p = SP.Popen(command)
try:
stream = cv.VideoCapture(' '.join(command))
if stream.isOpened():
isOpened = stream.isOpened()
stream.release()
try:
if isOpened:
payload['status'] = 1
payload['msg'] = "Ready to Transfer."
......@@ -99,28 +102,22 @@ while True:
p.communicate()
else:
stream.release()
payload['status'] = 0
payload['msg'] = "Popen is closed."
payload['msg'] = "Popen is broke."
client.publish(topic, json.dumps(payload), 1)
except Exception as e:
payload['status'] = 0
payload['msg'] = e
payload['msg'] = "Popen is closed."
client.publish(topic, json.dumps(payload), 1)
p.kill()
except Exception as e:
payload['msg'] = e
else:
payload['status'] = 0
payload['msg'] = "Connect to DVR is refused."
client.publish(topic, json.dumps(payload), 1)
else:
payload['status'] = 0
payload['msg'] = "Connect to EasyDarwin is refused."
client.publish(topic, json.dumps(payload), 1)
\ No newline at end of file
client.publish(topic, json.dumps(payload), 1)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment