Forum Discussion
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. :smileyhappy:
- melat0n1n4 years agoChannel Surfer
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!
- melat0n1n4 years agoChannel Surfer
Any pointers on how I might periodically poll the socket? I've been playing with the main render thread (main.brs) and getting single outputs, but really I want to poll the socket with a specific command to get updated status from the music player, every second or so (or alternatively, to listen on the socket for responses from the player, since it has the option to send them).
I've been reading up on Tasks as a means to do this, but I'm not having much luck so far and the sample channel isn't particularly helpful. The echo server sample here https://developer.roku.com/en-gb/docs/references/brightscript/components/rostreamsocket.md seems like a starting point too, but I'm not clear how to integrate it into the task/render architecture.
Any hints would be really appreciated!
- renojim4 years agoCommunity Streaming Expert
You may want to look into timers:
https://developer.roku.com/docs/references/scenegraph/control-nodes/timer.md