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?

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51
mkiesner
  • 635
  • 5
  • 20

2 Answers2

7

add the property to the message:

message.properties.add('iothub-creation-time-utc', utcDT);
Roman Kiss
  • 7,925
  • 1
  • 8
  • 21
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');
  }
}
Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51