Skip to content

Commit

Permalink
fix(wirepas): ignore diagnostic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Feb 12, 2024
1 parent 8ca0a08 commit 969f92c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions wirepas-5g-mesh-gateway/decodePayload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,15 @@ void describe('decodePayload()', () => {
assert.deepEqual(decodePayload(Buffer.from('030101', 'hex')), {
led: { b: true },
}))

void it('should ignore messages starting with bf', () =>
assert.deepEqual(
decodePayload(
Buffer.from(
'bf1840820118191845890119c31c000019022918fa190a9e0000184186011a0a175ab41a0a175ab418ff00001842820000182e8218ff0018180001140502040607030818ff181a01181b011830011831241201ff',
'hex',
),
),
{},
))
})
9 changes: 9 additions & 0 deletions wirepas-5g-mesh-gateway/decodePayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Byte 1: ID (0x03)
Byte 2: Color. 0x00: red, 0x01: blue, 0x02: green
Byte 3: State. 0x00: off, 0x01: on.
## Diagnostic messages
Concerning the message starting with BF, it does not come from the Thingy: these are diagnostic messages giving information about the network. You can safely ignore them too.
*/
export const decodePayload = (
payload: Uint8Array,
Expand All @@ -71,6 +75,11 @@ export const decodePayload = (

let message: Wirepas5GMeshNodePayload = {}

// Diagnostic special case
if (msg.peek() === parseInt('BF', 16)) {
return {}
}

// Button special case
if (payload.length === 3 && msg.peek() === 1) {
msg.next() // skip type
Expand Down
1 change: 0 additions & 1 deletion wirepas-5g-mesh-gateway/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ setInterval(async () => {
await Promise.all(
Object.entries(nodes).map(async ([gwId, nodes]) => {
Object.entries(nodes).forEach(([nodeId, data]) => {
debug()
debug(gwId, nodeId, JSON.stringify(data))
})

Expand Down

0 comments on commit 969f92c

Please sign in to comment.