Advertisement
Tempist

RPi Tactigon Extender

Jul 5th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. # Discord: wizard#7815 | Instagram: @ImWizardly | Twitter: @itsWizardly
  2.  
  3. #!/usr/bin/env python
  4. #UDP SERVER CODE FOR AUTOMATIC BOOTUP
  5. import os
  6. import sys
  7. import socket
  8. import serial
  9. import time
  10.  
  11. UDP_PORT = 5000
  12. UDP_IP = '192.168.4.1' #IP address of the machine to whick this script will run
  13. #small delay to ensure that everithing started up
  14. time.sleep(10)
  15.  
  16. port = serial.Serial("/dev/ttyGS0", baudrate=115200, timeout=0.1)
  17.  
  18. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  19. sock.bind((UDP_IP, UDP_PORT))
  20.  
  21. while ((port.in_waiting) <= 0):
  22.     data, addr = sock.recvfrom(1024) #store received data
  23.     #print(data) #for debug
  24.     port.write(data + '\n') #write received data from UDP to the emulated serial port
  25. #if the input buffer of the serial port is NOT empty that means that the shutdown command has been received from the PC
  26. os.system("shutdown now -h")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement