Alexander James Pane
Alexander James Pane

Reputation: 648

ThingsBoard IoT Gateway - Timestamp mapping timeseries in release 1.4.0

I've just upgraded my ThingsBoard IoT Gateway to the release 1.4.0, and I saw from the repository that it is now possible to map the published telemetry with client side timestamp. From my understanding this feature before was only possible by directly publishing to the ThingsBoard embedded MQTT broker, but not through the Gateway. From the repository I found that the previous mapping class (rep. branch 1.2) was the following:

public class KVMapping {
    private String key;
    private DataTypeMapping type;
    private String value;
}

While the new release (rep. branch 1.4) has the following class:

public class KVMapping {
    private String key;
    private DataTypeMapping type;
    private String value;
    private String ts;
    private String tsFormat;
}

From my understanding the timestamp feature (and the formatting style) have been added in the message mapping. My problem is that I'm unable to map the timestamp in the message I publish towards ThingsBoard. The platform still receives the correct key and value, but maps the data with the server side timestamp.

This is a code snippet of the python code I use to publish the packet to the external MQTT broker, that shows how my json packet is structured:

timeStamp = "1488273476000"
data = {
    "about": "Devices",
    "properties": [
        {
            "about": "Device1",
            "iotStateObservation": [
                {
                    "phenomenonTime": timeStamp,
                    "value": "1"
                }
            ]
        },
        {
            "about": "Device2",
            "iotStateObservation": [
                {
                    "phenomenonTime": timeStamp,
                    "value": "174468"
                }
            ]
        },
        {
            "about": "Device3",
            "iotStateObservation": [
                {
                    "phenomenonTime": timeStamp,
                    "value": "12"
                }
            ]
        }
    ]
}

This is a snippet from my ThingsBoard IoT gateway mapping file (mqtt-config.json), here configured all the wanted mapping:

{
    "topicFilter": "sensors",
    "converter": {
        "type": "json",
        "filterExpression": "$.properties[*]",
        "deviceNameJsonExpression": "${$.about}",
        "timeseries": [
            {
                "type": "double",
                "ts": "${$.iotStateObservation[0].phenomenonTime}",
                "key": "${$.about}",
                "value": "${$.iotStateObservation[0].value}"
            }
        ]
    }
}

Is there some mistake I'm committing in this procedure, or simply it is still not possible to map the data with client side timestamp yet?

Upvotes: 1

Views: 1449

Answers (1)

Alexander James Pane
Alexander James Pane

Reputation: 648

Ok, so after performing a better analysis of the thingsboard gateway code, I found out that for some reason it is still not possible to map the client side timestamp for a timeseries using MQTT. This functionality may be possible using HTTP, but didn't test this. So in order to add this feature I forked the repository and slightly changed the MQTT mapping routine to add this feature. if anyone is interested in this you can find the modified code on my repo.

Upvotes: 0

Related Questions