An intro to Mender — Part 1
The modern way to update IoT devices.
Mender makes over-the-air (OTA) software and firmware updates easy. Really easy. It’s just not-so-easy to get started.
This tutorial is the first part in a multi-part series on setting up OTA updates for your IoT device using Mender:
- [This part] Setting up a golden device for
Mender. This entails flashing an SD card and getting started with
Raspberry Pi OS(headless, i.e. without monitor/keyboard).
- Part 2 link - Setting up a
Google cloud platform(GCP).
- [TBD] Setting up a device that can be deployed in the field.
- [TBD] Making an image from your current golden device and sending the update to a deployed device.
Sorry for the missing parts for now — I got bored of writing today. Check back soon for the other parts! Or drop me a line if I’m procrastinating too much….
We will be using a
Raspberry Pi Zero WiFi running
Raspberry Pi OS (32-bit) Lite (
Raspbian? When did they rename it?!).
There is some overlap between this article and the setup in another article on getting a headless setup of Raspberry Pi — here we focus on the necessary steps to get Mender up and running.
The magic of Mender for OTA updates
This is the boilerplate text for why OTA updates are so magical with Mender. But if you already knew that, just go ahead and skip on to the next part.
Mender makes IoT device updates easy. There are two types of updates, both of which can be done with Mender:
- Firmware updates — this updates the entire OS.
- Software updates — this updates just some software on your device, e.g. like a Docker container.
In this tutorial I’m gonna focus on the first one — maybe a later one will discuss software updates.
Both firmware and software updates are done by what are called Mender artifacts. For firmware updates, artifacts can be generated from the image of a “golden device”. The way this works is:
- You create a golden device. The golden device will run all of your firmware and software that is needed to make your product go. It will not contain any Mender software.
- You copy over the image of your golden device, and run it through a helpful convertor to generate a ready-to-go Mender artifact.
- You provision devices that will be deployed to the field with your artifact.
- You can see your devices in your hosted Mender server (hosted by you for free, or here for a fee over Google cloud platform (GCP), or otherwise hosted for a fee on Mender’s platform).
- To send firmware updates to devices in the field, simply repeat step (2) and deploy the update by uploading the new artifact to your server.
Easy as that!
Let’s get start creating a golden device. I’ll show you how to set up the Raspberry Pi Zero WiFi without a keyboard or monitor, and how to enable some fancy features that your product may need.
I’ve marked every section with one of:
and you can pick what parts you like.
Headless setup of RPi (required)
We will now setup your Pi without a monitor or keyboard.
You can find more details and options in this article. Here we will only review the necessary steps to get Mender going later.
Mount the SD card on your computer, and navigate to the
Then we can set up the Pi as follows.
You can edit WiFi by making a file called `wpa_supplicant.conf` with contents:
NOTE: this didn’t work for me. I had to set it up later by editing
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf directly as described below. But you can connect to pi using SSH over USB without setting up networking to begin.
NOTE NOTE: The correct way to restart the WiFi is:
sudo wpa_cli -i wlan0 reconfigure
ssh, make empty file simply titled
ssh (no extension) in the
boot partition. You can use the command
touch ssh to do this.
SSH over port USB (required)
To enable USB connection, add to the bottom of `config.txt`:
# Enable USB OTG like ethernet
and to the end of
rootwait such that it reads:
… rootwait modules-load=dwc2,g_ether
Make sure you connect the USB cable to the USB port — not the power port on the Raspberry Pi Zero WiFi!
ssh still does not work later (ugh!) you will have to use a keyboard to enter to pi and run:
sudo systemctl enable ssh.service
which should do it.
Connecting to your device (required)
Now you can connect — find the address:
which should give e.g.
Setup important features (required)
- Check WiFi connects:
- If not, edit
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf:
- Restart WiFi the correct way:
sudo wpa_cli -i wlan0 reconfigure
New user (recommended)
- Make a new user called
sudo adduser joehisashi
- Add to sudo:
sudo adduser joehisashi sudo
- Now log out and back in as
- Delete the
sudo userdel -r pi
- We can add ourselves to
sudoso we don’t need
sudofor a command like
joehisashi ALL=(ALL) NOPASSWD: some_command
at the bottom.
Change hostname (recommended)
- Change the hostname so instead of
ping raspberrypi.localwe can
sudo nano /etc/hostname
such that it reads simply
- This requires a restart to work:
sudo reboot -h now
Now we can ping the device with simply
That’s it! It should be enough to get your “golden”
Raspberry Pi going for your project. In the next part, we will work on setting up the