Parcourir la source

allow a service restart via mqtt

David il y a 8 ans
Parent
commit
0e5807e055
1 fichiers modifiés avec 11 ajouts et 3 suppressions
  1. 11 3
      mic1/mic.py

+ 11 - 3
mic1/mic.py

@@ -16,6 +16,7 @@ HEIGHT = 720
 SCREEN_WIDTH = 800
 SCREEN_HEIGHT = 600
 zoom = 1
+not_exited = True
 
 
 # def bus_call(bus, msg, *args):
@@ -42,6 +43,9 @@ def on_connect(client, userdata, flags, rc):
 # The callback for when a PUBLISH message is received from the server.
 def on_message(client, userdata, msg):
     print(msg.topic+" "+str(msg.payload))
+    global not_exited
+    if msg.topic == "vide/mic1/restart":
+        not_exited = False
 
 
 client = mqtt.Client()
@@ -82,8 +86,12 @@ if __name__ == "__main__":
     pipeline.set_state(Gst.State.PLAYING)
     t = threading.Thread(target=client.loop_forever, daemon=True)
     t.start()
-    while True:
-        client.publish("video/heartbeat", "mic1")
-        time.sleep(10)
+    counter = 0
+    while not_exited:
+        counter += 1
+        time.sleep(1)
+        if counter >= 10:
+            client.publish("video/heartbeat", "mic1")
+            counter = 0
 
     pipeline.set_state(Gst.State.NULL)