Search code examples
azureazure-iot-central

How to report telemetry to IOTCentral?


I can't figure out how to report telemetry to IOTCentral.

I created a Device Template, added a Telemetry measurement, Field Name "freeDiskSpace", Maximum Value 999999999999. Got a device associated with the template. Fired up the device code, but looking at the device in Device Explorer of IOTCentral it only says "Missing Data".

First I tried:

const upd = {};
upd.freeDiskSpace = info.available;
deviceTwin.properties.reported.update(upd, function (err) {

and in the debugger I could see the twin received the data

Got device twin
{ reported:
   { update: [Function: update],
     freeDiskSpace: 468716691456,
     '$version': 4 },

But nothing in IOTCentral.

Then I noticed how they were sending down desired properties:

desired:
 { setCurrent: { value: 0 },

so I tried

const upd = {};
upd.freeDiskSpace = { value: info.available };
deviceTwin.properties.reported.update(upd, function (err) {

but still nothing in IOTCentral.


Solution

  • A comment on another question pointed me to https://learn.microsoft.com/en-us/azure/iot-central/howto-connect-nodejs which I had somehow never found in all my searching. The key point is that telemetry is reported as an event, not as a reported property. This is counterintuitive to me because I understand an "event" to be a distinct meaningful incident versus "telemetry" being continuous data. But it works. Code snippet from that link:

      var data = JSON.stringify({
        temperature: temperature,
        humidity: humidity,
        pressure: pressure,
        fanmode: (temperature > 25) ? "1" : "0",
        overheat: (temperature > 35) ? "ER123" : undefined });
      var message = new Message(data);
      client.sendEvent(message, (err, res) =>