-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreq.py
More file actions
22 lines (17 loc) · 659 Bytes
/
Copy pathreq.py
File metadata and controls
22 lines (17 loc) · 659 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import serial
import requests
import time
URL = 'http://YOUR_IP_ADDRESS/device/rgb/'
ser = serial.Serial('COM7', 9600)
while True:
r, g, b = ser.readline().strip().split()
print(r, g, b)
print("-----------------------------------")
with requests.Session() as s:
s.get(URL, timeout=60)
response = s.post(URL, data={'red': r, 'green': g, 'blue': b}, timeout=60,
headers={'X-CSRFToken': s.cookies.get('csrftoken'),
'Referer': URL})
if response.status_code != 200:
print(f"{response.status_code}: Can not send the rgb data")
time.sleep(1.5)