]> vault307.fbx.one Git - roku.git/commitdiff
roku remote using POST requests via web master
authorjimmy <jimipunk88@gmail.com>
Fri, 28 Jun 2024 01:23:54 +0000 (20:23 -0500)
committerjimmy <jimipunk88@gmail.com>
Fri, 28 Jun 2024 01:23:54 +0000 (20:23 -0500)
rokuPOST.py [new file with mode: 0644]

diff --git a/rokuPOST.py b/rokuPOST.py
new file mode 100644 (file)
index 0000000..cb09916
--- /dev/null
@@ -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)
+"""