How to install dvu server in Raspberry Pi?

 Installing a DVU Server (which I understand refers to the Device Update for IoT Hub service from Microsoft Azure) on a Raspberry Pi is an excellent way to manage over-the-air (OTA) updates for your Pi and other devices.



Here is a comprehensive guide on how to do it.

What is Device Update for IoT Hub (DVU)?

It's a Microsoft Azure service that allows you to deploy firmware, OS, application, and configuration updates to your IoT devices (like Raspberry Pi) connected to Azure IoT Hub. It's designed for reliability and security.


Prerequisites

Before you begin, you must have the following:

  1. A Raspberry Pi (any model 3 or 4 is recommended) running a 64-bit OS (e.g., Raspberry Pi OS Lite (64-bit) or Ubuntu Server 20.04/22.04 LTS (64-bit) for ARM). The Device Update agent is built for 64-bit architecture.

  2. An Azure Account. You will need a subscription (you can use the free tier with credits).

  3. Azure IoT Hub. You must create an IoT Hub instance in your Azure portal.

  4. A Device Identity. Your Raspberry Pi must be registered as a device in your IoT Hub.

  5. Network Connection. The Pi must have internet access.


Step-by-Step Installation Guide

Here’s the process broken down into two main parts:

  1. Setting up Azure Resources (in the cloud)

  2. Installing and Configuring the Agent (on the Raspberry Pi)


Part 1: Setup in Azure Portal

1. Create and Configure an IoT Hub

  1. Log in to the Azure Portal.

  2. Search for and create an IoT Hub service.

  3. Select your subscription, create a new resource group, give it a name, choose a region, and select a pricing tier (S1 Standard is the minimum for Device Update).

2. Create a Device Update Account

  1. In the Azure Portal, search for "Device Update for IoT Hub".

  2. Click Create and link it to the IoT Hub you just created.

3. Register Your Raspberry Pi as a Device

  1. Inside your IoT Hub, navigate to Devices under Explorers.

  2. Click + Add Device.

  3. Give your device a Device ID (e.g., my-raspberry-pi).

  4. For authentication, select Symmetric key and check Auto-generate keys.

  5. Click SaveCRITICAL: Copy the Primary Connection String that is generated. You will need this for the agent configuration on the Pi. Store it securely.


Part 2: Setup on the Raspberry Pi

Connect to your Raspberry Pi via SSH. All following commands are run on the Pi's terminal.

bash
ssh pi@raspberrypi.local

1. Prepare the System (64-bit OS)

Ensure your OS is 64-bit. Check with:

bash
uname -m

If it returns aarch64, you are using a 64-bit OS. If it returns armv7l, you are on 32-bit and need to install a 64-bit OS.

Update the package list:

bash
sudo apt update && sudo apt upgrade -y

2. Install the Device Update Agent

Microsoft provides packages for Debian/Ubuntu on ARM64.

  1. Configure the Microsoft package repository:

    bash
    curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
    sudo apt-add-repository https://packages.microsoft.com/debian/11/prod
    sudo apt update
  2. Install the Device Update agent:

    bash
    sudo apt install deviceupdate-agent

3. Configure the Agent with the Connection String

This is the most important step. You must provide the agent the connection string to connect to your specific IoT Hub.

  1. Open the agent configuration file for editing:

    bash
    sudo nano /etc/adu/du-config.json
  2. Find the connectionData section and replace the entire JSON array ["**Replace with IoT Hub Device Connection String**"] with the connection string you saved from Azure IoT Hub.

    Example:

    json
    {
      "connectionData": ["HostName=my-iot-hub.azure-devices.net;DeviceId=my-raspberry-pi;SharedAccessKey=abc123..."]
    }
    • Save the file (Ctrl+OEnterCtrl+X).

4. Start the Device Update Service

  1. Start the service and enable it to run on boot:

    bash
    sudo systemctl enable deviceupdate-agent
    sudo systemctl start deviceupdate-agent
  2. Check the status to ensure it's running without errors:

    bash
    sudo systemctl status deviceupdate-agent

    Look for active (running). If you see errors, check the logs with journalctl -u deviceupdate-agent -f.


Part 3: Verification and Next Steps

1. Verify in Azure Portal

  1. Go back to your Device Update for IoT Hub instance in the Azure Portal.

  2. Navigate to Devices and groups.

  3. You should see your device (my-raspberry-pi) listed. Its state might initially be Ungrouped and then change to Ready, indicating a successful connection.

2. Next Steps: Creating and Deploying an Update

Now that the agent is running, you can use the Device Update service to:

  1. Import an Update: Package your application or OS changes into a valid update manifest and import it into your Device Update account.

  2. Create a Group: Group your devices (e.g., "all-pi-devices-in-berlin").

  3. Deploy an Update: Schedule the imported update to be deployed to a device group. You can monitor the deployment progress from the portal.

Troubleshooting Common Issues

  • deviceupdate-agent service fails:

    • Most common cause: An error in the du-config.json file (typo in the connection string). Double-check it.

    • Check logs: journalctl -u deviceupdate-agent -e -f

  • Device not appearing in Azure Portal:

    • Ensure the Pi has internet access.

    • Verify the IoT Hub name and device ID in the connection string are correct.

  • Architecture error during install:

    • Confirm you are running a 64-bit OS with uname -m.

By following these steps, you have successfully turned your Raspberry Pi into a device managed by Azure IoT Hub, ready to receive secure, reliable updates from the cloud.

评论

此博客中的热门博文

How To Connect Stm32 To PC?

How do you set up ADC (Analog-to-Digital Converter) in STM32?

What is a Look-Up Table (LUT) in an FPGA, and how does it work?