Skip to content

Latest commit

 

History

History
304 lines (235 loc) · 13.5 KB

proto-lib-azure.md

File metadata and controls

304 lines (235 loc) · 13.5 KB

Azure MQTT Protocol Adapter Libraries

NVIDIA provides two Azure MQTT protocol libraries installed with DeepStream under /opt/nvidia/deepstream/deepstream/lib

  • libnvds_azure_proto.so - a device client protocol for sending messages from the device to an Azure IoT Hub instance. Requires minimal setup.
  • libnvds_azure_edge_proto.so - a module client protocol for bidirectional device-server messaging. Applications linking with DSL must be run in a deployed Docker container.

The protocol adapter libraries are used by the DSL Message Sink and Message Broker components.

Contents


Common Setup for both Protocol Adapters

Install Additional device dependencies

sudo apt-get install -y libcurl4-openssl-dev libssl-dev uuid-dev libglib2.0 libglib2.0-dev

Setup an Azure IoT Hub Instance

Follow the directions at https://docs.microsoft.com/en-us/azure/iot-hub/tutorial-connectivity#create-an-iot-hub.

Register your IoT Edge Device

There are three methods to register your device as outlined at https://docs.microsoft.com/en-us/azure/iot-edge/how-to-provision-single-device-linux-symmetric?view=iotedge-2020-11&tabs=azure-portal%2Cubuntu#register-your-device - Azure portal, Visual Studio Code, and Azure CLI - with Azure portal being the simplest.

The following section details the installation process and steps to use the Azure CLI.

Install the Azure CLI on your edge device

For an x86 computer running Ubuntu:

The Azure CLI team maintains a script to run all installation commands in one step. This script is downloaded via curl and piped directly to bash to install the CLI.

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

For Jetson:

Currently, the only way to use Azure CLI on ARM64 is to install from PyPI (https://pypi.org/project/azure-cli/):

sudo pip3 install azure-cli

If the install fails, see Failure installing azure-cli on Jetson under Trouble Shooting.

Important: once the installation is complete you will need to reboot the device!

sudo reboot

Verify the installation with.

az --version

If the verification command fails, see Failure verifying azure-cli install on Jetson under Trouble Shooting.

Add the azure-iot extension.

az extension add --name azure-iot

Create an IoT Edge Device

Log into to your Azure IoT Hub on the cloud from your device terminal window. The following command will bring up the login screen in your browser.

az login

Create an IoT edge device from your device terminal with the following command.

az iot hub device-identity create --device-id <device-id> --hub-name <hub-name> --edge-enabled

where:

Verify the device creation with the following command.

az iot hub device-identity list --hub-name <hub-name>

Or check from your Azure IoT Hub instance on the cloud. From your hub dashboard, select the IoT Edge item in the left menu pane, you should then see your device listed in the main window.

Get the connection string for your new device

az iot hub device-identity connection-string show --device-id <device-id> --hub-name <hub-name>

Or copy the Primary Connection String from your Azure IoT Hub instance by selecting the device name on IoT Edge main page (see image above).

You will need the connection-string to use the Message Sink and Message Broker API.

Enable the NVIDIA logger

For Jetson and x86 computers running Ubuntu:

Run the settup script with the following commands.

sudo chmod u+x /opt/nvidia/deepstream/deepstream/sources/tools/nvds_logger/setup_nvds_logger.sh
sudo /opt/nvidia/deepstream/deepstream/sources/tools/nvds_logger/setup_nvds_logger.sh

Log messages will be written to /tmp/nvds/ds.log.

Note: when using the Message Sink, setup errors will result in the Pipeline failing to play. The reason for the failure may be found in the nvds log file, for example

Mar 24 16:37:57 prominenceai1-desktop dsl-test-app.exe: DSLOG:NVDS_AZURE_PROTO: Error. Azure connection string not provided#012
Mar 24 16:37:57 prominenceai1-desktop dsl-test-app.exe: DSLOG:NVDS_AZURE_PROTO: nvds_msgapi_connect: Failure in fetching azure connection string

Your device setup is now sufficient to use the Device Client libnvds_azure_proto.so with the following examples.


Azure Module Client setup

Setup the Azure IoT Edge runtime on the edge device

For Jetson and x86 computers running Ubuntu:

Follow the below steps from the instructions here. https://docs.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-edge-linux. Specifically:

Build and deploy a Docker Image

See the instructions and Docker file under the deepstream-services-library-docker GitHub repository.

Grant host access to the local X-server

As a privileged user (root), append the following lines to file /etc/profile to allow access to the local X-server.

if [ "$DISPLAY" != "" ]
then
  xhost +
fi

Make the file executable

sudo chmod u+x /etc/profile

Then execute the file.

sudo /etc/profile

You should see confirmation similar to below.

access control disabled, clients can connect from any host.

Note: how to correctly setup specific or limited access is still under investigation.

Deploy IoT Modules

The following instructions detail the steps to create a new IoT Edge Custom Module to run the Docker Image created in the previous section Build and deploy a Docker Image.

From your Azure portal, select IoT Edge from the left menu pane, then select your device by its id. You should see the two existing IoT Edge System Modules that were deployed when you Setup the Azure IoT Edge runtime on the edge device.

To setup a new IoT Edge Custom Module to run the message_broker_azure_module_client.py example, select the Set modules from the upper menu bar on the device page, as show below.



Select the + Add button under the IoT Edge Modules section on the Set modules page and select the first item + IoT Edge Module as shown below.



Define the Module Settings by specifying the IoT Edge Module Name and Image URI to the Docker Image created in the previous section Build and deploy a Docker Image as shown in the image below.


Select the Environment Variables tab and add the DISPLAY variable as shown below. Set the value to :0 for local or :1 for remote.


Select the Container Create Options tab

Then add the below JSON code and select Add

{
    "Entrypoint": [
        "python3",
        "/opt/prominenceai/deepstream-services-library/examples/python/message_broker_azure_module_client.py"
    ],
    "HostConfig": {
        "runtime": "nvidia",
        "NetworkMode": "host",
        "Binds": [
            "/tmp/argus_socket:/tmp/argus_socket",
            "/tmp/.X11-unix/:/tmp/.X11-unix/",
            "/tmp/.dsl/:/tmp/.dsl/"
        ],
        "IpcMode": "host"
    },
    "NetworkingConfig": {
        "EndpointsConfig": {
            "host": {}
        }
    },
    "WorkingDir": "/opt/prominenceai/deepstream-services-library/examples/python/"
}

Once the code has been added, select the Review + create button from the Set modules main page as show below:

Make sure that the validation passed - as show in the upper left corner in the image below - and then select Create



All three IoT Edge Modules should now be in a running state as shown below.


The example script directs the DSL INFO logs and Python application logs to files located under /tmp/.dsl/ which is viewable from outside of the Module container.


Next Steps and Useful Links

Use the trouble shooting page in the Azure portal to monitor IoT Edge devices and modules.

Create a single database in Azure SQL Database using either the Azure portal, a PowerShell script, or an Azure CLI script. You then query the database using Query editor in the Azure portal.


Trouble Shooting

Failure installing azure-cli on Jetson.

If the command to install azure-cli using pip3 fails with the following module dependency errors

    No package 'libffi' found
    c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
     #include <ffi.h>
              ^~~~~~~
    compilation terminated.

Install the dev suite of libffi as follows:

sudo apt-get install libffi6 libffi-dev

If the command to install fails with the following error

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-jshgucrb/cryptography/setup.py", line 14, in <module>
        from setuptools_rust import RustExtension
    ModuleNotFoundError: No module named 'setuptools_rust'
   
            =============================DEBUG ASSISTANCE==========================
            If you are seeing an error here please try the following to
            successfully install cryptography:
   
            Upgrade to the latest pip and try again. This will fix errors for most
            users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
            =============================DEBUG ASSISTANCE==========================

Upgrade to the latest version of setuptools and pip with the following commands

sudo apt-get install python3-setuptools
sudo pip3 install --upgrade pip

Failure verifying azure-cli install on Jetson

If the command az --version fails with

/usr/bin/az: line 2: /opt/az/bin/python3: cannot execute binary file: Exec format error

You have an invalid Debian version installed which can be removed with.

sudo apt-get remove -y azure-cli

Open a new terminal and re-verify.