handle-slide-syncer.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. import paho.mqtt.client as mqtt
  3. import threading
  4. import json
  5. import subprocess
  6. from time import sleep
  7. from os import path
  8. p = None
  9. # The callback for when the client receives a CONNACK response from the server.
  10. def on_connect(client, userdata, flags, rc):
  11. print("Connected with result code "+str(rc))
  12. # Subscribing in on_connect() means that if we lose the connection and
  13. # reconnect then subscriptions will be renewed.
  14. client.subscribe("video/slidesyncer/#")
  15. # The callback for when a PUBLISH message is received from the server.
  16. def on_message(client, userdata, msg):
  17. global p
  18. print(msg.topic+" "+str(msg.payload))
  19. if msg.topic == "video/slidesyncer/sync":
  20. p = subprocess.Popen(["/home/curso/code/snowmix/camera1/slide_syncer.sh"])
  21. print(p.communicate())
  22. client = mqtt.Client()
  23. client.on_connect = on_connect
  24. client.on_message = on_message
  25. client.connect("192.168.2.123", 1883, 60)
  26. t = threading.Thread(target=client.loop_forever)
  27. t.start()
  28. t.join()