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:
Mender
. This entails flashing an SD card and getting started with Raspberry Pi OS
(headless, i.e. without monitor/keyboard).Mender
server on Google cloud platform
(GCP).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.
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:
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:
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:
required
recommended
optional
and you can pick what parts you like.
Get the latest Raspberry Pi OS Lite image here. I used:
Raspberry Pi OS (32-bit) Lite
Minimal image based on Debian Buster
Version: May 2020
Release date: 2020–05–27
Kernel version: 4.19
Size: 432 MB
Get balenaEtcher
here and flash an SD card with the image.
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 boot
partition.
Then we can set up the Pi as follows.
You can edit WiFi by making a file called wpa\_supplicant.conf
with contents:
ctrl\_interface=DIR=/var/run/wpa\_supplicant GROUP=netdev
update\_config=1
country=US
network={
ssid=”YOURSSID”
psk=”YOURPASSWORD”
}
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 (required) ——————
To enable ssh
, make empty file simply titled ssh
(no extension) in the boot
partition. You can use the command touch ssh
to do this.
To enable USB connection, add to the bottom of config.txt
:
# Enable USB OTG like ethernet
dtoverlay=dwc2
and to the end of cmdline.txt
after 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!
If 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.
Now you can connect — find the address:
ping raspberrypi.local
which should give e.g. 169.254.29.31
, then:
ssh pi@169.254.29.31
password: raspberry
ping 8.8.8.8
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
:ctrl\_interface=DIR=/var/run/wpa\_supplicant GROUP=netdev
update\_config=1
country=US
network={
ssid=”YOURSSID”
psk=”YOURPASSWORD”
}
sudo wpa\_cli -i wlan0 reconfigure
New user (recommended) ————————–
joehisashi
with password abc123
:sudo adduser joehisashi
password: abc123
sudo adduser joehisashi sudo
joehisashi
.pi
usersudo userdel -r pi
sudo
so we don’t need sudo
for a command like some_command
:joehisashi ALL=(ALL) NOPASSWD: some\_command
at the bottom.
ping raspberrypi.local
we can ping ghibli.local
.sudo nano /etc/hostname
such that it reads simply
ghibli
sudo reboot -h now
Now we can ping the device with simply
ping ghibli.local
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 Mender
server.
Oliver K. Ernst
July 11, 2020