DEV Community

Dave Glover for Microsoft Azure

Posted on • Updated on

Azure IoT Edge on Raspberry Pi Buster plus tips for Raspberry Pi 4

Azure IoT Edge on Raspberry Pi Buster plus tips for Raspberry Pi 4

Raspberry Pi 4 with Fan SHIM

Useful References

  1. Azure IoT Edge
  2. Azure Custom Vision

Raspberry Pi 4

If you are anything like me, then you too couldn't resist the Raspberry Pi 4 4GB goodness. I wanted to improve the inference performance of my favourite Machine Learning project - Creating an image recognition solution with Azure IoT Edge and Azure Cognitive Services.

As a rough guide, the inference performance of my Azure Custom Vision model was as follows:

  1. Raspberry Pi 4 4GB - 720 Milliseconds
  2. Raspberry Pi 3B Plus - 1.2 Seconds
  3. Intel Core i5-8250U (Surface Laptop 2) - 230 Milliseconds

Raspbian Buster

With the release of the Raspberry Pi 4 the Raspberry Pi Foundation has moved from Raspbian Stretch to Buster (Debian 10) as the default Linux distribution for all Raspberry Pis. For now, at least, it's busted a few things. So here are some tips and tricks for running Azure IoT Edge on a Raspberry Pi running Raspbian Buster.

Installing Raspbian Buster

This article is not intended as a guide to getting started with Raspberry Pi or Azure IoT Edge. For more information on those topics then read the following articles.

  1. My Creating an image recognition solution with Azure IoT Edge and Azure Cognitive Services project is a great place to get started with Azure IoT Edge.

  2. I typically run Raspbian Lite (Headless). Check out this guide "HEADLESS RASPBERRY PI 3 B+ SSH WIFI SETUP (MAC + WINDOWS)".

Azure IoT Edge on Raspbian Buster

Raspberry Pi 4 Tips

  1. Cooling your Raspberry Pi 4
  2. Booting your Raspberry Pi 4 from USB 3 Flash or SSD drive

Azure IoT Edge and Raspbian Buster Tips

  1. Installing Docker on Raspbian Buster
  2. Installing Azure IoT Edge on Raspbian Buster

Cooling your Raspberry Pi 4

The Raspberry Pi 4 runs hot and you will likely need to provide some active cooling to prevent thermal throttling.

I like the Pimoroni case and Fan SHIM, it is a nice compact solution. Note, I have no affiliation with Pimoroni, I'm just a fan (pun intended, groan). There are other cool solutions for Raspberry Pi 4 too. Check out the Raspberry Pi 4 Thermals and Fan Shim article.

Fan SHIM

Install the Fan SHIM Software

Check out the Getting Started with Fan SHIM article. In summary, install git and pip3 support, clone the Fan SHIM GitHub repo, install the dependencies, and then set up the automatic temperature monitor service that turns the fan on as required.

sudo apt install -y git sudo python3-pip && \
git clone https://github.com/pimoroni/fanshim-python && \
cd fanshim-python && \
sudo ./install.sh && \
cd examples && \
sudo ./install-service.sh --on-threshold 65 --off-threshold 55 --delay 2

Booting from a USB 3 Flash or SSD Drive

The benefit of booting from USB 3 depends on how disk IO intensive your Azure IoT Edge Solution is. The Raspberry Pi 4 introduces vastly improved USB support and disk IO performance is impressive when combined with a USB 3 SSD drive. Check out the USB 3 Flash and SSD Disk Performance numbers I recorded.

USB booting your Raspberry Pi from with Beta Firmware (May 2020)

How to Boot Raspberry Pi 4 From a USB SSD or Flash Drive


Installing Docker on Raspbian Buster

curl -sSL get.docker.com | sh && sudo usermod pi -aG docker && sudo reboot

Installing Azure IoT Edge on Raspbian Buster

Review how to Install the Azure IoT Edge runtime on Debian-based Linux systems.

SSL Library libssl1.0.2

Buster does not ship with the require libssl1.0.2 library. As an interim workaround install this library before installing IoT Edge.

sudo apt-get install libssl1.0.2
curl https://packages.microsoft.com/config/debian/stretch/multiarch/prod.list > ./microsoft-prod.list && \
sudo cp ./microsoft-prod.list /etc/apt/sources.list.d/ && \
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg && \
sudo cp ./microsoft.gpg /etc/apt/trusted.gpg.d/ && \
sudo apt-get update && \
sudo apt-get -y install iotedge

Add IoT Edge Connection String

sudo nano /etc/iotedge/config.yaml

Restart Azure IoT Edge

sudo systemctl restart iotedge

SSH Authentication with private/public keys

ssh login

Setting up public/private keys for SSH login and authentication is very handy (and secure).

The following creates a new SSH key, copies the public key to the Raspberry Pi. Take the default options.

From Windows

  1. Use the built-in Windows 10 (1809+) OpenSSH client. First install the OpenSSH Client for Windows (one time only operation).

    From PowerShell as Administrator.

Add-WindowsCapability -Online -Name OpenSSH.Client
  1. From PowerShell, create a key pair.
ssh-keygen -t rsa
  1. From PowerShell, copy the public key to your Raspberry Pi
cat ~/.ssh/id_rsa.pub | ssh pi@raspberrypi.local "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"

From Linux, macOS, and the Windows Subsystem for Linux

  1. Create your key. Typically a one time operation.
ssh-keygen -t rsa
  1. Copy the public key to your Raspberry Pi. From Linux and macOS.
ssh-copy-id pi@raspberrypi.local

Tools

tools

Torrent Tool for Windows (fastest way to download Raspbian Images)

USB 3 Flash and SSD Disk Performance

For reference, these are performance stats I recorded for various drives using the performance tool found at Raspberry Pi Storage Benchmarks 2019

SD Card SanDisk Ultra 16GB

     Category                  Test                      Result
HDParm                    Disk Read                 40.22 MB/s
HDParm                    Cached Disk Read          39.47 MB/s
DD                        Disk Write                17.8 MB/s
FIO                       4k random read            2614 IOPS (10457 KB/s)
FIO                       4k random write           296 IOPS (1186 KB/s)
IOZone                    4k read                   8669 KB/s
IOZone                    4k write                  2808 KB/s
IOZone                    4k random read            8609 KB/s
IOZone                    4k random write           1480 KB/s

                          Score: 923

PNY 128

     Category                  Test                      Result
HDParm                    Disk Read                 98.99 MB/s
HDParm                    Cached Disk Read          70.08 MB/s
DD                        Disk Write                21.6 MB/s
FIO                       4k random read            2238 IOPS (8953 KB/s)
FIO                       4k random write           116 IOPS (464 KB/s)
IOZone                    4k read                   16067 KB/s
IOZone                    4k write                  2204 KB/s
IOZone                    4k random read            7747 KB/s
IOZone                    4k random write           461 KB/s

                          Score: 860

SanDisk Ultra 64 GB

     Category                  Test                      Result
HDParm                    Disk Read                 551.09 MB/s
HDParm                    Cached Disk Read          77.30 MB/s
DD                        Disk Write                55.0 MB/s
FIO                       4k random read            994 IOPS (3976 KB/s)
FIO                       4k random write           312 IOPS (1250 KB/s)
IOZone                    4k read                   17479 KB/s
IOZone                    4k write                  1616 KB/s
IOZone                    4k random read            4052 KB/s
IOZone                    4k random write           1005 KB/s

                          Score: 1087

ASMT - Model: 1153 - USB 3 SSD

     Category                  Test                      Result
HDParm                    Disk Read                 297.42 MB/s
HDParm                    Cached Disk Read          264.49 MB/s
DD                        Disk Write                69.0 MB/s
FIO                       4k random read            15019 IOPS (60076 KB/s)
FIO                       4k random write           8239 IOPS (32957 KB/s)
IOZone                    4k read                   36059 KB/s
IOZone                    4k write                  27480 KB/s
IOZone                    4k random read            20925 KB/s
IOZone                    4k random write           33354 KB/s

                          Score: 6939

Top comments (1)

Collapse
 
bengkel profile image
Bengkel • Edited

I followed this tutorial. IoTEdge does not work on Raspberry Pi 4 or 3 with buster. The edgeHub container never runs, edgeAgent throws exceptions:

"Microsoft.Azure.Devices.Edge.Util.InvalidSchemaVersionException: Invalid desired properties schema version 1,0
at Microsoft.Azure.Devices.Edge.Util.SchemaVersionHelper.CompareMajorVersion(Version expectedVersion, String actualVersionString, String context) in /home/vsts/work/1/s/edge-util/src/Microsoft.Azure.Devices.Edge.Util/SchemaVersionHelper.cs:line 12"