Azure IoT Edge on Raspberry Pi Buster plus tips for Raspberry Pi 4
Tags: raspberrypi, azure, iot, buster
Published: 2019-08-01 03:59:59

---
title: Azure IoT Edge on Raspberry Pi Buster plus tips for Raspberry Pi 4
published: true
description: Tips and tricks for running Azure IoT Edge on Raspberry Pi Raspbian 
tags: raspberrypi, azure, iot, buster
---
# Azure IoT Edge on Raspberry Pi Buster plus tips for Raspberry Pi 4

![Raspberry Pi 4 with Fan SHIM](https://raw.githubusercontent.com/gloveboxes/Azure-IoT-Edge-on-Raspberry-Pi-Buster/master/resources/rpi4.jpg)

## Useful References

1. [Azure IoT Edge](https://azure.microsoft.com/en-au/services/iot-edge?WT.mc_id=devto-blog-dglover)
2. [Azure Custom Vision](https://azure.microsoft.com/en-au/services/cognitive-services/custom-vision-service?WT.mc_id=devto-blog-dglover)

## 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](https://dev.to/azure/creating-an-image-recognition-solution-with-azure-iot-edge-and-azure-cognitive-services-4n5i).

As a rough guide, the inference performance of my [Azure Custom Vision](https://azure.microsoft.com/en-au/services/cognitive-services/custom-vision-service/?WT.mc_id=devto-blog-dglover) 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](https://www.raspberrypi.org/) 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](https://docs.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-edge-linux?WT.mc_id=devto-blog-dglover) 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](https://dev.to/azure/creating-an-image-recognition-solution-with-azure-iot-edge-and-azure-cognitive-services-4n5i) 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)](https://desertbot.io/blog/headless-raspberry-pi-3-bplus-ssh-wifi-setup)".

## Azure IoT Edge on Raspbian Buster

### Raspberry Pi 4 Tips

1. [Cooling your Raspberry Pi 4](#cooling-your-raspberry-pi-4)
2. [Booting your Raspberry Pi 4 from USB 3 Flash or SSD drive](#booting-from-a-usb-3-flash-or-ssd-drive)

### Azure IoT Edge and Raspbian Buster Tips

1. [Installing Docker on Raspbian Buster](#installing-docker-on-raspbian-buster)
2. [Installing Azure IoT Edge on Raspbian Buster](#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](https://shop.pimoroni.com/products/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](https://blog.pimoroni.com/raspberry-pi-4-thermals-and-fan-shim/) article.

![Fan SHIM](https://raw.githubusercontent.com/gloveboxes/Azure-IoT-Edge-on-Raspberry-Pi-Buster/master/resources/fan-shim.jpg)

### Install the Fan SHIM Software

Check out the [Getting Started with Fan SHIM](https://learn.pimoroni.com/tutorial/sandyj/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.

```bash
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](#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](https://www.tomshardware.com/how-to/boot-raspberry-pi-4-usb)

---
## Installing Docker on Raspbian Buster

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

## Installing Azure IoT Edge on Raspbian Buster

![](https://raw.githubusercontent.com/gloveboxes/Azure-IoT-Edge-on-Raspberry-Pi-Buster/master/resources/iotedge.png)

Review how to [Install the Azure IoT Edge runtime on Debian-based Linux systems](https://docs.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-edge-linux?WT.mc_id=devto-blog-dglover).

### 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.

```bash
sudo apt-get install libssl1.0.2
```

```bash
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

```bash
sudo nano /etc/iotedge/config.yaml
```

### Restart Azure IoT Edge

```bash
sudo systemctl restart iotedge
```

## SSH Authentication with private/public keys

![ssh login](https://raw.githubusercontent.com/gloveboxes/Azure-IoT-Edge-on-Raspberry-Pi-Buster/master/resources/ssh-login.jpg)

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**.

```bash
Add-WindowsCapability -Online -Name OpenSSH.Client
```

2. From PowerShell, create a key pair.

```bash
ssh-keygen -t rsa
```

3. From PowerShell, copy the public key to your Raspberry Pi

```bash
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.

```bash
ssh-keygen -t rsa
```

2. Copy the public key to your Raspberry Pi. From Linux and macOS.

```bash
ssh-copy-id pi@raspberrypi.local
```

## Tools

![tools](https://raw.githubusercontent.com/gloveboxes/Azure-IoT-Edge-on-Raspberry-Pi-Buster/master/resources/tools.jpg)

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

- [qBittorrent](https://www.qbittorrent.org/download.php) Windows Torrent Utility for fast download of Raspbian Images
- Burn Raspbian to sd card with [Balena Etcher](https://www.balena.io/etcher)
- [Raspberry Pi Storage Benchmarks 2019](https://www.raspberrypi.org/forums/viewtopic.php?t=31925)

## 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](https://www.raspberrypi.org/forums/viewtopic.php?t=31925)

## 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
```