lichtorgel/lichtorgel_udp/sender.py

48 lines
1.1 KiB
Python
Raw Permalink Normal View History

2019-04-06 09:57:15 +00:00
import socket
import time
import random
UDP_IP = "192.168.178.31"
#UDP_PORT = 4210
#UDP_IP = "195.160.169.73"
UDP_PORT = 4210
print("UDP target IP:", UDP_IP)
print("UDP target port:", UDP_PORT)
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
def setLights(outputsB,outputsA):
message=chr(int(outputsB, 2))+chr(int(outputsA, 2))
sock.sendto(message.encode(), (UDP_IP, UDP_PORT))
setLights("00000000","00000000") #00000000 00000001 -> erster port (orange). .. 00100000 -> 6. port
time.sleep(1)
setLights("00000000","00000001")
time.sleep(1)
setLights("00000000","00000010")
time.sleep(1)
setLights("00000000","00000100")
time.sleep(1)
setLights("00000000","00001000")
time.sleep(1)
setLights("00000000","00010000")
time.sleep(1)
setLights("00000000","00100000")
time.sleep(1)
setLights("00000000","00000000")
while True:
outA="00000000"
outB=bin(random.randint(0,1)+random.randint(0,1)*2+random.randint(0,1)*4+random.randint(0,1)*8+random.randint(0,1)*16+random.randint(0,1)*32)
setLights(outA,outB)
time.sleep(0.5)