AzureIoTHub: How to send telemetry data in JSON format? - azure

I used the example repo of Azure für sending telemetry data: https://github.com/Azure/azure-iot-arduino/tree/master/examples/esp8266/iothub_ll_telemetry_sample
I did not modify any code. This is the important part:
const char* telemetry_msg = "test_message";
message_handle = IoTHubMessage_CreateFromString(telemetry_msg);
result = IoTHubDeviceClient_LL_SendEventAsync(device_ll_handle, message_handle, send_confirm_callback, NULL);
Why does my body-result looks like an ASCII array? (Note: Using Azure IoT explorer)
Is it meant to be an array like this. Do I have to unpack this array on the other side?
I want to be able to send the data in JSON format like the azure device simulator does:

Nevermind, figured it out. The following example will send data in JSON format:
char telemetry_msg_buffer[80];
sprintf(telemetry_msg_buffer, "{\"temperature\":11.11,\"humidity\":12.12,\"scale\":\"13.13\"}");
message_handle = IoTHubMessage_CreateFromString(telemetry_msg_buffer);

Related

How to convert a 'dictionary-like' structure in Azure Stream Analytics to a multi dimensional array with a javascript UDF?

After using the CollectTop aggregation function of Azure Stream Analytics, I get back a json-like structure that seems to be like a Dictionary of Dictionaries.
I need to convert this one to a multi-dimensional array which I want to pass to an AzureML UDF.
My question is mostly on how I can interpret this structure in a javascript-UDF, as I'm totally new to Javascript.
This is a sample record (using CollectTop), but the challenge is how my javascript UDF should look like?
[
{"rank":1,"value":{"engineid":"engine001","tmp":-0.0019,"hum":-0.0002,"eventtime":4}},
{"rank":2,"value":{"engineid":"engine001","tmp":-0.0026,"hum":-0.0002,"eventtime":2}},
{"rank":3,"value":{"engineid":"engine001","tmp":0.0003,"hum":-0.0002,"eventtime":1}}
]
From the above data structure, I'd love to get the following array generated. (taking tmp & hum fields)
[[-0.0019, -0.0002], [-0.0026, -0.0002], [0.0003, -0.0002]]
Any help or insights are welcome.
This question is related to two other questions:
CollectTop is returning more rows than I would expect in Azure Stream Analytics
Call Azure Stream Analytics UDF with multi-dimensional array of last 5 records, grouped by record
Best regards
var input = [
{"rank":1,"value":{"engineid":"engine001","tmp":-0.0019,"hum":-0.0002,"eventtime":4}},
{"rank":2,"value":{"engineid":"engine001","tmp":-0.0026,"hum":-0.0002,"eventtime":2}},
{"rank":3,"value":{"engineid":"engine001","tmp":0.0003,"hum":-0.0002,"eventtime":1}}
];
console.log(getOutput(input));
function getOutput(input){
var output = [];
for(var x in input){
var array = [];
array.push(input[x].value.tmp);
array.push(input[x].value.hum);
output.push(array);
}
return output;
}
Is this your needed?

Azure FHIR: Get RawResource in Plain Text

I've just started my research on the "Azure FHIR SQL Server Version".
I had some issues trying to get the Json Resource in plain text, since It is stored compressed in the database (as shown in the following lines):
select r.RawResource from dbo.Resource r where r.IsHistory=0 and r.IsDeleted=0;
RAWRESOURCE
0x1F8B080000000000000A8492CB4EC2501086E7519AAE344122F7E04A4274618C90C8CEB8282D60136E2985A08477F79B39A71513D034E77466CECC3FFF5C0E124A2613D9C84AB64831F2483E65CD3F943BCE00EB4C22594A2A5FFC73FE2BB4502A9C5412EF579786B4898AA4234DEE1BB99531783152137B225DA431D6485A481DF408FB546AC8131FD9F0B839FA9E5BB10FDC1B64CDBD4572F966782C3999D9153F9463C949DF94E994A33E1AF366483BFCE7E014F5D561D4E2AB733A76B7398AF56E68111528D2CE47E4A069B4BE2D795D94487D7053EB538C3D300E01D608CEAABF4A0FCDD5A71C527B71CCFE8B0E3D1BAD74CE8999C1E2A4AA0D33D31E4DBC3564821F362765573953F71575D7E49A1C4D3EED429BBBEBBB781E53A50886F30B982F641C59C7356F1F2DB3ED5AC93DF32A62AB25FBCB99A6F8EEFFC8129CE409E4D17BFFCC2CE1737B5D7458F3B80E3B1CED790FEC2AF14F44ECFCA60432B49D4A2CCB83E7159035C352B50D69A10FE0A8B10DEB63319F18949C6A1CD36734ADDAD5B126DEEDF1DC7AA35BFADB2F00BDE3BDB5475BDBE2ACC41B1AC3ADAFF428DF000000FFFF
I tried different ways to get it, however no one was successful.
select cast(r.RawResource as varchar(max)) VarcharResource,
CONVERT(varchar(max), r.RawResource, 0) VarcharResource2
from dbo.Resource r where r.IsHistory=0 and r.IsDeleted=0;
VarcharResource2
‹ „’ËNÂP†çQš®4A""÷àJBtaŒÈθ(-`n)… „w÷›9§Ð4çtfÎÌ?ÿ\J&ÙÈJ¶H1òH>eÍ?”;Î ëL""YJ*_üsþ+´P*œTïW—†´‰Š¤#M1x1R{""]¤1ÖHZHôûTjÈÙð¸9úž[±ÜdͽErùfx,9™Ù?”cÉIߔ锣>ófH;üçàõÕaÔâ«s:v·9Šõnh(ÒÎGä i´¾-y]”H}pSëSŒ=0ÖΪ¿JÍÕ§R{qÌþ‹=­tΉ™Á⤪3ÓM¼5d‚6'eW9S÷u×äšM>íB›»ë»xS¥†ó˜/dYÇ5o-³íZÉ=ó*b«%ûË™¦øîÿÈœä äÑ{ÿÌ,ás{]tXó¸;íyì*ñODìü¦2´J,˃ç5ÃRµi¡à¨±ëc1Ÿ”œjÓg4­ÚÕ±&ÞíñÜz£[úÛ/ ½ã½µG[Ûâ¬Äí¯ô(ß ÿÿ
Anybody knows the correct way to get back the Json in plain text?
Thanks
The resources are Gzipped, so something like:
string rawResource;
using (rawResourceStream)
using (var gzipStream = new GZipStream(rawResourceStream, CompressionMode.Decompress))
using (var reader = new StreamReader(gzipStream, ResourceEncoding))
{
rawResource = await reader.ReadToEndAsync();
}

Generate dynamic CZML data using NodeJS

Cesium has the ability to render dynamic data that originates from a czml file. They have an example on their website showing how use the czml data on the client-side.
I'd like to generate czml data dynamically on the server-side using nodejs. Are there any pointers or examples on how that can be achieved?
There's an official czml-writer for C# and Java, and a 3rd-party czml writer for Python, but I'm not aware of any yet available for NodeJS.
It seems like one could easily output CZML from NodeJS just by calling JSON.stringify on an array of CZML packets (specially-formatted JavaScript objects). For dates and intervals, one could even import Cesium (or Cesium Core) into NodeJS for access to JulianDate and related time interval classes, to store in the appropriate fields.
You'll need to make sure the first element in the array is the "id" : "document" packet (as shown in the guide) with the settings for the rest of the CZML data, and that each subsequent packet provides a unique id of its own. After that just push some entity description packets into the array, and you should be good to go.
For earth orbiting objects, you can use the czml-writer npm package. Here's some basic usage:
var czml = require("czml-writer");
var orbit = new czml.orbit.fromParams({
apogee: 426.9, // km
perigee: 416.2, // km
inclination: 51.65, // deg
rightAscension: 304.1, // deg
argumentOfPeriapsis: 117.8 // deg
});
var output = orbit.czml();
var czml = require("czml-writer");
var tle = 'NOAA 14\n' +
'1 23455U 94089A 97320.90946019 .00000140 00000-0 10191-3 0 2621\n' +
'2 23455 99.0090 272.6745 0008546 223.1686 136.8816 14.11711747148495';
var orbit = new czml.orbit.fromTle(tle);
var output = orbit.czml();

How to render JSON using Stream Analytics Query

I have Inputs in the form of JSON stored in Blob Storage
I have Output in the form of SQL Azure table.
My wrote query and successfully moving value of specific property in JSON to corresponding Column of SQL Azure table.
Now for one column I want to copy entire JSON payload as Serialized string in one sql column , I am not getting proper library function to do that.
SELECT
CASE
WHEN GetArrayLength(E.event) > 0
THEN GetRecordPropertyValue(GetArrayElement(E.event, 0), 'name')
ELSE ''
END AS EventName
,E.internal.data.id as DataId
,E.internal.data.documentVersion as DocVersion
,E.context.custom As CustomDimensionsPayload
Into OutputTblEvents
FROM InputBlobEvents E
This CustomDimensionsPayload should be a JSON actually
I made a user defined function which did the job for me:
function main(InputJSON) {
var InputJSONString = JSON.stringify(InputJSON);
return InputJSONString;
}
Then, inside the Query, I used the function like this:
SELECT udf.ConvertToJSONString(COLLECT()) AS InputJSON
INTO outputX
FROM inputY
You need to just reference the input object itself instead of COLLECT() if you want the entire payload to be converted. I was trying to do this also so figured I'd add what i did.
I used the same function suggested by PerSchjetne, query then becomes
SELECT udf.JSONToString(IoTInputStream)
INTO [SQLTelemetry]
FROM [IoTInputStream]
Your output will now be the full JSON string, including all the metadata extras that IOT hub adds on.

How to get the blob data from Oracle in C#4.0?

Here i have a requriment to read the data from Oracle DB.In that one column is defined as BLOB.using that data i need to frame the insert query like this "insert into emp values('100','John',EMP_PIC);
Here emp_pic is defined as BLOB.Please suggest me some idea's about this.I am using C#4.0.
perhaps you can use this sample project based on this link. I hope this help.
http://www.codeproject.com/Articles/13365/Insert-retrieve-an-image-into-from-a-blob-field-in
if you wanna get value from blob data using OracleDataReader just convert first byte to image using this:
private Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
ms.Position = 0;
Image returnImage = Image.FromStream(ms);
return returnImage;
}
then read data blob like this:
picFileData.Image = byteArrayToImage(dr["EMP_PIC"] as byte[]); // dr is OracleDataReader dr;
picFileData is PictureBox from visual studio and EMP_PIC is blob column in Oracle
Try to use LINQ to SQL. This is very useful.

Resources