In previous post (https://radacad.com/create-a-live-stream-weather-station-with-cortana-analytics-part-1), I have explained what is Cortana, What is IoT and how to set up the Raspberry pi3. In this post, I will explain the process of connecting weather station sensor to Raspberry Pi. Also, how to send data to the Event Hub and set it up.
Get Weather Data
For connecting Raspberry PI to weather station sensor, we should write some codes. Two types of code are needed. First a code that read data from sensor and, the second one that send data to cloud.
There is an article that shows the process of connecting weather station to Raspberry PI (https://www.hackster.io/windowsiot/build-hands-on-lab-iot-weather-station-using-windows-10-5b818f). This article provides 4 main .Net projects:
1- Sparkfun weather shield: a Universal windows project for collecting information from Weather sensor
also for collecting the “barometric pressure” information we use mpl3115a2 project and also for measuring humidity htu21d project has been used.
First of all, we should specify the name of Raspberry PI in code. Hence, find the file with name “MainPage.xaml.cs” then in uri put the iot device name.
In windows universal projects, the code will be run in specific device, that in this scenario is “Raspberry Pi”. hence we have to specify the device name, that we want to run code on it. In page build2015-weather-station we should find the remote machine first.
there is an important note that raspberry pi and pc that we run should be in a same internet network.
by running the code, in monitor you will see the below picture, that shows weather station is receiving information about weather such as humidity, temperature and pressure.
In this stage, Raspberry Pi and weather station sensor have been connected. Now, we should sent the collected data to Cloud (Cortana), but before that, we it should be set it up.
Event hub is a managed event ingestor that able to collect million of events per second from different devices. Event hub is part of service bus in Cortana. It receives information from Raspberry PI in JASON Format. To create event hub, I login in old Cortana portal: “Manage.windowsazure”. Tto create new event hub we should create “New” component.
By clicking on New bottom, new page will be show up, we should create “APP Service” and then “Service Bus”. following, in service bus, “Event Hub” should be chosen.
This should be accompany with specifying the Event Hub name and Region, which in my case is “Southeast Asia”.
now we can see the process of creating Event hub and related service bus in Cortana (see below picture).
After creating Event Hub, we able to see Event hub configuration by clicking on the configuration component (below picture). By clicking on the name of Service bus, we able to see the configuration in event hub.
In event hub we can see some information about the “Policy Name” and “Primary Key” that can be used for creating connection between Universal Windows code that we have and Cortana analytics.
now we should put the policy code and primary key in our .Net code as below
By running the code, first the project will be deployed in Raspberry PI and the information from weather sensor will be send to Event Hub. Below picture shows the sending message in output.
Now by clicking on the “iotLeila” service bus in Cortana analytics (see below picture), we can see the Related Event Hub.
We can see all the messages that have been sent to Event Hub in last 24 Hours. This includes all sending message, errors and successful messages.
Till now, we find out how to send data from weather station to Raspberry PI and then to Event Hub. In the next, post I will show how to sent information to Power BI and Azure ML via stream Analytics.