adrianc1982
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-27-2015
07:11 AM
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:
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 š
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 š
3 REPLIES 3


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-27-2015
10:15 AM
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
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.
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-27-2015
03:56 PM
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.
adrianc1982
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-27-2015
10:22 PM
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!
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!