Roku Developer Program

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

Working ECP input example?

Does anyone has a working example or ecp for inputs?

Im trying to send a message from java or python to my channel while its running.

my code so far would be something like this:

    while (true)
msg = wait(0, port)

print "type(msg): ",type(msg)
print "msg.GetMessage(): ",msg.GetMessage()

if (type(msg) = "roInput")
print "Got the message: ", msg.url
end if

end while


keypresses up, down, querying apps and home key are working as expected according to the ecp manual, but i cant get any custom message across my channel, it just doesnt show up while waiting for input from the remote...

please help Smiley Sad
0 Kudos
3 Replies
Roku Employee
Roku Employee

Re: Working ECP input example?

The documentation is indeed cryptic.

You need to create an roInput object, call SetMessagePort on it, and look for events of type "roInputEvent".

http://sdkdocs.roku.com/display/sdkdoc/ ... olServices

The external control server places these name-value pairs into a BrightScript associative array and passes them directly through to the currently executing channel script via a Message Port attached to a created roInput object.
...
Messages of type roInputEvent have a GetInfo() method that will obtain the associative array.
0 Kudos
belltown
Level 7

Re: Working ECP input example?

"adrianc1982" wrote:
Does anyone has a working example or ecp for inputs?

Sub Main ()
inputObject = CreateObject ("roInput")
port = CreateObject ("roMessagePort")
inputObject.SetMessagePort (port)
While True
msg = Wait (0, port)
If Type (msg) = "roInputEvent"
info = msg.GetInfo ()
Print info
EndIf
End While
End Sub


The trick to sending an ECP input request is to ensure that you use the HTTP POST verb (not GET), and put the arguments in the QUERY STRING (NOT in the request body). This is a non-conventional practice. Normally, if you have query string arguments with no message body, you'd use a GET request; if you wanted to use a POST request, you'd put the arguments in the body. However, Roku chooses to do things differently, for whatever reason, and you have to make sure you use a POST with a query string and an empty message body.

In Python, for example:

import urllib.parse
import requests

params = {'a': 123, 'b':'Hello, World!'}

r = requests.post ('http://192.168.0.6:8060/input?' + urllib.parse.urlencode (params))


BrightScript Debugger> ------ Running ------
a: 123
b: Hello, World!


Note also that even if an argument had an integer value, it will be received as a roString in your BrightScript code.
https://github.com/belltown/
0 Kudos
adrianc1982
Level 7

Re: Working ECP input example?

Thanks a lot you both, i will try this tomorrow.

Really the documentation is okay, the lack of an example is what fails. For whatever reason i never thought of calling a roInput object..

Thanks! I will report back!
0 Kudos