Page 1 of 1

SSDP Discovery

Posted: Fri Oct 10, 2014 12:55 am
by sturgis
Has anyone used livecode to find ssdp devices? (like, roku, apple tv, etc) If so, mind if I ask how you accomplished the task? Preferably cross platform, windows, mac, linux, android. Linux shouldn't be bad, it can be done with shell calls (most likely.)
Same for mac, i'll explore that, but if it can be done internally with livecode, i'd much prefer it!

Thanks in advance for any assistance.

Re: SSDP Discovery

Posted: Wed Oct 15, 2014 7:11 pm
by sturgis
For anyone interested in controlling their roku from a computer or networked device using LC, here are a few things that might help. I'm still interested in the ssdp discovery to make it easier, but so far things are working well.

First, you must know the address of the roku. (hence my wish to understand how to glean it using ssdp)

In my case, this would be

Code: Select all

-- The address of the simple web service for the roku including the default port of 8060
http://192.168.254.7:8060
After that, things are pretty easy. To send a keypress as if from a remote control, use an empty post to the correct URL. In my little app, I have buttons in a group, labeled by the name of the keypress. Back, up, home, left, select, right, down, rev, play, fwd. So, to send the keypress just..

Code: Select all

-- [[tlabel]] is a variable containing the label of the target. IE the clicked button. 
-- so if the label of the clicked button is "select" it merges into.. http://192.168.254.7:8060/keypress/select
post "" to merge("http://192.168.254.7:8060/keypress/[[tLabel]]")
Other things can be done. For example, here is a simple handler to generate data for a datagrid. It requests a list of channels on the roku, then cycles through and gets the icon for each channel. My datagrid (form) is set up to display these channel icons and act on click. So if I click netflix, poof, netflix starts on the roku.

Here the command handler to gather the data.

Code: Select all

command getList
--sAddress contains the address of the roku as mentioned above, and is merged in.
-- this one is not an empty post like the keypresses
   put URL merge("[[sAddress]]/query/apps") into tData
   set the itemdelimiter to quote
  -- the returned format is pretty simple to work with (didn't have to do it as xml, just used livecodes chunking to get what I need)
-- the first line, and the last line are just xml container enclosures so I remove them. 
   delete the first line of tdata
   delete the last line of tdata
-- run a counter for the datagrid index
   put 1 into tCounter

-- repeat for each works great for this
   repeat for each line tLine in tData
      put item 2 of tLine into sDataA[tCounter]["appid"] -- adds the appid to the data array so that it can be used when switching channels
      put URL merge(("[[sAddress]]/query/icon/" & item 2 of tLine)) into sDataA[tCounter]["image"] -- grab the icon for each channel and add to the array
      
      add 1 to tCounter
   end repeat
-- put the data into the already set up datagrid.
   set the dgData of group "channelsgrp" to sdataA
end getList

For the datagrid itself, mousedoubleup is disabled in the datagrid behavior, and here is the mouseup handler to do the channel changing.

Code: Select all

on mouseUp
   put the dgDataOfLine[the dgindex of me] of group "channelsgrp" into theDataA -- grabs the array of data for the clicked line
   put theDataA["appId"] into tId -- pulls the app id out of the array
   post "" to merge("http://192.168.254.7:8060/launch/[[tId]]") -- merges the app id into the empty post to launch the channel associated with the app id
end mouseUp
For anyone interested, more info can be found here: http://sdkdocs.roku.com/display/sdkdoc/ ... trol+Guide
I would also be willing to post my (not pretty) stack if there is any interest.

Again, if anyone has a reliable way to gather ssdp information in a multiplatform way I'd much appreciate it.