In this article I will show you how to create an Stream Analytics Job to process the data coming from the previously connected IoT Device. This article is part of the IoT Virtual Bootcamp – Predict Temperature using Azure IoT & Raspberry Pi3.
- Execution Time: 30 minutes.
- Required Hardware:
- Windows 10 PC
- IoT Hardware kit: https://www.adafruit.com/product/3605 or similar hardware.
- Access to a WiFi network
- Required Operating System:
- Windows 10
- Other Requirements:
- Active Azure Subscription
Managing IoT Data using Stream Analytics, Blob Storage and Power BI
Stream Analytics is a fully managed event-processing engine that will help us to connect to external data sources, enabling our application to integrate certain data into the application flow, or to update an external database with processed information.
- Go to the Azure Portal and create a new Stream Analytics Job, this job also specifies a transformation; how to look for data, patterns, or relationships :
3. Now we will prepare the input for the data that we will be receiving form the IoT hardware. This input specifies from where the data comes. Click on Add and provide the proper parameter for your input:
4. Now we will prepare the output from the data we are processing through stream analytics. Click on Outputs:
5. Now Click on Add and provide the proper parameters for your desired output as shown in the image below:
In this case I´m using CSV as Event Serialization Format:
6. Now we have provided to Stream analytics our input and output. Stream Analytics offers a SQL-like query language for performing transformations and computations over streams of events. In this case we will modify our query as shown below:
The image below shows the default query that you should be looking at:
Now we will modify the query as follows:
**Note that you have to have a previously IoTHub deployed – please refer to Create an IoT Hub and connect your IoT Device
Enter the following query:
SELECT AVG(temperature), iothub.iothub.connectiondeviceid as deviceName, DATEPART(minute, System.TimeStamp) as minute, DATEPART(hour, System.TimeStamp) as hour, DATENAME(weekday, System.TimeStamp) as day, DATENAME(month, System.TimeStamp) as month, DATENAME(year, System.TimeStamp) as year INTO powerBi FROM iothub Group By TumblingWindow (minute, 1), iothub.iothub.connectiondeviceid SELECT * INTO blob FROM iothub
7. Now click on Start Job Now.
This could take couple of seconds:
8. Now let´s move on to integrate Power BI. To achieve Power Bi integration you must create a second output and specify PowerBI as desired output Alias and Authorize PowerBI on your associated account as shown below:
Go to http://powerbi.com/, and click Sign in then select “My Workspace”. Under Datasets, click Streaming dataset and then click the Create Report on the table “HandsonLab”. Then create a Line chart, using deviceName as the Legend and minute, hour day, month and year as the Axis. Lastly, change the val to Average of avg. Holding your hand over the sensor for over a minute will show the difference seen below:
9. Once you properly authorized Power BI through your account you should be able to go to Power Bi and review the data coming from your IoT Device:
This completes the Lab on Managing IoT Data using Stream Analytics, Blob Storage and Power BI. Please refer to the IoT Virtual Bootcamp – Predict Temperature using Azure IoT & Raspberry Pi3.