I'd like to create a channel for controlling Denon's HEOS devices. The API for this uses a telnet connection, to which commands can be sent to change tracks, volume, etc. Responses include artist and track titles, artwork, etc. (see an overview here).
I'm wondering if it's possible to open a connection via telnet? I found some code here (https://github.com/brightsign/BrightAuthor-Plugins/blob/15e1c44fea574cc9ebb8f52c2051c333c5382603/Tel...) but `roDatagramSender` doesn't appear in the current Roku Developer docs.
Can anyone give me any pointers?
That example is for a BrightSign device which uses BrightScript, but it's not the same as what's used on Roku devices. I'm guessing it's possible with roDatagramSocket, but I don't really know. It might be a fun little project.
Thanks for the suggestion @renojim! It seems as though the full telnet protocol would need to be implemented in BrightScript, which is a bit too steep a task for me, unfortunately!
EDIT: another thought is that the Roku obviously has telnet running locally, since we use it for debugging etc. Perhaps this can be accessed, and a connection made outwardly?
It's actually a lot easier than what you (and I) think (thought). I misspoke, you want to use roStreamSocket. Here's a little example of connecting to the Roku's own port 8080 where you'd run genkey, get some system information, or just send remote button presses:
Sub telnet() print "telnet" di = CreateObject("roDeviceInfo") ipaddrs = di.GetIPAddrs() if ipaddrs.eth0 <> invalid then print "eth0" ipaddr = ipaddrs.eth0 end if if ipaddrs.eth1 <> invalid then print "eth1" ipaddr = ipaddrs.eth1 end if print ipaddr sa = CreateObject("roSocketAddress") sa.setAddress(ipaddr+":8080") print sa.getAddress() ss = CreateObject("roStreamSocket") print ss.setSendToAddress(sa) print ss.getSendToAddress().getAddress() cmd = "press" + chr(10) + "exit" + chr(10) print ss.Connect() print ss.SendStr(cmd) sleep(1000) print ss.ReceiveStr(1024) print ss.Close() sleep(1000) print "Done" End Sub
If you run this you should see something like:
telnet eth0 192.168.0.120 192.168.0.120:8080 true 192.168.0.120:8080 true 11 1GS3DW050934 (Roku 3) >h Home a A u Up c B d Down n Closed Caption r Right g Game l Left j Sleep s Select ? Search f,> Fwd [ Volume Down b,< Rev ] Volume Up p Play \ Volume Mute y InstantReplay ^ Guide i Info ! Power k Back @ PowerOn = Backspace # PowerOff o PlayOnly + Channel Up ~ Input Source - Channel Down t Stop ` Input Source Prev m TellMe w Join e Enter q1-q3 Preset1 - Preset3 :rgybe r=Red, g=Green, y=Yellow, b=Blue, e=Exit *1234vtu true Done
I put in a lot of unnecessary prints to follow the action. All it does is send "press" and then "exit". You can telnet to port 8080 yourself and enter "press" to see what it spits out. Just make sure if you try to run this you're not already running telnet connected to port 8080.
I'm guessing if you've never created a channel/app and sideloaded it you'll have some questions about that.
Wow, that works, thanks so much!! That was a fundamental building block, without which the whole thing would have been a non-starter, so thank you! I've already managed to retrieve artist and track names, and artwork. I'm grafting these into the sample podcast channel as a starting point. Fantastic!