Live streaming Weather station with Cortana Analytics – Part 2

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 on LinkedinLeila Etaati on TwitterLeila Etaati on Youtube
Leila Etaati
Trainer, Consultant, Mentor
Leila is the first Microsoft AI MVP in New Zealand and Australia, She has Ph.D. in Information System from the University Of Auckland. She is the Co-director and data scientist in RADACAD Company with more than 100 clients in around the world. She is the co-organizer of Microsoft Business Intelligence and Power BI Use group (meetup) in Auckland with more than 1200 members, She is the co-organizer of three main conferences in Auckland: SQL Saturday Auckland (2015 till now) with more than 400 registrations, Difinity (2017 till now) with more than 200 registrations and Global AI Bootcamp 2018. She is a Data Scientist, BI Consultant, Trainer, and Speaker. She is a well-known International Speakers to many conferences such as Microsoft ignite, SQL pass, Data Platform Summit, SQL Saturday, Power BI world Tour and so forth in Europe, USA, Asia, Australia, and New Zealand. She has over ten years’ experience working with databases and software systems. She was involved in many large-scale projects for big-sized companies. She also AI and Data Platform Microsoft MVP. Leila is an active Technical Microsoft AI blogger for RADACAD.

1 thought on “Live streaming Weather station with Cortana Analytics – Part 2

Leave a Reply