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: 
adrianc1982
Visitor

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 😞
0 Kudos
3 REPLIES 3
RokuKC
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
Roku Guru

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.
0 Kudos
adrianc1982
Visitor

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
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.