Hufferduffer Radiodan part 4 – server side Radiodan API and buttons

Update: a step by step how-to is now available.

Server side calls

Andrew has been helping me with server-side radiodan calls. I was close with this commit but this:

radiodan = require('radiodan-client'),
radiodanClient = require('radiodan-client'),
player = radiodan.player.get("default"),
player.add({ clear: true, playlist: url});

should have been:

player = radiodan.player.get("main"),

‘main’ is specified in the config file – you can set your own name for the player, but using this means that you don’t have to touch the (shared) config file (which is here)

Andrew also used cheerio for jQuery-like XML parsing rather than my hack-parsing.

The full API is here, but those docs need updating.


On button

Andrew suggests I just put my button handling code in main.js for now. The code itself is just copied from here, and at the moment we only want it to print something to console with a press of the button. Here’s the commit.

We also need to add the buttons code to monit:

sudo pico /etc/monit/conf.d/radiodan-type-huffduffer

add this at the end:

check process radiodan-buttons with pidfile /var/run/radiodan/
group radiodan
start program = "/usr/sbin/service radiodan-buttons start"
stop program = "/usr/sbin/service radiodan-buttons stop"

sudo monit reload

tail -f /var/log/radiodan-huffduffer.log

and we see "powerButton PRESSED"

[later] Thanks to Andrew it works very nicely, playing when the box is opened, and pausing when it’s closed. The code is here and we’ll use it as fodder for a proper tutorial. I am *well* chuffed. Thanks Andrew.

Here’s the result in action (video).

One thought on “Hufferduffer Radiodan part 4 – server side Radiodan API and buttons

Comments are closed.