How to report data with timestamp
From ESS-WIKI
Revision as of 08:00, 26 October 2017 by Scott68.chang (talk | contribs)
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"
}
}
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}
}
{
"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}
}