#AzureIoT – Granting access to Raspberry Pi GPIO from an ☁ Azure IoT Edge Module

Buy Me A Coffee

Hi !

Today let’s face a cool question:

How do I grant GPIO access in a Raspberry Pi to an Azure IoT Module?

So, the main goal is to access the GPIO to interact with sensors and actors. Usually, when we run programs in the device that’s easy to accomplish, however running an Azure IoT Module we need to grant these permissions to the module definition.

In the Container Create Options, we need to add the following lines:

{
  "HostConfig": {
    "Binds":[
        "/dev/i2c-1:/dev/i2c-1"
        ],
    "Privileged": true
  }
}

Enabling access to the i2c and also running the module with elevated privileges:

And, of course, if the module is also running as a HTTP server, you need to add here the TCP open ports, and more. That’s it! super easy!

Happy coding!

Greetings

El Bruno



¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:

#AzureIoT – Creating a folder 📂 in the docker definition in an ☁ Azure IoT Edge

Buy Me A Coffee

Hi !

In my (spanish) podcast I often complain that we always speak about JavaScript and Docker. And, it also applies to my blog. After my yesterday’s post, someone asked

How we can create a folder on the creation process of the Azure IoT module?

This is not an Azure IoT question, is mostly a docker one. And the answer is easy, just add these lines to create and grant permissions to a folder named [fsexchange]

# create folder for file exchange
RUN mkdir /fsexchange
RUN chown 1000 /fsexchange
RUN chmod 700 /fsexchange

RUN chown 1000 /.
RUN chmod 700 /.

And, you need to do this in each one of the docker definition files that you may use. Like

  • Dockerfile.amd64
  • Dockerfile.arm32v7
  • Dockerfile.arm64v8
  • Dockerfile.windows-amd64
  • Dockerfile.amd64.debug
  • Dockerfile.arm32v7.debug
  • Dockerfile.arm64v8.debug
docker definition files to azure Iot Modules

And that’s it! super easy!

Happy coding!

Greetings

El Bruno


References


¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:

#AzureIoT – Mapping a local ☁ Azure IoT Edge folder module with an Edge device folder 📁

Buy Me A Coffee

Hi !

Another quick post in [Brain backup mode]. This one for a very simple scenario when working with Azure IoT modules:

Mapping a local folder in an Azure IoT Edge module with an Edge device folder

There is a full post on Azure IoT Documentation (see references). And I’ll resume the post here.

Add this configuration to

{
    "HostConfig": {
        "Binds": [
            "[EdgeDeviceFolder]:[AzureIoTModuleFolder]"
        ]
    }
}

Where:

  • EdgeDeviceFolder is the folder on the edge device
  • AzureIoTModuleFolder is the folder on the module, defined the docker image

Of course, you need to grant access to the EdgeDeviceFolder. 2 commands for this

sudo chown 1000 <EdgeDeviceFolder>
sudo chmod 700 <EdgeDeviceFolder>

And that’s it! super easy!

Happy coding!

Greetings

El Bruno


References


¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:

#AzureIoT – ☁ Azure IoT Edge 1.1.0 release is now GA, experiences upgrading #Ubuntu

Buy Me A Coffee

Hi !

There is a new version of the Azure IoT Edge module: 1.1.0 (see references). So, I decided to upgrade my 2 test devices and maybe share some lessons learned in the process.

Upgrade on Ubuntu 18.04 on a Raspberry Pi 4

As usual I’ll start with a full update

# Update
sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'

Similar to the Raspberry Pi OS upgrade process, I found a nice surprise on the update log.

Setting up iotedge (1.1.0-1) ...
===============================================================================

                              Azure IoT Edge

  IMPORTANT: Please update the configuration file located at:

    /etc/iotedge/config.yaml

  with your device's provisioning information. You will need to restart the
  'iotedge' service for these changes to take effect.

  To restart the 'iotedge' service, use:

    'systemctl restart iotedge'

    - OR -

    /etc/init.d/iotedge restart

  These commands may need to be run with sudo depending on your environment.

===============================================================================
Setting up friendly-recovery (0.2.38ubuntu1.2) ...
Setting up moby-engine (20.10.3+azure-1) ...
Processing triggers for systemd (237-3ubuntu10.44) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
ureadahead will be reprofiled on next reboot
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  u-boot-tools
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 139 kB of archives.
After this operation, 7168 B of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main arm64 u-boot-tools arm64 2020.10+dfsg-1ubuntu0~18.04.2 [139 kB]

So, the module is updated. However I need to setup the device provisioning information again and restart the service. In the references section I shared the officials docs for these steps.

Let’s edit the provisioning information

# Update provisioning information (if necessary)
sudo nano /etc/iotedge/config.yaml

My file still have all the valid information (again, like the Raspberry Pi upgrade process)

No changes here, let’s restart IoT Edge

# restart iotedge service
systemctl restart iotedge

Important, authentication is required in this step:

So, I may missed something here. I run the update command for the module, and it’s already on the 1.1 version. However the iotedge list of modules is still using the 1.0

Update runtime settings on Azure IoT Portal

I now I can fix this in the Azure IoT Portal. In the device definition, I need to update the Runtime settings to use the version 1.1. (image is just for reference)

A couple of seconds later, everything works as expected !

iotedge module updated to v1.1.0

Recap

So, the steps to update were these commands

# Update
sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'

# Update provisioning information (if necessary)
sudo nano /etc/iotedge/config.yaml

# restart iotedge service
systemctl restart iotedge

Then update the Runtime Settings on the Azure IoT Portal.

And restart iotedge one more time !

Happy coding!

Greetings

El Bruno


References

My posts on Raspberry Pi ⚡🐲⚡

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware


¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría: