]> vault307.fbx.one Git - roku.git/blob - rokuPOST.py
roku remote using POST requests via web
[roku.git] / rokuPOST.py
1 import network, socket, time, requests, gc
2 from machine import Pin
3
4 ssid='SSID'
5 password='PSWD'
6
7 url='http://192.168.0.109:8060'
8
9 homeKey='/keypress/home'
10 upKey='/keypress/up'
11 downKey='/keypress/down'
12 leftKey='/keypress/left'
13 rightKey='/keypress/right'
14 selectKey='/keypress/select'
15
16 def connect():
17 wlan=network.WLAN(network.STA_IF)
18 wlan.active(True)
19 wlan.connect(ssid,password)
20 while wlan.isconnected() == False:
21 print('Waiting for connection...')
22 time.sleep(1)
23 ip=wlan.ifconfig()[0]
24 print(f'Connected on {ip}')
25 return ip
26
27 def gccol():
28 gc.collect()
29
30 connect()
31 gccol()
32
33 """
34 to use key presses: requests.post(url+keypress), ie, requests.post(url+homeKey)
35 need to run gcol() after each keypress, memory runs out quick
36 when setting up buttons, set resistor on board, do not use internal PULL_UP/PULL_DOWN
37 """
38 """
39 homebtn=Pin(#,Pin.IN)
40 upbtn=Pin(#,Pin.IN)
41 downbtn=Pin(#,Pin.IN)
42 leftbtn=Pin(#,Pin.IN)
43 rightbtn=Pin(#,Pin.IN)
44 selectbtn=Pin(#,Pin.IN)
45
46 while True:
47 if homebtn.value()==1:
48 requests.post(url+homeKey)
49 gccol()
50 time.sleep(0.2)
51 if upbtn.value()==1:
52 requests.post(url+upKey)
53 gccol()
54 time.sleep(0.2)
55 if downbtn.value()==1:
56 requests.post(url+downKey)
57 gccol()
58 time.sleep(0.2)
59 if leftbtn.value()==1:
60 requests.post(url+leftKey)
61 gccol()
62 time.sleep(0.2)
63 if rightbtn.value()==1:
64 requests.post(url+rightKey)
65 gccol()
66 time.sleep(0.2)
67 if selectbtn.value()==1:
68 requests.post(url+selectKey)
69 gccol()
70 time.sleep(0.2)
71 """