Particle for Linux with the MagicMirror² project
Remotely manage your Raspberry Pi-powered smart mirror deployment.


Ready to build your IoT product?
Create your Particle account and get access to:
- Discounted IoT devices
- Device management console
- Developer guides and resources
The MagicMirror² project is an open source modular dashboard. It provides an easy way to display widgets such as weather, calendar, news, and more on a wall-mounted screen. Let’s explore how we can use Particle for Linux to remotely manage our MagicMirror² deployment. For this tutorial, we’ll be using a Raspberry Pi 4B and a 10.1” LCD display, but the technique can be carried over to alternate hardware. You can view the CAD for the 3D-printed frame for the LCD display here.
This will assume you already have Raspberry Pi OS Desktop mode installed and running on your Raspberry Pi.
It’s important to use the Desktop variant as the MagicMirror² project will need it to interact with the display drivers.
Configure a Linux product on Particle Cloud
We should first set up a Linux product in your Particle Console. Log in to the console and create a new product. This product can exist either at the Sandbox level or organization level.
Give your product a name and description (optional), then select “Linux (Wi-Fi)” as the device type.
Install Particle for Linux
Next, we’ll need to install the Particle for Linux CLI on the Raspberry Pi. You can do this by running the following command on your device.
bash <( curl -sL https://particle.io/install-linux.sh )
Note that this script should be ran directly on the Raspberry Pi and not from an SSH session.
If you pay attention to the log output, you’ll notice that Docker gets installed (if not already installed) along with the Particle CLI. Docker is how the Particle subsystem manages the applications that are running on your Linux device.
Once the setup script completes, you’ll be prompted to click a link that will link your Raspberry Pi with the Particle product you just created.
This should complete with output similar to what’s shown below. Follow the link from the Raspberry Pi to complete the onboarding process.
Starting interactive setup... To finish setting up your device with Particle, open the link below with your browser. You'll be prompted to log in to your Particle account or create one, and select a Particle product for your device. A product will help manage the device and keep things organized. https://setup.particle.io/linux?code=xxxx
In the web browser, you’ll be greeted with a few prompts that will require you to be logged into Particle. Log in, and click through the prompts making sure to select the Linux product you created in the previous step.
Configure tooling
Next, we’ll need to install the Particle CLI on our device in order to deploy our apps to the Particle Console. To do this run the following command:
bash <( curl -sL https://particle.io/install-cli )
Once that command completes, make sure the bin
folder (where Particle CLI was just installed) has been added to your PATH
by running the following:
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
Ensure the CLI was successful by running:
particle --version
You should see some output indicating a version number. At the time of this writing, the installed version is 3.35.8
.
Finally, we need to set a system configuration for the MagicMirror² project to work properly on the device. Running the following commands will give Docker access to the graphical session.
export DISPLAY=:0 xhost +local:docker
This will need to be ran each time the Raspberry Pi reboots. It’s recommended to configure a systemd autostart script (see later section).
After these steps, we’re mostly finished with any local Raspberry Pi develop and can complete the remaining steps from a development computer.
Configure the Particle MagicMirror² project
We can start to configure our MagicMirror²’s modules to suite our preferences. Start by cloning the Particle MagicMirror² repository to any computer that has the Particle CLI installed.
Your development environment can be totally separate from the Raspberry Pi! Particle will manage deploying the app to your device.
git clone https://github.com/epietrowicz/particle-magic-mirror.git cd particle-magic-mirror
On your development computer, make sure to log into the CLI with:
particle login
Open particle-magic-mirror/magic-mirror/config/config.js
in a text editor of your choice and make any changes you’d like per the MagicMirror² documentation.
Once you’re happy with your changes, you can run the following command to push the app to your Raspberry Pi:
particle app push
The very first time you run this command, the CLI will ask some details about which device to target. Choose the organization (or sandbox) and product you created earlier.
You should then see the Particle MagicMirror² container start to build. Depending on your network connectivity and host computer you are using, this might take a while. Thankfully, it will only have to be done once.
Once completed, you should see the sample configuration on displayed on your screen! Note that this might take a few minutes the very first time.
You can imagine how powerful this experience would be if you have dozens of Raspberry Pis deployed and you’d like the push a new app update. Simply run a particle app push
and every device in your product will receive the latest app update.
From here on out, you can make changes to the config.js
file from your development computer and run particle app push
to get the app changes synced to the device, wherever it may be.
Debugging a deployment
If you run into any issues, you can view the container’s logs using the Particle Console’s remote shell.
Go to Particle Console and open a new shell instance on your Raspberry Pi:
Run the following command to list all containers:
docker ps -a
Then, copy the most recent container instance’s ID and run:
docker logs <container_id>
You can also view information about various applications that are running on your device in the “applications” tab of the Particle Console.
Common problems
If you’re building the application on the Raspberry Pi itself (particle app push
on the Raspberry Pi) and are getting a Docker permission denied error:
Building application... ERROR: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Head "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied Failed to build container particleapp/magic-mirror:d74e13ad-3fc4-4ce7-be73-0b4527b0705f. See the Docker output for details: Command failed with exit code 1: docker --config /home/eric/.particle/docker build magic-mirror --platform linux/arm64 --tag particleapp/magic-mirror:d74e13ad-3fc4-4ce7-be73-0b4527b0705f
Run:
sudo usermod -aG docker $USER newgrp docker
If you get the error along the lines of “Missing X server or $DISPLAY:”
[38:0506/194443.866154:ERROR:ozone_platform_x11.cc(246)] Missing X server or $DISPLAY [38:0506/194443.866198:ERROR:env.cc(257)] The platform failed to initialize. Exiting. /app/node_modules/electron/dist/electron exited with signal SIGSEGV
Run the below command, or jump to the “Configuring a start up service” section.
export DISPLAY=:0 xhost +local:docker
Make sure to run this command as a logged in user, not as root! You can do this via the Particle shell with the following:
sudo su <your_pi_account>
Configuring a startup service
Startup script:
nano /usr/local/bin/startup-script.sh
#!/bin/bash echo "Starting magic mirror..." >> ~/startup.log export DISPLAY=:0 xhost +local:docker echo "Started magic mirror project!" >> ~/startup.log
Make it executable:
sudo chmod +x /usr/local/bin/startup-script.sh
Create the service:
sudo nano /etc/systemd/system/startup.service
Paste the following:
[Unit] Description=Allow Docker to access X11 After=graphical-session.target Wants=network-online.target [Service] Type=simple ExecStart=/usr/local/bin/startup-script.sh User=eric Restart=on-failure [Install] WantedBy=multi-user.target
Enable and start the service:
sudo systemctl daemon-reexec sudo systemctl enable startup.service sudo systemctl start startup.service
Ready to get started?
Learn more about Particle for Linux.
