An IoT solution using IoT Hub, Azure Stream Analytics and Power BI Desktop

Goal of the IoT Solution

Get the current temperature for Jeddah City and monitor it for anomalies (ups and downs) over a period of time (a few days).

Overview of the IoT Solution

The IOT solution gets the current weather data in Jeddah (from a weather web site) and sends it to Azure IOT Hub in Azure.  From the IOT Hub the data goes through Azure Stream Analytics (ASA).  ASA does some filtering on the data and then stores it in table storage in Azure.  Subsequently, I then read the data from the Power BI Desktop application and I plotted it on a chart.  Subsequently, using the plot,  I monitored the temperature data for anomalies or variances.

Details of the IoT Solution

Since the sensors for my TI micro-controller are yet to arrive, I developed a solution that simulates those temperature sensors by reading current temperature data from http://www.openweathermap.org.  The weather data is in the JSON format and it is consumed using a REST API.  In the future, instead of using a weather site to get temperature data, I can easily get real weather data from temperature sensors on a micro controller or a computer on a board.  For example, sensors attached to a Rasperry PI or sensors attached to an Arduino board can easily provide this data.

Reading the Weather Data from OpenWeatherMap web site
// Get temperature from OPenWeatherMap
JObject jsonData = JObject.Parse(new System.Net.WebClient().DownloadString(string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q=Jeddah&type=accurate&mode=json&units=metric&cnt=3&appid=key")));

if (jsonData.SelectToken("cod").ToString() == "200")
{
todayTemperature = (double)jsonData.SelectToken("list[0].temp.day");
Console.WriteLine($"Temp: {todayTemperature.ToString()}"
);

A Windows’ console application gets this temperature data (from openweathermap.org) and sends this telemetry to an Azure IOT Hub.

The data is sent to Azure IoT Hub and picked up by Azure Stream Analytics

From the IOT Hub the data is picked up by an Azure Stream Analytics job.  This is basically a query (similar to SQL) that takes the data from IOT hub, validates it and places it in an Azure Storage table.

SELECT
DeviceId,
telemetryTime,
temperature as TemperatureReading
INTO
TemperatureTableStorage
from TempSensor
WHERE
DeviceId is not null
and EventProcessedUtcTime is not null
and telemetryTime is not null
Finally analysis – for anomalies – is done in Power Bi Desktop

Once the data is in an Azure Storage table, I performed cold-path analytics on it using PowerBI Desktop.  I used PowerBI Desktop to read the data directly from Azure storage.  I then used it to analyze the data and plot it in different ways.

The image below is a screenshot of a Stacked Column chart of (temperature readings against time).  It shows the variance in Jeddah weather (temperature) over the course of a day on 15 May 2016.

PowerBI Desktop showing temperature data plot
PowerBI Desktop showing temperature data plot