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: 
melat0n1n
Channel Surfer

BrightScript: Open a telnet connection to a HEOS device?

Hello all

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?

 
0 Kudos
8 REPLIES 8
renojim
Community Streaming Expert

Re: BrightScript: Open a telnet connection to a HEOS device?

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.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
melat0n1n
Channel Surfer

Re: BrightScript: Open a telnet connection to a HEOS device?

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?

0 Kudos
renojim
Community Streaming Expert

Re: BrightScript: Open a telnet connection to a HEOS device?

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.  Smiley Happy

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
melat0n1n
Channel Surfer

Re: BrightScript: Open a telnet connection to a HEOS device?

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!

0 Kudos
melat0n1n
Channel Surfer

Re: BrightScript: Open a telnet connection to a HEOS device?

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!

0 Kudos
renojim
Community Streaming Expert

Re: BrightScript: Open a telnet connection to a HEOS device?

You may want to look into timers:

https://developer.roku.com/docs/references/scenegraph/control-nodes/timer.md

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
melat0n1n
Channel Surfer

Re: BrightScript: Open a telnet connection to a HEOS device?

Thank you!

I managed to achieve what I was looking for in a normal Task node, just using a `while` loop and a `sleep()` statement. Is there any deeper benefit to using a Timer node, other than simplifying this? The docs don't specify.

0 Kudos
renojim
Community Streaming Expert

Re: BrightScript: Open a telnet connection to a HEOS device?

I couldn't say, but it's probably the same thing.  It's hard to say what sleep (or anything else) does in the Roku world, but one would think it yields.  I was going to suggest the while loop with sleep, but it seemed too primitive.  Smiley Happy  I'd say go with what works and hope Roku doesn't break it in one of their updates.

There used to be good discussions here about how BrightScript works, but the people doing the most discussing got jobs at Roku where apparently the first thing they tell you is don't help anyone in the developer forum.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos