Raspberry PI, Me, and Azure IoT
Hi all! Happy Friday! Well, recently I have been trying my hand doing something new as an MCT (Microsoft Certified Trainer). I was teaching my second AZ-900 class and there was a great Azure IoT walkthrough that I worked through with my students, and I thought it was a great learning experience! Not only for my students, but for me as well! I decided to actually try it out myself in the real world, and build my own physical test IoT device based on that exercise. I wanted to share that learning experience with you and how fun it was to try out! Brace yourselves!
The first thing I did was the Raspberry Pi setup. The kit that I used was an Raspberry Pi 4 with 2GB of RAM, a micro-hdmi to hdmi adapter, Raspberry Pi power supply, 16GB SD card, and Raspberry Pi case. I purchased all this from my local electronics retailer. Awesomeness!
I assembled the Raspberry Pi as shown below to prepare for the OS.
I downloaded the Raspberry Pi Imager from the Raspberry Pi website as shown below. For testing I decided to load Ubuntu Server 20.04.1 LTS. There are distros galore to choose from! A whole new world here!
Placing the SD card in the laptop, here you can see me performing the imaging process below. Shake and bake!
Once the imaging had completed, I placed the SD card in the socket on the Raspberry Pi and things started to happen!
What sorcery is this you say?
Ubuntu started its boot up process and I was able to logon with default creds and change them. I then setup the wireless network connection by installing Ubuntu network manager package while on ethernet.
Ok, now that my mini Raspberry Pi server is up and running and online. Let's get an Azure IoT Hub going and connect this thing up to it!
Here you can see me creating my IoT Hub in the Azure portal.
Let's watch our deployment! Shall we?
Ok, once the deployment is complete we can get our connection information by adding a device to the IoT Hub and getting the associated connection string information.
Now comes the fun part of setting up communication with Azure IoT Hub, the sample weather station app from Microsoft, and Visual Studio Code. Are you ready for this? I am!
So, during the MCT class for AZ-900, I was teaching with the Raspberry Pi Simulator referenced here.
https://azure-samples.github.io/raspberry-pi-web-simulator/
So, what I wanted to do after the class was build it myself. A little mini weather station! I do have an actual BME280 sensor on its way, but wanted to get this going with some simulated weather data first. Call me impatient, but I couldn't wait!
So, to simulate it on my Raspberry Pi the first thing I need to do is install Node.js.
See this exciting experience firsthand below!
Ok, now that I have Node.js installed I can go ahead and clone the source repo for the same weather IoT app from Microsoft. This is the command to clone the official repo from Microsoft! There are other goodies in here as well, but my main objective was to get the Microsoft weather station up! Stay on target!
git clone https://github.com/Azure-Samples/azure-iot-samples-node.git
The cloning process is complete!
I run my trusty npm install command to install all dependencies to setup the Microsoft weather application on the Raspberry Pi!
Alright, Alright, Alright!
You now need to edit the config.json file and turn on the simulated data to "true" for now!!! I will be getting my actual sensor. It will be mine! Ok, ill stop talking about the sensor! If you are lucky enough to have a sensor, you can leave it in the false setting and use that sensor!
You then launch the application and pass in the IoT connection string to the Azure IoT to collect the data.
Let's check on in on our hub and see if the data arrives......Yesss!!! Excellent we have data! I did something right for a change!
There also is a way cool way also to check in Visual Studio Code to view messages sent and received from your devices and IoT Hub. Let's check that out!
So, to start you want to load up Visual Studio Code and search the wonderful world of extensions. The extension you are going to want to use the Azure IoT Hub. Check it out! I can right click my Raspberry Pi device in Azure IoT and get status! Status is important!
Lets try some device to cloud messages:
Let's actually use the Visual Studio Code tools to monitor my messages sent by my Raspberry Pi in real time. There we go! We can see here my Raspberry Pi sending the data from the test app and also the same output in Visual Studio Code. Truly symmetrically radical experience!
Cool, I actually can do the reverse using Visual Studio Code to monitor the endpoint and send some test messages from the Azure Portal. Way cool!
Well, there we go! Bi-directional communication in real time between the Azure Portal, Azure IoT Hub, my Raspberry Pi, and to top it off Visual Studio Code integration at its finest!! You betcha!
Ok, eventually I have to get my actual weather sensor and get this outside in a project box! Ok, I said I wasn't going to talk about the sensors anymore!
If you are wanting to this out on your own, I added the official Microsoft reference docs below to try it out on your own! I used these and I wanted to share my personal experience with you all and how easy it was to get started! Look forward to trying out additional experiences with Azure IoT in the future! Have a great weekend ahead and see you next time! Stay safe!
References:
https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-raspberry-pi-kit-node-get-started