Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python3
- import os
- import paho.mqtt.client as mqtt
- import serial
- import socket
- import sys
- import time
- from mpd import MPDClient
- while True:
- try:
- with serial.Serial('/dev/ttyUSB0', 115200) as ser:
- line = ser.readline()
- if line[0:4] != 'Init':
- print('%s deurbel!' % time.ctime())
- os.system('/usr/local/sbin/jsb-udpsend -m DEURBELLLLL')
- UDP_IP = "10.208.42.159"
- UDP_PORT = 5001
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- sock.sendto('$f$deurbel!!!'.encode(), (UDP_IP, UDP_PORT))
- client = mqtt.Client('deurbel_%d' % os.getpid())
- client.connect('10.208.11.30', port=1883, keepalive=61, bind_address="")
- mclient = MPDClient() # create client object
- mclient.timeout = 10 # network timeout in seconds (floats allowed), default: None
- mclient.idletimeout = None # timeout for fetching the result of the idle command is handled seperately, default: None
- mclient.connect("slabpi.dhcp.nurd.space", 6600) # connect to localhost:6600
- print(mclient.mpd_version) # print the MPD version
- client.publish('deurbel', payload=line, qos=0, retain=False)
- mclient.pause(1)
- for i in range(0, 16):
- client.loop()
- time.sleep(5)
- mclient.pause(0)
- mclient.disconnect()
- client.disconnect()
- except Exception as e:
- print(e)
- pass
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement