Live streaming Weather station with Cortana Analytics – Part 2

Posted by on Feb 28, 2017 in Analytics, Cortana Analytics, IOT | One Comment

In previous post (, 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 ( 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.image30

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

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.



Then, we can see iot event hub in below picture.image43

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.





Leila Etaati
Dr. Leila Etaati is Principal Data Scientist, BI Consultant, and Speaker. She has over 10 years’ experience working with databases and software systems. She was involved in many large-scale projects for big sized companies. Leila has PhD of Information System department, University of Auckland, MS and BS in computer science. Leila is Microsoft Data Platform MVP.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *