Difference between revisions of "How to report data with timestamp"

From ESS-WIKI
Jump to: navigation, search
Line 8: Line 8:
  
  
<source lang="JSON">{
+
<syntaxhighlight lang="JAVA">{
 
"HWM": { 
 
"HWM": { 
 
"e": [
 
"e": [
Line 41: Line 41:
 
}
 
}
 
}
 
}
</source>Report Data Sample:
+
</syntaxhighlight>Report Data Sample:
  
<source lang="JSON"> {
+
<syntaxhighlight lang="JSON">{
 
"HWM": {
 
"HWM": {
 
"e": [
 
"e": [
Line 66: Line 66:
 
}
 
}
 
}
 
}
</source> In this case, the report data carried&nbsp;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.
+
</syntaxhighlight> In this case, the report data carried&nbsp;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 08:03, 26 October 2017

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"
	}
}
Report Data Sample:
{
	"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}
}