Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
rrosamond
Level 7

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

I am using a Roku to transmit a live stream 24/7 to a TV system which has its connectivity inside a datacenter that's not easily accessible by humans. Due to issues with the Roku freezing after prolonged amounts of time, I want to schedule a proactive nightly reboot using a cronjob or Windows scheduled task. The idea being that if I can make the box reboot and then re-launch the channel with the live stream at a certain time each night, then it's less likely to crash the next day. I need to accomplish this without human intervention. The trouble is, I'm having a difficult time figuring out how to make the Roku actually reboot. While I can do Home (x5), Up, Rev (x2), Fwd (x2) on the remote control to reboot the box, doing so via the RESTful API in my own script or through the remoku.tv interface doesn't seem to reboot the box. Isn't there a way to do this?

I would expect this script to work, but it does not (the commands do what's expected on the Roku screen, but no reboot occurs):

curl -X POST -d "" http://10.0.2.21:8060/keypress/Home
sleep 1
curl -X POST -d "" http://10.0.2.21:8060/keypress/Home
sleep 1
curl -X POST -d "" http://10.0.2.21:8060/keypress/Home
sleep 1
curl -X POST -d "" http://10.0.2.21:8060/keypress/Home
sleep 1
curl -X POST -d "" http://10.0.2.21:8060/keypress/Home
sleep 1
curl -X POST -d "" http://10.0.2.21:8060/keypress/Up
sleep 1
curl -X POST -d "" http://10.0.2.21:8060/keypress/Rev
sleep 1
curl -X POST -d "" http://10.0.2.21:8060/keypress/Rev
sleep 1
curl -X POST -d "" http://10.0.2.21:8060/keypress/Fwd
sleep 1
curl -X POST -d "" http://10.0.2.21:8060/keypress/Fwd
0 Kudos
13 REPLIES 13\
RokuJoel
Roku Employee
Roku Employee

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

Most data centers have remote controlled power strips that can be used to power cycle hardware, that would be using the correct tool for the job. Some are probably accessible via SSH to allow secure rebooting via a chron job.

Another approach: programmable power strip:
http://www.pwrusb.com/powerUSB-smart.html

- Joel
0 Kudos
EnTerr
Level 11

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

Most of the "Konami cheat codes" seem to have been disabled for ECP key-in (vs physical remote) in 2012. Not clear if that was intentional or collateral damage. There has been no explanation/justification from Roku and they never answered direct question from me about ECP reboot either. Can't help but notice RokuJoel is elusive in his answer here
0 Kudos
destruk
Level 10

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

Brightscript has internal support for "Reboot" but that has always been disabled. As the box is designed to be always on, and they thoroughly test and approve public channels to ensure that they do not reboot the box, I don't think they want to allow for it in the firmware, thus the external device power strip control is the most practical option for remote reset.
0 Kudos
BradC
Level 7

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

Well, you could change the z pos of a sprite to a high number to force an instant reboot.

but...you probably want to do something else. Smiley Happy

Like Joel said, if you have a decent data center, you should certainly have remote access to the rack PDU, if not, you could just get a digital timer for like 3 bucks, though convincing a data center to let you put THAT in a rack might be more of a challenge. Starting the channel again after powerup is a bit more complicated.


It might be worth investigating why the roku freezes after a certain amount of time, check the channel you are running to make sure that's not the real cause of the problem, the issue might be fixed more easily by changing a bit of code. Freezing after a period of time might indicate some type of memory leak, if the code can't be fixed, perhaps you could just restart the channel instead of the entire box as a different "fix"?
♦MiniGolf♦HangMan♦Brain Puck♦Retro Tennis♦BORK♦FLIP♦Pathogen♦Pathogen 2♦Shut the Box♦Birdie♦Logic♦Dots♦Pool♦küglo♦Bubble Wrap♦Trivia Channel♦Mancala♦Air Hockey♦Weather♦CAMERA♦Your Photos Screensaver♦Desert Beauty Screensaver♦Wild Lakes Screensaver♦
0 Kudos
geebs
Level 7

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

From a server running cron, send a UDP datagram (netcat or nc) text string to the roku. the roku can have an event listener listening for the text string, and run a shutdown command when it arrives. This gives you the most control as you can execute it whenever you want.

Or completely within the roku player, in your brightscript setup a loop with a timer to check the time every minute, and if current time is within 1 minute of midnright, run shut down command in your brightscript.
0 Kudos
TheEndless
Level 9

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

"geebs" wrote:
From a server running cron, send a UDP datagram (netcat or nc) text string to the roku. the roku can have an event listener listening for the text string, and run a shutdown command when it arrives. This gives you the most control as you can execute it whenever you want.

Or completely within the roku player, in your brightscript setup a loop with a timer to check the time every minute, and if current time is within 1 minute of midnright, run shut down command in your brightscript.

There are no shutdown commands on the Roku Streaming Player. There is a shutdown command in BrightScript, but it only works on the BrightSign. It has been disabled on the streaming players. I used to have a "reboot" channel that exploited a memory bug that would cause the unit to crash, but it has long since stopped working, because that particular memory issue was fixed. There are probably others that you could exploit to accomplish the same, but that's probably not the best method to accomplish a reboot.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
schworak
Level 8

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

Hey, I love that I found your script. It works great but only after a little tweaking. Here is what works for me to cause a reboot. I found that a 1/2 second delay was more than enough. I tried less and things started failing around 1/4 and below. I ultimately settled on 0.35 seconds of delay for the best results.

I run this with the command: bash reboot 192.168.1.103





#!/bin/bash
#
# reboot the specified roku device
#

if [ "$1" != "" ]; then
curl -X POST -d "" http://$1:8060/keypress/Home
if [ "$?" != "0" ]; then echo "ERROR"; exit $?; fi
sleep 0.35
curl -X POST -d "" http://$1:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$1:8060/keypress/Right
sleep 0.35
curl -X POST -d "" http://$1:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$1:8060/keypress/Right
sleep 0.35
curl -X POST -d "" http://$1:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$1:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$1:8060/keypress/Up
sleep 0.35
curl -X POST -d "" http://$1:8060/keypress/Right
sleep 0.35
curl -X POST -d "" http://$1:8060/keypress/Select
sleep 0.35
else
echo "You must specify the IP address"
fi
0 Kudos
destruk
Level 10

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

Well done.
0 Kudos
renojim
Community Streaming Expert

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

You should probably add a few Homes like the original script had; I don't think your script would work if the screensaver is active. Keep in mind that a firmware update could change things in the Settings menu. Also, I don't think this will work for a RokuTV (and possibly Roku 4; I'd have to check).

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos