-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_LED.py
More file actions
38 lines (31 loc) · 1.21 KB
/
server_LED.py
File metadata and controls
38 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from socket import *
import pickle
"""
Script contains two function: serverLED establishes a TCP connection with a
Raspberry PI and sends the most recent changes, the LED states, from the shared
LED queue between main and LED server; server_video creates an UDP connection
for live video streaming of any changes, and updates the queue frames also
shared with main.
"""
server_LED_Port = 6666
HOST = ""
server_video_port = 6669
def serverLED(qled):
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind((HOST,server_LED_Port))
serverSocket.listen(1)
print("[LED_process] LED Server ready for Raspberry PI and web server communication")
rasp_conn, rasp_addr = serverSocket.accept()
print(f"Raspberry PI IP: {rasp_addr}")
while True:
led_states = qled.get() #queue of led states
rasp_conn.send(pickle.dumps(led_states))
def server_video(qframes):
server_video_socket = socket(AF_INET,SOCK_DGRAM)
server_video_socket.bind((HOST,server_video_port))
print("[video_process] Video Server ready.")
while True:
payload = server_video_socket.recvfrom(1000000)
data = payload[0]
data = pickle.loads(data)
qframes.put(data)