Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tadakk
Newbie

Re: Scheduled reboot of Roku box using PHP/batch script/etc

Hey guys,
I really like that script. I decided to make a Powershell 3.0 equivalent.

$roku=$args[0]
if ($roku -ne $null) {
  $Error.Clear()
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Home"
  if ($Error.count) {Write-Host "ERROR"; exit}
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Right"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Right"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Right"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Select"
  sleep -Milliseconds 350 
}
else {
  Write-Host "You must specify the IP address"
}

Tommy
0 Kudos
Smokindog
Roku Guru

Re: Scheduled reboot of Roku box using PHP/batch script/etc

"tadakk" wrote:
Hey guys,
I really like that script. I decided to make a Powershell 3.0 equivalent.

$roku=$args[0]
if ($roku -ne $null) {
  $Error.Clear()
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Home"
  if ($Error.count) {Write-Host "ERROR"; exit}
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Right"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Right"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Up"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Right"
  sleep -Milliseconds 350 
  Invoke-RestMethod -Method Post -Uri "http://$($roku):8060/keypress/Select"
  sleep -Milliseconds 350 
}
else {
  Write-Host "You must specify the IP address"
}

Tommy

Could you help explain how to put this into a file and execute it automatically?  I know UNIX and Cron and shell scripts and I can follow that I'd need to set my ROKU IP address but I don't know how to automate on a Windows device.
Thanks in advance!
Brought to you from someplace in Texas!
0 Kudos
ThomasZA
Newbie

Re: Scheduled reboot of Roku box using PHP/batch script/etc

I had to add an additional home command to the beginning, and an additional up... and I've reduced the delays after the initial home  press... and since I only have 1 roku - I moved the IP into the file... but this works for me: (obviously tweak the IP to suit 🙂 )

it just does nothing if its in that annoying "pairing with roku remote" message...

#!/bin/bash
# reboot the specified roku device
ROKU="192.168.1.111"
if [ "$ROKU" != "" ]; then
curl -X POST -d "" http://$ROKU:8060/keypress/Home
if [ "$?" != "0" ]; then echo "ERROR"; unset ROKU; exit $?; fi
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Home
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Right
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Right
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Right
sleep 0.35
curl -X POST -d "" http://$ROKU:8060/keypress/Select
sleep 0.35
fi
unset ROKU

0 Kudos

Re: Scheduled reboot of Roku box using PHP/batch script/etc

These posts helped immensely. Here's a script that makes use of loops to shorten the code. Tested on Roku Ultra and Streaming Stick:

#!/bin/bash
# Date = 04.26.20
# Leveraged some code from https://github.com/chall32/ROKU_restart.sh
# Tested on Roku Ultra & Roku Streaming Stick

ShowUsage() {
echo "usage: $0 <ROKU IP>"
}

EXPECTED_ARGS=1
TARGET=$1
ROKUREBOOT=("home" "up" "right" "up" "right" "up" "up" "up" "up" "right" "select")

if [ $# -lt $EXPECTED_ARGS ]
then
ShowUsage
exit 1
fi

for i in $*
do
case $i in
--help)
ShowUsage
exit 1
;;
esac
done

if [[ -n "$TARGET" ]]
then

curl -d '' http://$TARGET:8060/keypress/home
sleep 3.5

for CMD in ${ROKUREBOOT[@]}
do
curl -d '' http://$TARGET:8060/keypress/$CMD
sleep 0.35

done

fi

0 Kudos