#Azure – Sending custom Telemetry and Event information from a #RaspberryPi device to #AzureIoT Central

Hi!

Azure IoT Central is one of the amazing services we can use on Azure. I was wondering how easy is to use a Raspberry Pi using Raspbian and Azure IoT and here is my experience.

Let’s assume we had a device up to date using Raspbian, our next step will be to create an Azure IoT Central application. The official step by step is the main resource for this

Create an
Azure IoT Central application (see references)

Once we have our application, we can quickly create a new Raspberry Pi device and use it. However, I’ll do an extra step, lessons learned as a handsome developer

Create a Device Template

Go to [Device Templates] and create a new template

azure iot central create new device template

For Raspberry Pi, I’ll name this [Raspberry Pi Dev]

azure iot central create new device template raspberry pi dev

So now, I can add a new real device, in the Devices section from the left menu

azure iot central raspberry pi dev add new real device

Once you create a new real device, is important to copy and save for later the connection information. To access this, go to the top right [Connect] button

azure iot central raspberry pi dev real device connect information

Almost there, there is an official tutorial that explain how to send random telemetry information with a Python script in a Raspberry Pi. I’ll use it as base for this scenario.

Connect a
Raspberry Pi to your Azure IoT Central application (Python) (see references)

For this demo, I’ll add a custom telemetry property and a custom event to the device. Since I won’t use the device to track temperature, accelerometer, and more, I think it make sense to track some custom information.

So, I’ll go back to my Device Template definition and I’ll add a new Telemetry, named [t1], with the following information.

azure iot central raspberry pi dev new telemetry information

And now, I can run a custom version of my script that will send new telemetry information, for [t1]. Sample in line 18

After a couple of minutes running the sample script, I can see the telemetry information for T1. In this view, I enabled [Temperature] and [T1] to display the timeline.

azure iot central raspberry pi dev real device dashboard telemetry

And, next step will be to add an event, which is also a very important uses case in Azure IoT. Back in the Device Template, I add a new event named [event1]

azure iot central raspberry pi dev new event information

And added some extra lines of code to send also an event between telemetry, Line 22

In the following image, we can see how the events appears in the timeline, and we can also get some extra details clicking on each event.

azure iot central raspberry pi dev real device dashboard telemetry and events

Very cool! Next steps will be to integrate this with some image recognition scenarios.

Happy Coding!

Greetings @ Burlington

El Bruno

References

Advertisements

#VSCode – How to install #docker in a #RaspberryPi 4

Hi!

In my series of posts on how to create a development environment using a Raspberry Pi4, today is time to write about installing Docker. (see references)

I was user to download and build docker to be used on the device, however now we have an easier way to do this. Thanks to http://get.docker.com we can now install docker with a single command

curl -sSL
https://get.docker.com | sh

And then, a simple check for the docker version

raspberry pi docker version in terminal

Happy coding!

Greetings @ Toronto

El Bruno

References

#VSCode – Let’s do some #Git dev in #RaspberryPi (GitHub and Azure DevOps!)

Buy Me A Coffee

Hi!

In my previous posts I wrote about how to prepare a developer station with a Raspverry Pi 4. I wrote on how to install Visual Studio Code, how to install .Net Core and how to build and run C# projects. Of course, the next step is to work with Git.

The command to install git is

sudo
apt-get install git

However, I already have Git installed. I haven’t checked, but it seems to me that the latest Raspbian distro includes by default git. I was hoping that VSCode will recognize and use this, but in order to work with Git in VSCode I need some extra work in the IDE settings.

raspberry pi git installed but not integrated in visual studio code

I was able to clone some repositories from GitHub and Azure DevOps, directly from bach

raspberry pi 4 git clone azure devops repository

So, let’s fix Visual Studio Code and Git integration. This one is very easy, I just need to go to Settings, search for Git and define the Git path for VSCode.

raspberry pi 4 visual studio code preferences git

In order to find the git path, we need to use the [which] command

pi@rpidev3:~ $ which git

/usr/bin/git

My got location is [/usr/bin/git].

I’m not a command line dude! I like User Interfaces, so now it’s time to open one of the cloned repositories in Visual Studio Code. I can see that VSCode recognices Git and I can start to commit my files.

raspberry pi 4 visual studio code using git

This is also a perfect moment to define Git user name and user email.

git config --global user.email "email@email.com" 
git config --global user.name "your name"

I like to do this in the Terminal in VSCode, just to check all is working fine.

Happy Coding!

Greetings @ Burlington

El Bruno

References

#VSCode – Build and Run C# #DotNetCore projects in #RaspberryPi

Hi!

Time to move on with some lessons learned using Visual Studio Code in the Raspberry Pi 4.

One of the first issues you may find working with VSCode in the device is related to file write permissions when you are saving a file.

I raspberry pi 4 visual studio code failed to save file

So, it was a good opportunity for me to learn about files and folder permissions in Linux. I found a great starting article “How to Manage File and Folder Permissions in Linux” (see references), and it allowed me to fix this issue.

My next error was triggered when I try to build my project. Again, it was a permission related error.

/home/pi/dotnet/sdk/2.2.401/Microsoft.Common.CurrentVersion.targets(4195,5):
error MSB3021: Unable to copy file "obj/Debug/netcoreapp2.2/dotnethelloworld.dll"
to "bin/Debug/netcoreapp2.2/dotnethelloworld.dll". Access to the path
is denied. [/home/pi/dotnethelloworld/dotnethelloworld.csproj]

However, this time the fix was not related to file and folder permissions.

One of the solutions I found, was to run VSCode with admin privileges. This is probably one of the worst ideas ever, and you can find tons of articles explaining why this is bad (see references).

Anyways, I decided to give it a try. Of course, it worked. Let me share how.

I run VSCode with the following command, which runs the app in root mode.

sudo
code-oss --user-data-dir=/home/pi/dotnethelloworld
raspberry pi 4 visual studio code run as root

The VSCode team is aware of this, so you will find a warning about this scenario

raspberry pi 4 visual studio code run as root warning

Even so, you can still use VSCode to edit and build C# .Net Core Projects.

raspberry pi 4 visual studio code build code

And you can run them also

raspberry pi 4 visual studio code build and run edited code

So far, so good. Or maybe not, broken a lot of good practices. I’ll see this as an amazing chance to learn and test new stuff!

Happy coding.

Greetings @ Burlington

El Bruno

References

#RaspberryPi – How to install #DotNetCore in a #RaspberryPi4 and test with #HelloWorld (of course!)

Hi!

During the next couple of months, I’ll be sharing some amazing experiences around AI. Some of these experiences includes IoT devices like a Raspberry Pi, and of course some Machine Learning.Net (ML.Net). Because ML.Net is built with .Net Core, it makes sense to share the 5 simple steps you need to do to install .Net Core in a Raspberry Pi.

Of course, my 1st try was to navigate to the official .Net page (see references), which automatically detect my Linux distro and proposes a set of x64 SDKs.

raspberry pi 4 .net tutorial page with linux distribution options

I’m completely sure that I’m working in a 32 bits environment, however I’ll double check this with the following commands

sudo apt-get install lshw
lshw

After installing lshw I confirm that I’m in a 32 bit environment

raspberry pi 4 lshw information on 32 bit environment

Bonus: lshw is a small tool to extract detailed information on the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc. on DMI-capable x86 or IA-64 systems and on some PowerPC machines (PowerMac G4 is known to work).

Now I need to navigate to the download page to download the specific Linux 32-bit version (see references).

Once I got the image downloaded its time to extract the file on a specific folder. I’ve created a folder named “dotnet” with the following command

sudo mkdir -p dotnet

And to extract the image from the Downloads folder

sudo tar zxf dotnet-sdk-2.2.401-linux-arm.tar.gz -C
/home/pi/dotnet/

Let’s create a symbolic link to the extracted binaries

sudo ln -s /home/pi/dotnet/dotnet /usr/local/bin

And it’s done! Let’s invoke the .DotNet help command to test it

raspberry pi 4 .net core 2.2 installed and test dotnet help

Now we can follow the steps of [.NET Core on Raspberry Pi, see references] to create a Console Application and to test the device.

To create a new console App

dotnet new console
raspberry pi 4 .net core 2.2 create new console app

And test the app

sudo dotnet run
raspberry pi 4 .net core 2.2 console app run

We can publish the app for linux / raspberry pi

sudo dotnet publish -r linux-arm

And copy the generated folder to be used in another device

./bin/Debug/netcoreapp2.2/linux-arm/
raspberry pi 4 .net core 2.2 console app build and publish folder to reuse

So next steps will be some other tests with Raspberry Pi and .Net Core. And the following image is a big teaser of this

raspberry pi 4 .net core 2.2 console app edit in Visual Studio Code

Happy coding!

Greetings @ Toronto

El Bruno

References

#RaspberryPi – How To enable auto start with #HDMI safe mode

Hi!

A couple of days ago I wrote (a personal reminder post) about how to add automatic connect to Wi-Fi and SSH enabled in a bootable Raspbian image in a SD card (see references). I also explained that this was required for me because, by default Raspberry Pi 4 video ports were not starting with a 1920 x 1080p resolution.

Important: Remember that now, the 2 video ports supports 4K !

I was digging and reading about this, and I found another quick fix to solve this problem. Once you had a Raspbian image in a SD card, you can edit the file [config.txt] for some amazing cool tweaks! (Also, see references)

For me, my main change was in the [hdmi_safe] parameter. Setting hdmi_safe to 1 will lead to “safe mode” settings being used to try to boot with maximum HDMI compatibility.

# uncomment if you get no picture on HDMI for a default "safe" mode 
hdmi_safe=1

With this, the device will start automatically in a safe and standard mode. And, yes, it will work with my old and crappy test monitor!

Happy coding!

Greetings @ Toronto

El Bruno

References

#VSCode – Installing Visual Studio Code in a #RaspberryPi, a couple of lessons learned – @code

Hi!

Now that I have my amazing Raspberry Pi 4 with 4GB RAM, it’s time to see how serious the device is. So, I decided to install and use some developers’ tools in the RPi. My dev list will be something like this

  • Python
  • Some ML and AI Python packages
  • GIT
  • Arduino
  • Visual Studio Code

It’s been a while since I installed VSCode in the device. The last time I did this, I needed to download the code from GitHub and compile the tool in the Raspberry Pi. As far as I remember this was a +25 min process.

Lucky for us the process can now be much simpler, thanks to Headmelted (see references). Now, we only need a single command to install VSCode:

. <( wget -O -
https://code.headmelted.com/installers/apt.sh )

Install process started! Or Maybe not because I found this amazing GPG error

python error installing visual studio code in raspberry pi
pi@rpidev3:~ $ curl -L https://code.headmelted.com/installers/apt.sh | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2349 0 2349 0 0 19739 0 --:--:-- --:--:-- --:--:-- 19906
Detecting architecture…
Ensuring curl is installed
Reading package lists… Done
Building dependency tree
Reading state information… Done
curl is already the newest version (7.64.0-4).
The following packages were automatically installed and are no longer required:
python3-pyperclip python3-thonny rpi.gpio-common
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Architecture detected as armv7l…
Retrieving GPG key headmelted
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
gpg: no valid OpenPGP data found.
Removing any previous entry to headmelted repository
Installing [headmelted] repository…
Updating APT cache…
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://archive.raspberrypi.org/debian buster InRelease
Get:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease [23.4 kB]
Err:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
Reading package lists…
W: GPG error: https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
E: The repository 'https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease' is not signed.
Done!
Repository install complete.
Installing Visual Studio Code from [stretch]…
Reading package lists… Done
E: The value 'stretch' is invalid for APT::Default-Release as such a release is not available in the sources
Visual Studio Code install failed.

There a public GPG key used to verify the package and the SH script somehow does not download it (I think the ARM RPI version is still not defined). So, before the previous command, I need to run this command

wget https://packagecloud.io/headmelted/codebuilds/gpgkey -O
- | sudo apt-key add –

Now we have Visual Studio Code installed!

raspberry pi visual studio code installed

But, yes another but, you may note that the tool open and display a black window. Again, I need to go deeper on the details, but the latest version does not work well. There is some context information on GitHub (see references), and the proposed solution is to rollback to a previous version

sudo apt-get install code-oss=1.29.0-1539702286

And we also need to disable the automatic updates on this tool

sudo apt-mark hold code-oss

And now, yes, we got a fully functional Visual Studio Code in our Raspberry Pi!

Happy Coding!

Greetings @ Toronto

El Bruno

References

#Python – Let’s use a #FaceRecognition demo app for a performance comparison between #RaspberryPi3 and #RaspberryPi4

Hi!

I started to do some tests with the new Raspberry Pi 4 and the results are amazing. I’m not a performance expert, so I decided to pick up some of the demos / apps I’ve creating for the Raspberry Pi and run them in both models: Raspberry Pi 3 B+ and Raspberry Pi 4.

I started with an amazing set of tutorials on how to perform Face Recognition from Adrian Rosebrock (see references). I’ve been using his Face Recognition python package for this scenarios and it’s an amazing one.

I added some code to a custom version of Adrian’s Face Recognition sample, and it looks great. The main idea was to track in real-time the current FPS (similar to the work I did with the Image AI and Hololens sample a couple of days ago, see references).

This sample load a file with 15 trained faces and analyze frame by frame to

  • Detect faces in the frame.
  • If a face is detected, draw a frame around it.
  • For each detected frame analyze if the face is a trained face.
  • If the face is part of the trained dataset, the app will add the name of the person on top of the frame.

I display in real-time the FPS processed with a USB camera in a Raspberry Pi 3 B+. Doing a lot of tweaks and getting the best performance in the device I could never process 1FPS. The average processing data were between 0.6 and 0.9 FPS in a Raspberry Pi 3B+.

python face recognition in raspberry py 3 with FPS live

IMHO, these results are great for a small device like a Raspberry Pi 3B+. But now it was time to test it in the new Raspberry Pi 4. And an important note here is to remark that even if I did this tests in a Raspberry Pi 4 with 4GB of Rams, the performance results are similar to a RPI4 with just 1 GB of ram. We have more memory, however the processor improvements are quite significant in the new version.

I installed all the necessary software in the Raspberry Pi 4 and I got 3X better results. I’ve even tun this in a 1080p resolution to get a sense of the real processing time. The average processing data were between 2.3 and 2.4 FPS in a Raspberry Pi 4.

python face recognition in raspberry py 4 with FPS live

Amazing! In this scenario the Raspberry Pi 4 is almost 3 times faster than the Raspberry Pi 3. And again, these are amazing times for a 50USD device.

The sample source code is https://github.com/elbruno/Blog/tree/master/20190819%20Rpi%203%20vs%20Rpi%204%20Face%20Recognition

I even have time for some BBQ time with family and friends!

Happy coding!

Greetings @ Toronto

El Bruno

References

#RaspberryPi – How To automatically connect to WiFi and enable SSH on 1st boot

Hi!

If you been playing around with Raspberry Pi, I’m sure you already know this. For me this was a 1st timer, so I must write this down for the future myself.

When I started testing the Raspberry Pi 4, I got one of the complete kits, so I got the official red keyboard and mouse.

raspberry pi 4 official keyboard and mouse

I figure out I also need a couple of extra video cables. Now we need a [Micro HDMI to HDMI Cable] to connect one of the 2 video outputs to an external monitor.

This is the (cheap) monitor I’ve been using for a long time, however by default the RPi does works in a valid resolution for this monitor.

raspberry pi 7 inches monitor

And, the 2 main tasks you perform when you start your RPI are

  • Configure Wireless Connection
  • Enable SSH

Of course, you can do this directly in the SD with the Raspbian image (see references). And it’s also very easy to do.

You need to create a file named [wpa_supplicant.conf] in the root of the SD card with the following information:

country=ca
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
 scan_ssid=1
 ssid=" Your WiFi SSID"
 psk="You amazing password"
}

The file content is very straight forward to understand. Main values to complete are [ssid] and [psk]

Important: This only works the first time you boot the Raspberry Pi with the SD card. The SO search for [wpa_supplicant.conf] and performs the connection. If you already booted the device, you need to create a bootable SD card again.

If you also want to enable SSH, you need to create a blank file named [ssh] to the main partition.

And that’s it, your Raspberry Pi will be connected to the Wifi and with SSH enabled!

Happy coding!

Greetings @ Toronto

El Bruno

References

#RaspberryPi – Using “please” instead of “sudo”, a very Canadian command line of work for #Linux

Hi!

I’ll write this down, so I don’t forget in the near future. I’m not a Linux user, and that’s amazing. Every day I learn something new, mostly while I’m working with Python, Visual Studio Code and Raspberry Pi.

So, I received a couple of brand new Raspberry Pi 4, and now it’s time to test them. And of course, most of this job is via SSH / command line. I’m not an expert (yet) on Raspberry Pi user permissions, however I started to realize when I need to use “sudo” to get things done.

If you search for sudo definition, you may find something similar to this one:

Sudo stands for either “substitute user do” or “super user do” (depending upon how you want to look at it)

https://www.lifewire.com/what-is-sudo-2197466

Today, I’ve learned the power of the “alias” command, and how it can be used to have a more polite conversation with my device. In example, I can create an alias for sudo, named “please” and then this happen.

alias please="sudo"

This is a very polite way to display my Raspberry Pi4 CPU information

raspbery pi 4 using please instead of sudo display cpu information

Or another polite way to display Disk information for the Raspberry Pi 4

raspbery pi 4 using please instead of sudo display disk information

You get the idea.

Happy Coding!

Greetings @ Toronto

El Bruno

Twitter source