Advertisement
PANVICA2

Untitled

Dec 13th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import socket
  2.  
  3. UDP_IP = "0.0.0.0" # listen to everything
  4. UDP_PORT = 12345 # port
  5.  
  6. sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  7. sock.bind((UDP_IP, UDP_PORT))
  8.  
  9. while True:
  10. data, addr = sock.recvfrom(512) # random buffer size, doesn't matter here..
  11. print("received message:", data)
  12. #simplest way to react.. of course, a better parser should be used, and add GPIO code, etc..
  13. if data==b'LED=1\n':
  14. print("LED ON")
  15. elif data==b'LED=0\n':
  16. print("LED OFF")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement