Difference between revisions of "How to report data with timestamp"
Line 1: | Line 1: | ||
− | == Situation == | + | === Situation === |
In Handler, user can attach their timestamp into report data and capability with tag 'opTS'. | In Handler, user can attach their timestamp into report data and capability with tag 'opTS'. | ||
Line 8: | Line 8: | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="null">{ |
"HWM": { | "HWM": { | ||
"e": [ | "e": [ | ||
Line 43: | Line 43: | ||
</syntaxhighlight>Report Data Sample: | </syntaxhighlight>Report Data Sample: | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="null"> { |
"HWM": { | "HWM": { | ||
"e": [ | "e": [ | ||
Line 67: | Line 67: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | In this case, the report data carried timestamp as sensor data. But server process the timestamp as a single sensor data and cannot related to others snesor data. So user cannot query cpu1_volt with timestamp. | |
== Solution == | == Solution == |
Revision as of 07:55, 26 October 2017
Contents
Situation
In Handler, user can attach their timestamp into report data and capability with tag 'opTS'.
In original capability and report data, user only describe and report the sensor data without carry any timestamp or carried as a sensor data as below.
Capability Sample:
{
"HWM": {
"e": [
{
"n": "cpu1_volt",
"type": "volt",
"u": "V",
"max": 20,
"min": 10
},
{
"n": "cpu2_volt",
"type": "volt",
"u": "V",
"max": 20,
"min": 10
},
{
"n": "cpu1_temp",
"type": "temp",
"u": "Cel",
"max": 100,
"min": 10
},
{
"n": "timestamp",
"type": "tick",
"u": "millisec"
}
],
"bn": "HWM"
}
}
{
"HWM": {
"e": [
{
"n": "cpu1_volt",
"v": 10
},
{
"n": "cpu2_volt",
"v": 10
},
{
"n": "cpu1_temp",
"v": 10
},
{
"n": "timestamp",
"v": 1508998354
}
],
"bn": "HWM"
}
}
In this case, the report data carried timestamp as sensor data. But server process the timestamp as a single sensor data and cannot related to others snesor data. So user cannot query cpu1_volt with timestamp.
Solution
For RMM 3.3, user can carried the timestamp as a special tag 'opTS' in the capability or report, the server will store the timestamp related with each sensor data. The 'opTS' format is "opTS":{"$date":1508998354000}. The '$date' must be the milli seconds since Jan 01 1970 (UTC).
Capability Sample with Timestamp
{
"HWM": {
"e": [
{
"n": "cpu1_volt",
"type": "volt",
"u": "V",
"max": 20,
"min": 10
},
{
"n": "cpu2_volt",
"type": "volt",
"u": "V",
"max": 20,
"min": 10
},
{
"n": "cpu1_temp",
"type": "temp",
"u": "Cel",
"max": 100,
"min": 10
},
{
"n": "timestamp",
"type": "tick",
"u": "millisec"
}
],
"bn": "HWM"
},
"opTS":{"$date":1508998354000}
}
Report Data Sample with Timestamp
{
"HWM": {
"e": [
{
"n": "cpu1_volt",
"v": 10
},
{
"n": "cpu2_volt",
"v": 10
},
{
"n": "cpu1_temp",
"v": 10
},
{
"n": "timestamp",
"v": 1508998354
}
],
"bn": "HWM"
},
"opTS":{"$date":1508998354000}
}