Monday, 10 June 2024

Roberts Radio

Intro

I have recently been having some success in controlling music systems in the house.  I use web pages which allow me to tailor the choice of music and the way it is played.  Although android/iOS apps are available they require some faffing around to achieve resukts and each of them is different.  A web page has just the options I want to use and it is easy to select albums or stream music from my home server.  Previously I have set up the ability to control Denon amplifier, Sonos speakers and Pure Jongo devices.

The last remaining music device which would benefit from home control is a Roberts Radio 94i.  It is a portable radio with wifi interface for music streaming.  My Home Assistant system recognises the radio but doesnt allow me to do much more than turn it on or off.



PoC

Until recently I thought that there wasn't an app to provide remote control, then I came across UNDOK, which is recommended by Roberts and allows you to do all the necessary functions from an iPad.



Roberts don't provide documentation on commands to program the radio.  Functionality is provided a by Frontier Silicon chip and although there isn't a specification, some people have managed to reverse engineer their software api so that FS devices can be controlled.

I have had a lot of success recently using a TP-link monitor port and an iPad ethernet cable which allow me to monitor network traffic from the iPad using wireshark.  I started monitoring UNDOK traffic between the iPad (192.168.0.200) and Roberts Radio  (192.168.0.54) and found that communication uses HTTP GET commands with XML responses.


HTTP GET commands are easy to use, you can enter them directly into a browser and see the response, for example the power off command puts Roberts into standby and gives an "FS_OK" response:


I was hoping to use Javascript for programming but I soon fell foul of CORS (Cross-Origin Resource Sharing) as the Roberts Radio  (RR) doesn't permit it (perfectly normal) and I quickly decided to use a python back-end which generally works well for me.

After a little experimentation I found that the fsapi-tools python library "fsapi.net" establsihes communication easily with RR:


I found that it doesn't have all the functionality I want, in particular I am unable to view or change presets using fsapi.net.  
For more general controls we can use the HTTP GET requests which we identified in Wireshark.
To do this we use python “requests” library to submit a request.
Since the output is in XML format we use “xmltodict” to decode the XML response.



Programming


As usual we setup a python command with arguments to define the request.  The response from python is a print statement formatted as XML to pass back to the web page:
Using the fsapi.net api programming for power (and volume) is very simple:
To view / change the preset we use a HTTP GET request:

Now we can set up a web page to control Roberts:
In Javascript we can invoke the python commands using websockets.  For example four commands are issued to update the power/volume/muted/preset current status:
Python responses are received back via the web socket and processed in Javascript to update the web page:

Conclusion


It isn't a simple task to program device apis.  However the use of wireshark to decode what apps are sending to the devices is much much easier than looking at api specifications.  I wouldn't have been able to work out how to control the Roberts Radio without looking in detail at how UNDOK manages it.









No comments:

Post a Comment