Skip to content

Commit

Permalink
Demonstrate normalized payload
Browse files Browse the repository at this point in the history
  • Loading branch information
johanstokking committed Sep 1, 2022
1 parent 14d51a2 commit 405f92d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
31 changes: 31 additions & 0 deletions vendor/laird/rs1xx-temp-rh-sensor-codec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ uplinkDecoder:
humidity: 52.33
alarmMsgCount: 256
backlogMsgCount: 1
normalizedOutput:
data:
- air:
temperature: 37.03888888888889
relativeHumidity: 52.33

- description: Send Temp and RH Aggregated Data Notification
input:
Expand All @@ -31,6 +36,16 @@ uplinkDecoder:
numberOfReadings: 2
timestamp: { year: 2015, month: 'January', day: 1, hours: 0, minutes: 0, seconds: 0 }
readings: [{ temperature: 98.67, humidity: 52.33 }, { temperature: 99.68, humidity: 53.34 }]
normalizedOutput:
data:
- time: '2015-01-01T00:00:00.000Z'
air:
temperature: 37.03888888888889
relativeHumidity: 52.33
- time: '2015-01-01T00:00:00.000Z'
air:
temperature: 37.6
relativeHumidity: 53.34

- description: Send Backlog Message Notification
input:
Expand All @@ -43,6 +58,12 @@ uplinkDecoder:
timestamp: { year: 2015, month: 'January', day: 1, hours: 0, minutes: 0, seconds: 2 }
temperature: 107.76
humidity: 61.42
normalizedOutput:
data:
- time: '2015-01-01T00:00:02.000Z'
air:
temperature: 42.08888888888889
relativeHumidity: 61.42

- description: Send Backlog Messages Notification
input:
Expand All @@ -58,6 +79,16 @@ uplinkDecoder:
{ timestamp: { year: 2015, month: 'January', day: 1, hours: 0, minutes: 0, seconds: 0 }, temperature: 107.76, humidity: 61.42 },
{ timestamp: { year: 2015, month: 'January', day: 1, hours: 0, minutes: 0, seconds: 0 }, temperature: 107.76, humidity: 61.42 },
]
normalizedOutput:
data:
- time: '2015-01-01T00:00:00.000Z'
air:
temperature: 42.08888888888889
relativeHumidity: 61.42
- time: '2015-01-01T00:00:00.000Z'
air:
temperature: 42.08888888888889
relativeHumidity: 61.42

- description: Send Sensor Config Simple Notification
input:
Expand Down
49 changes: 49 additions & 0 deletions vendor/laird/rs1xx-temp-rh-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3481,3 +3481,52 @@ function decodeUplink(input) {
return(result);
}

function normalizeUplink(input) {
parseDecodedTimestamp = (t) => {
return new Date(Date.UTC(
t.year,
monthTypeEnum.list.map(kv => kv.key).indexOf(t.month),
t.day,
t.hours,
t.minutes,
t.seconds,
)).toISOString();
}

let rootTimestamp;
if ('timestamp' in input.data) {
rootTimestamp = parseDecodedTimestamp(input.data.timestamp);
}

if ('humidity' in input.data && 'temperature' in input.data) {
return {
data: {
...(rootTimestamp ? { time: rootTimestamp } : {}),
air: {
relativeHumidity: input.data.humidity,
temperature: (input.data.temperature - 32) * 5 / 9
}
}
}
}

if ('readings' in input.data) {
return {
data: input.data.readings.map(r => {
let timestamp = rootTimestamp;
if ('timestamp' in r) {
timestamp = parseDecodedTimestamp(r.timestamp);
}
return {
...(timestamp ? { time: timestamp } : {}),
air: {
relativeHumidity: r.humidity,
temperature: (r.temperature - 32) * 5 / 9
}
}
})
}
}

return;
}

0 comments on commit 405f92d

Please sign in to comment.