Commit 1ae2363b authored by 簡碩辰's avatar 簡碩辰

Update run.py

parent 9983a077
...@@ -21,9 +21,11 @@ name = os.getenv("DVR_NAME") or "rd" ...@@ -21,9 +21,11 @@ name = os.getenv("DVR_NAME") or "rd"
key = os.getenv("DVR_KEY") or "main_4" key = os.getenv("DVR_KEY") or "main_4"
ch = os.getenv("DVR_CH") or "0"
topic = "dvr/{0}/{1}".format(name, key) topic = "dvr/{0}/{1}".format(name, key)
payload = { 'status': 0, 'host': "", 'name': name, 'key': key, 'msg': "" } payload = { 'status': 0, 'rtsp': "", 'msg': "" }
while True: while True:
host = os.getenv("MQTT_HOST") or "192.168.5.217" host = os.getenv("MQTT_HOST") or "192.168.5.217"
...@@ -51,7 +53,7 @@ while True: ...@@ -51,7 +53,7 @@ while True:
port = os.getenv("DVR_PORT") or "80" port = os.getenv("DVR_PORT") or "80"
if TryConnect(host, port): # 測試連線到 DVR if TryConnect(host, port): # 測試連線到 DVR
rtsp_out = "{0}/{1}/{2}".format(rtsp_out, name, key) rtsp_out = "{0}/{1}/{2}".format(rtsp_out, name, ch)
rtsp_in = "rtsp://{0}:{1}@{2}".format(user, pswd, host) rtsp_in = "rtsp://{0}:{1}@{2}".format(user, pswd, host)
...@@ -72,7 +74,9 @@ while True: ...@@ -72,7 +74,9 @@ while True:
try: try:
payload['status'] = 1 payload['status'] = 1
payload['msg'] = 'Ready to Transfer.' payload['rtsp'] = rtsp_out
payload['msg'] = "Ready to Transfer."
client.publish(topic, json.dumps(payload), 1) client.publish(topic, json.dumps(payload), 1)
...@@ -80,7 +84,9 @@ while True: ...@@ -80,7 +84,9 @@ while True:
payload['status'] = 0 payload['status'] = 0
payload['msg'] = 'Popen is closed.' payload['rtsp'] = ""
payload['msg'] = "Popen is closed."
client.publish(topic, json.dumps(payload), 1) client.publish(topic, json.dumps(payload), 1)
except Exception as e: except Exception as e:
...@@ -90,15 +96,19 @@ while True: ...@@ -90,15 +96,19 @@ while True:
client.publish(topic, json.dumps(payload), 1) client.publish(topic, json.dumps(payload), 1)
else: else:
payload['msg'] = "Connect to DVR is refused."
payload['status'] = 0 payload['status'] = 0
payload['rtsp'] = ""
payload['msg'] = "Connect to DVR is refused."
client.publish(topic, json.dumps(payload), 1) client.publish(topic, json.dumps(payload), 1)
else: else:
payload['msg'] = "Connect to EasyDarwin is refused."
payload['status'] = 0 payload['status'] = 0
payload['rtsp'] = ""
payload['msg'] = "Connect to EasyDarwin is refused."
client.publish(topic, json.dumps(payload), 1) client.publish(topic, json.dumps(payload), 1)
else: else:
......
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