Sending a timestamp

When we talk about the timestamp, we are referring to the time that a reading was taken on a sensor (an asset), or when the sensor detected an event occurring. 

The timestamp format must be in Unix Microtime, the number of seconds or milliseconds since 1 January 1970. (You can choose whether you want to use seconds, milliseconds, or both seconds and milliseconds in the Global Setup Options.)

There are three ways to handle timestamps:

  1. The device can omit the timestamp
  2. The device can send the timestamp for a single asset when it sends data.
  3. The device can send data for a set of readings from one asset.

No timestamp

In case (i), the device doesn't include a timestamp in the data it sends. When the data arrives at the Assetwolf portal, Assetwolf automatically assigns a timestamp to the data. This option is commonly used where it's not critical to record the precise time when something occurred, or when a reading was taken; it also reduces data transfer.

Timestamp included

In case (ii), the device can include a timestamp for the data object that it is sending. For example, like this:

    "timestamp": timestamp,
    "field1": boolean,
    "field2": integer ...

The timestamp is assumed to be measured accurately on the device, and this timestamp will be recorded against the data object when stored in the Assetwolf data archive.

Remember that in MQTT the device ID is set by the MQTT topic, so there is no need to include it in the data object.

Multiple timestamps

Case (iii) above describes how a device can send a list of readings for a single asset. 

    "timestamp": timestamp1,
    "field1": boolean,
    "field2": integer ...
}, {
    "timestamp": timestamp2,
    "field1": boolean,
    "field2": integer ...

In this case note the square brackets [ and ]. These are needed because the outer array contains one or many arrays inside it.

This method may be used if your application can tolerate there being a delay between a reading being taken from a sensor, and it being sent to the portal. For example, if transmission is costly or a device must only wake up occasionally to transmit, it allows it to batch up many objects of data into one larger object that is sent once.