Provide timestamp in message to IoT central
Asked Answered
A

2

5

I want to connect a 'real device' with Azure IoT Central and connect a local source application to it using MQTT. I use this code for the connection and replace.

However, I cannot find any information on how to provide the timestamp. This thread suggests to set "iothub-creation-time-utc" as a "property" - I am not sure how to do that however. Is there any documentation on this?

Attire answered 19/3, 2019 at 14:59 Comment(0)
P
7

add the property to the message:

message.properties.add('iothub-creation-time-utc', utcDT);
Poussin answered 19/3, 2019 at 16:8 Comment(0)
Z
5

Based on the links in your question I assume you are using Node.js to develop your device code. There is a sample code snippet that shows how to set the creation time property here: https://learn.microsoft.com/en-us/azure/iot-accelerators/iot-accelerators-connecting-pi-node

function sendTelemetry(data, schema) {
  if (deviceOnline) {
    var d = new Date();
    var payload = JSON.stringify(data);
    var message = new Message(payload);
    message.properties.add('iothub-creation-time-utc', d.toISOString());
    message.properties.add('iothub-message-schema', schema);

    console.log('Sending device message data:\n' + payload);
    client.sendEvent(message, printErrorFor('send event'));
  } else {
    console.log('Offline, not sending telemetry');
  }
}
Zee answered 19/3, 2019 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.