1
votes

I tried to collect pressure values by using Node.js in my Raspberry Pi and Azure Stream Analytics in my Azure IoT Hub. I sent the data to IoT Hub as JSON file using this code :

var data = JSON.stringify({ 
               deviceId: "myRaspi10",
               pressureVal: value, 
               time:Date.now() 
           });

When I checked the console, here's what being sent to the Hub

{
    "deviceId":"myRaspi10",
    "pressureVal":39,
    "time":1470642749428
}

How to convert the time value into timestamp in the Azure Stream Analytics?

3
Try sending new Date() instead of Date.now(). It will produce a string output like "2016-08-08T08:22:34.905Z", which may be Azure Stream Analytics would treat like a date. (Haven't used it though, just an idea). - Andrew Sklyarevsky
@AndrewSklyarevsky will do, currently checking Date section in SO Documentation. Do you have any idea how to simplify the Date() into time only, like "12.34.56.789"? - Muhamad Iqbal
See an answer to a different question on SO: stackoverflow.com/a/16426519/894973 - Andrew Sklyarevsky
I've tried various ways, and answer from @AndrewSklyarevsky are the most helpful one. Mind if you create an answer for that? So I can vote it - Muhamad Iqbal
Oh, cool, I don't actually use Azure Stream Analytics but I am glad that that idea helped you. - Andrew Sklyarevsky

3 Answers

1
votes

@nobodykid, you can use Stream Analyics Query Language to convert time from bigint to datetime as below.

CAST(time AS datetime)

Please refer to the buildin CAST function and the supported data types for conversions.

0
votes

Try sending new Date() instead of Date.now(). It will produce a string output like "2016-08-08T08:22:34‌​.905Z" which may be Azure Stream Analytics would treat like a date. (Haven't used it though, just an idea).

0
votes

According to Azure stream Analytics date type references https://msdn.microsoft.com/en-us/library/azure/dn835065.aspx datetime is represented as string converted to datetime following ISO 8601 standard.

Use javascript Date object and call toISOString() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString