Fireplace on a Raspberry Pi

A fireplace display in a dark-wood decorated room

After not too much work, I was able to finish up the fireplace in our front room. This was a small hack involving a Raspberry Pi. I’ll summarize what worked and then share a few thoughts on what didn’t.

What worked

Here’s the quick summary:

  1. Formatted a new Raspberry Pi 4B with a fresh OS install.
  2. In the Raspberry Pi settings, set boot to console.
  3. Set up a default fireplace user, install a 5-minute loopable video of a fireplace, and write a tiny script to invoke it. This lives in the /home/fireplace/kiosk/play-fireplace.sh directory.
#!/usr/bin/sh

cvlc -Lf fireplace-5min.mp4

I can test this here and confirm it works.

  1. Set up a systemd service to auto-launch the fireplace on boot: create a small script at /home/fireplace/kiosk/service-config/fireplace.service
[Unit]
Description=fireplace

[Service]
Type=simple
WorkingDirectory=/home/fireplace/kiosk
User=fireplace
Environment="XDG_RUNTIME_DIR=/run/user/1000"
Environment="DISPLAY=:0"
ExecStart=/home/fireplace/kiosk/play-fireplace.sh
Restart=always

[Install]
WantedBy=multi-user.target

Why multi-user.target here? Because since we never actually launch to a GUI, graphical.target isn’t invoked.

  1. Set up a little install script. `/home/fireplace/kiosk/service-config/install.sh
#!/bin/bash

sudo cp fireplace.service /etc/systemd/system/fireplace.service
sudo chown root:root /etc/systemd/system/fireplace.service
  1. Run that script!
  2. sudo systemctl enable fireplace — set fireplace to launch on startup
  3. sudo systemctl start fireplace

And we’re good! Fireplace grabs graphics and fires up.

What didn’t work

I originally tried setting this up with a browser in kiosk-mode and a small HTML page to play the video. I encountered a few problems here:

  1. The rules for Chromium auto-playing videos have become completley Draconian. There used to be a command-line flag you could pass to make it happen, but it doesn’t seem to work anymore. I gave up and switched to Firefox.
  2. On this configuration, both webgl and playing videos in Chromium and Firefox caused truly awful screen-tearing. I suspect if I’d played around with a lot of flags and switches, I could have improved performance, but where’s the fun in that?
  3. For reasons I was never able to sort out, startx wouldn’t work over an SSH connection without all of the /dev/tty* devices set to g+r permission. I wasn’t able to suss out why Xorg would care about TTY permissions, but it was necessary to grant that permission to unstick it.

Anyway, if one wanted to go this road, the command that was closest to working was

startx /usr/bin/firefox --width 1920 --height 1080 --use-gl=egl --noerrdialogs --disable-infobars --kiosk "${URL}" --autoplay-policy=no-user-gesture-required -- -nocursor
!
VLC is unfairly good. When I get time, I really should look into how it works successfully without even launching an X11 session. I’m not sure if it’s grabbing the video hardware directly or if it’s detecting a lack of X11 session and launching its own, but wow is it convenient to not have to care about that layer of abstraction!

The only issue is that the webgl shader I’ve been working on can’t be played directly since I don’t have a browser that won’t tear awfully. I might re-tool it into an OpenGL shader running closer to native code and see if that works… Or I might record 10 minutes of video on a more powerful machine and just let VLC play it!

Comments