Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #! /usr/bin/python3
  2.  
  3. import os
  4. import paho.mqtt.client as mqtt
  5. import serial
  6. import socket
  7. import sys
  8. import time
  9.  
  10. from mpd import MPDClient
  11.  
  12. while True:
  13. try:
  14. with serial.Serial('/dev/ttyUSB0', 115200) as ser:
  15. line = ser.readline()
  16.  
  17. if line[0:4] != 'Init':
  18. print('%s deurbel!' % time.ctime())
  19.  
  20. os.system('/usr/local/sbin/jsb-udpsend -m DEURBELLLLL')
  21.  
  22. UDP_IP = "10.208.42.159"
  23. UDP_PORT = 5001
  24.  
  25. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  26. sock.sendto('$f$deurbel!!!'.encode(), (UDP_IP, UDP_PORT))
  27.  
  28. client = mqtt.Client('deurbel_%d' % os.getpid())
  29. client.connect('10.208.11.30', port=1883, keepalive=61, bind_address="")
  30.  
  31. mclient = MPDClient() # create client object
  32. mclient.timeout = 10 # network timeout in seconds (floats allowed), default: None
  33. mclient.idletimeout = None # timeout for fetching the result of the idle command is handled seperately, default: None
  34. mclient.connect("slabpi.dhcp.nurd.space", 6600) # connect to localhost:6600
  35. print(mclient.mpd_version) # print the MPD version
  36.  
  37. client.publish('deurbel', payload=line, qos=0, retain=False)
  38.  
  39. mclient.pause(1)
  40.  
  41. for i in range(0, 16):
  42. client.loop()
  43.  
  44.  
  45.  
  46. time.sleep(5)
  47.  
  48. mclient.pause(0)
  49.  
  50. mclient.disconnect()
  51.  
  52. client.disconnect()
  53.  
  54. except Exception as e:
  55. print(e)
  56. pass
  57.  
  58. time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement