Today challenge was based on an easy one
How do I get a Raspberry Pi temperature using Python?
The lines to do this are quite simple, with the following lines we can get the absolute value for the device temperature, in Celsius (of course!)
Easy! My next step was to add a new [Device Property] to my [Device Template] in Azure IoT. I’ll store this as a temp string, so this is fine.
The lines to send the temperature as a device property are part of the following code sample. I also track the temperature as telemetry so I can work with the history of the device temp
So far, so good!
Now it was time to package all this in a docker image and run it from a container. I got an ugly surprise when I realize that I got an exception trying to get the device temperature
VCHI Initialization failed
Time to read and learn more about docker and containers on Raspberry Pi.
In the official documentation of [Docker Run, see references] I found a couple of options which may help me. There are 2 options to allow me access to the device temperature
- Run the container with the specific path to the device I want to grant privileged access for my container
- Run the container with the [–privileged] argument to enable access to all devices on the host
Of course, the 2nd one is easier, but much more dangerous
When the operator executes docker run –privileged, Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host. Additional information about running with –privileged is available on the Docker Blog.
I didn’t think twice and run my image with the [–privileged] argument.
sudo docker run --privileged -p 80:80 <Image ID>
And now I can get an amazing history and track of information using docker, containers and Azure IoT with a Raspberry Pi
- Docker Run, https://docs.docker.com/engine/reference/run/
- El Bruno, How to install .Net Core in a Raspberry Pi 4 and test with HelloWorld https://elbruno.com/2019/08/27/raspberrypi-how-to-install-dotnetcore-in-a-raspberrypi4-and-test-with-helloworld-of-course/
- El Bruno, Installing Visual Studio Code in a Raspberry Pi https://elbruno.com/2019/08/20/vscode-installing-visual-studio-code-in-a-raspberrypi-a-couple-of-lessons-learned-code/
- El Bruno, Build and Run C# ,NetCore projects in a Raspberry Pi 4 with Visual Studio Code https://elbruno.com/2019/08/28/vscode-build-and-run-c-dotnetcore-projects-in-raspberrypi/
- Let’s do some Git dev in Raspberry Pi 4 (GitHub and Azure DevOps!) https://elbruno.com/2019/09/02/vscode-lets-do-some-git-dev-in-raspberrypi-github-and-azure-devops/
- How to install Docker in a Raspberry Pi 4 https://elbruno.com/2019/09/17/vscode-how-to-install-docker-in-a-raspberrypi-4/
- Where is my Task Manager? let’s try htop https://elbruno.com/2019/09/23/raspberrypi-where-is-my-task-manager-lets-try-htop/
- Sending custom Telemetry and Event information from a Raspberry Pi device to Azure IoT Central https://elbruno.com/2019/09/18/azure-sending-custom-telemetry-and-event-information-from-a-raspberrypi-device-to-azureiot-central/