Hello everyone, Nowadays Integration is one of the hot and interesting topic in Information technology which really adds value to any system by linking together different computing systems and software applications physically or functionally, to act as a whole coordinated system.
Microsoft Azure also support integration of IoT devices like Raspberry Pi with one of its feature product called Azure IoT hub.
Below are the prerequisites for both the hardware and software you’ll need:
- A Raspberry Pi 3 Model B+ running Windows IoT core platform. The process of setting up your Raspberry Pi with Windows IoT core is simple. There’s a great Getting Started article on the Windows IoT site, so start there if you need to install Windows on your device. The whole process takes less than an hour and requires very little heavy lifting, so if you’re new to IoT, don’t worry the setup process is very basic via a simple wizard.
- Visual Studio 2015 Community.
- The Azure SDK 2.8.2 for .NET, which contains some great new improvements for Web, Mobile, and REST API developers
- An active Azure subscription. If you don’t have an Azure account, create a free Azure trial accountin just a few minutes.
In addition to these items, you’ll also need a network cable or wifi connection to connect your Raspberry Pi to the network. Once it’s connected you’ll be able to deploy code from Visual Studio to the device, debug your code while it’s running live on the device. Ideally, you’ll be able to connect a mouse and keyboard to your Raspberry Pi. I used a wireless mouse/keyboard combination from my desktop computer, but many options exist for enabling human interface devices to your Raspberry Pi.
Create an IoT hub
- Sign in to the Azure portal.
- Select Create a resource> Internet of Things > IoT Hub.
3. In the IoT hub pane, enter the following information for your IoT hub:
- Name: Create a name for your IoT hub. If the name you enter is valid, a green check mark appears.
Important: The IoT hub will be publicly discoverable as a DNS endpoint, so make sure to avoid any sensitive information while naming it.
- Pricing and scale tier: For this tutorial, select the F1 – Free For more information, see the Pricing and scale tier.
- Resource group: Create a resource group to host the IoT hub or use an existing one. For more information, see Use resource groups to manage your Azure resources
- Location: Select the closest location to you.
- Pin to dashboard: Check this option for easy access to your IoT hub from the dashboard.
4. Click Create. Your IoT hub might take a few minutes to create. You can monitor the progress in the Notifications
Now that you have created an IoT hub, locate the important information that you use to connect devices and applications to your IoT hub.
- After your IoT hub is created, click it on the dashboard. Make a note of the Hostname, and then click Shared access policies.
2. In the Shared access policies pane, click the iothubowner policy, and then copy and make a note of the Connection string of your IoT hub. For more information, see Control access to IoT Hub.
Note: You will not need this iothubowner connection string for this set-up tutorial. However, you may need it for some of the tutorials on different IoT scenarios after you complete this set-up.
Register a device in the IoT hub for your device
- In the Azure portal, open your IoT hub.
- Click IoT Devices.
- In the IoT Devices pane, click Addto add a device to your IoT hub. Then do the following:
Device ID: Enter the ID of the new device. Device IDs are case sensitive.
Authentication Type: Select Symmetric Key.
Auto Generate Keys: Select this check box.
Connect device to IoT Hub: Click Enable.
The device ID may be visible in the logs collected for customer support and troubleshooting, so make sure to avoid any sensitive information while naming it.
4. Click Save.
5. After the device is created, open the device in the IoT Devices
6. Make a note of the primary key of the connection string.
Set up Raspberry Pi
Download and install windows 10 IoT core operating system image on to micro SD card up to 8 GB minimum. Remove the micro SD card from your computer when installation is complete. Insert the micro SD card into the Pi and power it up. Pease have a look on SD card requirements for installing windows 10 Iot core.
Connect the sensor to Pi
For this blog post I’m using DHT22 Sensor connected to the Pi. DHT22 sensor used in this model allows you to monitor the temperature and humidity. This DHT22 temperature sensor holds three pins Data, Power in (VCC) and Ground (GND).
Follow the below steps for connecting DHT22 with Raspberry Pi 3 and deploying a sample application on Pi that will take temperature and humidity from environment and will send it to Azure IoT hub event/messages endpoint.
Connecting DHT22 sensor towards Pi:
- Connect the data pin towards GPIO 4 at Pi kit using Jumper wires
- Connect the Power pin towards Power (3.3v PWR) at Pi kit using Jumper wires
- Connect the ground pin at DHT22 towards Ground (GND) at Pi kit using Jumper wires
Refer the following image for connectivity:
Connecting Pi with Monitor:
Connect your Pi kit with monitor and start your device. Make sure that the Pi kit is connected towards Internet.
Build with Visual Studio 2015
Download the solution file from this URL – http://bit.ly/1rtQR55
Open the solution file attached with this article under Visual Studio 2015 and make the following changes:
1. In MainPage.xaml.cs file, first replace DHT11 interface with DHT22 interface and replace Azure IoT hub parameters with yours as shown below:
2. Change the target version towards the version of OS installed at Pi.
3. Change the Deployment platform for Remote Machine and ARM processor. Give the IP address of Pi towards Visual Studio and deploy now.
Find the temperature and humidity at the display connected towards Raspberry Pi and the same data is send to Azure IoT hub that we had created earlier in the step Create IoT Hub.
You’ve run a sample application to collect sensor data and send it to your IoT hub. To see the messages that your Raspberry Pi has sent to your IoT hub, or to send messages to your Raspberry Pi in a command-line interface, see the Manage cloud device messaging with iothub-explorer tutorial.
This is how we can integrate Raspberry Pi with Microsoft Azure cloud. This blog is just a basic but possibilities are numerous where there could be multiple sensors or even multiple Raspberry Pi connected to Azure IoT hub and infrastructure could be built as per your requirements.
Hope you enjoy the blog as IoT skills really matter for a computer scientist and nearly every industry would be infected by it in the future because human-to-human or human-to-computer interaction is minimizing in most industries. We will get back to you with another informative blog soon.