From 073b6b845fa6f513e017ad2ea0ceb031af516293 Mon Sep 17 00:00:00 2001 From: jimmy Date: Thu, 27 Jun 2024 20:23:54 -0500 Subject: [PATCH 1/1] roku remote using POST requests via web --- rokuPOST.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 rokuPOST.py diff --git a/rokuPOST.py b/rokuPOST.py new file mode 100644 index 0000000..cb09916 --- /dev/null +++ b/rokuPOST.py @@ -0,0 +1,71 @@ +import network, socket, time, requests, gc +from machine import Pin + +ssid='SSID' +password='PSWD' + +url='http://192.168.0.109:8060' + +homeKey='/keypress/home' +upKey='/keypress/up' +downKey='/keypress/down' +leftKey='/keypress/left' +rightKey='/keypress/right' +selectKey='/keypress/select' + +def connect(): + wlan=network.WLAN(network.STA_IF) + wlan.active(True) + wlan.connect(ssid,password) + while wlan.isconnected() == False: + print('Waiting for connection...') + time.sleep(1) + ip=wlan.ifconfig()[0] + print(f'Connected on {ip}') + return ip + +def gccol(): + gc.collect() + +connect() +gccol() + +""" +to use key presses: requests.post(url+keypress), ie, requests.post(url+homeKey) +need to run gcol() after each keypress, memory runs out quick +when setting up buttons, set resistor on board, do not use internal PULL_UP/PULL_DOWN +""" +""" +homebtn=Pin(#,Pin.IN) +upbtn=Pin(#,Pin.IN) +downbtn=Pin(#,Pin.IN) +leftbtn=Pin(#,Pin.IN) +rightbtn=Pin(#,Pin.IN) +selectbtn=Pin(#,Pin.IN) + +while True: + if homebtn.value()==1: + requests.post(url+homeKey) + gccol() + time.sleep(0.2) + if upbtn.value()==1: + requests.post(url+upKey) + gccol() + time.sleep(0.2) + if downbtn.value()==1: + requests.post(url+downKey) + gccol() + time.sleep(0.2) + if leftbtn.value()==1: + requests.post(url+leftKey) + gccol() + time.sleep(0.2) + if rightbtn.value()==1: + requests.post(url+rightKey) + gccol() + time.sleep(0.2) + if selectbtn.value()==1: + requests.post(url+selectKey) + gccol() + time.sleep(0.2) +""" -- 2.47.3