Tohora - instant web page control for balenaDash

7 Mar 2019

Meta meta tohora.320x320

A post introducing a recent hobby project of mine.

Last year I changed jobs and stopped working with digital signage. What do you know, though: the office I now sit in, at the super-nice Bradfield Centre, has a display on the wall, so I felt sort of obligated to get something running behind it.

Not literally behind it - although a Raspberry Pi is pretty small, it’s proved rather difficult to wedge behind the monitor. Anyway, this post is about software - about what we’ve got running on the Pi.

I’ve worked with balenaCloud before, back in the days when it was resin.io. Not entirely coincidentally, quite a while back I spent a few days working alongside Alexandros, founder of balena. It’s an excellent system for running code on fleets of connected devices, a delight to work with.

I discovered balenaDash while burning an SD card to go into the RasPi. The claim was true: within 30 minutes, we had a cheap device that booted up and rendered a web page on the HDMI-connected monitor. Job done.

Only I wanted more control, or rather, snappier control. The way balena works is like this: if you want to change the URL, you change a device variable called WPE_URL.

Edit WPE_URL to change what’s displayed

Since balena is all about IoT, you can do this from anywhere (there’s a easy-to-use API and a cli for it too). The docker container on the device is restarted as a result, and that takes at least a couple of minutes (on our RasPi 3B+, anyway). That’s really too long, especially since the web browser is fairly quick to render pages. Also, the process never attempts to reload the URL, so only pages that “update themselves” stay updated.

I’m not the first to try something more on the platform: see dashboards (“performance will be limited on Raspberry Pi devices”) and commercial offerings exist - screenly.

It felt really do-able, though, so I posted on the forum. Another plus for balena: I had a reply from the team very quickly. In the end, I went my own way: but the responsiveness was great.

Opening a terminal inside the wpe container was easy - another mind-blowing feature of the balena platform. I discovered that if I ran WPELauncher https://www.rmorrison.net then my website appeared on screen pretty much instantly. W00t!

Balena makes it easy to try things out, inside your container, from anywhere

After a Ctrl+C, the process exited and the screen returned to showing what it had been before.

OK, I thought - I just need to run a webserver to start and stop a subprocess. Then I can use balena’s public URL feature to control what’s on screen through a web browser. Tricky thing was though, the container is based on a stripped-back OS with no easy way for a web dev like me to get out good old python or nodejs.

So I had my first go at Go. The plan was: code and try stuff out on my Mac, then simply compile for ARM and a single binary would deliver everything. Honestly, I’d never written more than “Hello World” in Go before, but it delivered a great developer experience and I got there. I definitely eliminated some noobie mistakes on the way, and it’s probably still got plenty, but…

Introducing Tohora

Tohora is the result. (I renamed it with a whale-y name after “screenserve” seemed like it might be taken).

Tohora puts balenaDash under the instant control of anything that can talk http. That includes Slack, and curl, and web browsers. In this video I demo how to put a couple of pages up using my browser (the “Hello World” page is our base, it’s what WPE_URL is pointing at):

Getting pages on screen is easy: use browser or Slack.

I’ve submitted a pull request to balena to see if they feel like including it right into balenaDash. If included but unused, the impact of the extra webserver process is invisible and minimal.

Tohora displays URLs on balenaDash in an instant.

Next steps and ideas

We’ve been using Tohora for a few days and I’m proud of it. We regularly ‘fling’ pages up, discuss them, laugh at them or examine them, and then drop back to our dashboard. Being able to do it from Slack is fun and convenient.

I would like to know whether we can drive the display at 4k from the Raspberry Pi (1080p at the moment). Contact me if you know a way! Or if you know of a cheapish device that will run balenaDash and output at 4k.

Ideas for new features keep coming up. Remembering URLs is already done (just locally, for convenient action replays), and I might enabling a ‘bookmarks’ feature for double quick Slack-to-screen (we already bring up the lunch menu from downstairs using a cron job every day at the right time).

Also I would love to hear from you if you use Tohora: for any suggestions, discussions or issues, please use Github.

Richard Morrison, March 2019

Tags: digital, signage, code