Microsoft & Intel IoT Hackathon in Berlin

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

Last week we organized IoT hackathone (+ workshop) with Intel. The idea was to show how to build real-life IoT solution on Intel’s Edison Board connected to Azure Event Hub.

We created a simple Node.js application running  on Edison board, by using Intel’s XDK IoT Edition.
The full tutorial, which describes how to start tithe board including installation of required tools can be found here.

In this project we used an analog temperature sensor, which periodically delivers a temperature and posts it as event stream to Azure EventHub, by using service bus JS sdk

From there, we redirected a stream to Azure Stream Analytics  and evaluated runtime data. Finally result of evaluation delivered a hot-path events, which generate alerts when temperature exceeds 26 degree Celsius for more than 3 times in 2 minutes.

To be able to implement an IOT solution we used Intel’s ‘mraa’ Node.js library.
Here is an example, which shows how to setup ‘mraa’.
As next we define variable ‘button’ as GPIO input. Then we  start blinking of LED on GPIO3 with period of 1 second.
image 
image

image

imageimage
Here is the source code of the Node.js application., which we used in hackathon to read temperature and push event stream of temperature values to Azure Event Hub. 

var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

// This imports File System module.
var fs = require('fs');

// Here we read a Service Bus Java Script SDK vanilla JS API
filedata = fs.readFileSync(__dirname + '/client/Scripts/servicebusjssdk-1.2.js','utf8');

//.. and load it in JS context.
eval(filedata);

var mraa = require('mraa'); //require mraa

// Load Grove module for accessing sensors
var groveSensor = require('jsupm_grove');

// Create the temperature sensor object using AIO pin 0
var temp = new groveSensor.GroveTemp(0);
var i = 0;

   
var waiting = setInterval(function() {

    var celsius = temp.value();
    var fahrenheit = celsius * 9.0/5.0 + 32.0;
        console.log(celsius + " degrees Celsius, or " +
            Math.round(fahrenheit) + " degrees Fahrenheit");
    i++
      
    //EVENTHUB connection with JSSBSDK 
  var hubName = "telemetrydata";

            var ehClient = new EventHubClient(
           {
               'name': hubName,
               'devicename': 'edison_dev01', // This is by specification partition key.
               'namespace': "***",
               'sasKey': "***=",
               'sasKeyName': "***",
               'timeOut': 10,
           });

                var eventBody = { 'temperature': celsius, 'DeviceName': 'Damir-Edison' };

                var msg = new EventData(eventBody);

                    ehClient.sendMessage(msg, function (messagingResult) {
                        console.log(messagingResult.result);
                });

   
    }, 10000);

});

This is the script, which we used on the Azure side to analyze the real time data:

WITH CriticalEvents AS
(
    SELECT
        *
    FROM
      eventStream
    WHERE
        temperature > 26
)


-------------------------------
-- Copy all events to PowerBI
------------------------------

SELECT
*
INTO
      originalEvents
FROM  eventStream 

 

-------------------------------
-- Move all events to PowerBI
------------------------------
SELECT
   DateAdd(second,-5,System.TimeStamp) as WinStartTime,
   system.TimeStamp as WinEndTime,
   DeviceName,
   AVG(temperature) as AvgTemperature
 
INTO alleEentsBIOut

FROM eventStream

GROUP BY TumblingWindow(second, 5), DeviceName


----------------------------------------------------------------
-- Move all critical events to PowerBI
-- Critical is when we get more than 5 hot events in 15 seconds
----------------------------------------------------------------
SELECT
   DateAdd(second,-300,System.TimeStamp) as WinStartTime,
   system.TimeStamp as WinEndTime,
   DeviceName,
   MAX(temperature) as MaxTemperature,
   Count(*) as EventCount

INTO criticaleventsbiout

FROM CriticalEvents

GROUP BY TumblingWindow(second, 300), DeviceName
HAVING [EventCount] >=15




Following picture shows results in Power BI dashboard.
image image

 

And finally Microsoft Team.

image


Posted Jan 30 2016, 04:08 PM by Damir Dobric
developers.de is a .Net Community Blog powered by daenet GmbH.