Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Provide timestamp in message to IoT central

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?

like image 616
mkiesner Avatar asked Dec 24 '22 00:12

mkiesner


2 Answers

add the property to the message:

message.properties.add('iothub-creation-time-utc', utcDT);
like image 98
Roman Kiss Avatar answered Jan 22 '23 13:01

Roman Kiss


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');
  }
}
like image 42
Stefan Wick MSFT Avatar answered Jan 22 '23 12:01

Stefan Wick MSFT