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); });
|