From e786715ab38da89ca2dc521131537915f80fcdcb Mon Sep 17 00:00:00 2001 From: cheetah Date: Wed, 21 Dec 2022 02:10:31 +0100 Subject: [PATCH] birdy slim iot now has real random ID --- types/devices/BirdySlim.js | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/types/devices/BirdySlim.js b/types/devices/BirdySlim.js index 9567217..f2471e3 100644 --- a/types/devices/BirdySlim.js +++ b/types/devices/BirdySlim.js @@ -12,7 +12,7 @@ class BirdySlim extends PagerDevice { this.name = "birdyslim" } RandID() { - return `B${ Str.random(4) }` + return `${ Str.random(5) }` } async formatTX(msg) { msg.id = this.RandID() @@ -38,7 +38,6 @@ class BirdySlim extends PagerDevice { longitude: data.longitude, } stateSet.lastLoRaPacket = data.metadata - console.log(data, stateSet) /*if (!!data.metadata && !!data.metadata.uplink_message.rx_metadata) { const rx_metadata = data.metadata.uplink_message.rx_metadata @@ -46,24 +45,28 @@ class BirdySlim extends PagerDevice { switch (data.type) { case 'ack': { - switch (data.ack) { - case 'recv': - require('../ConnectorRegistry').reportDelivered({ id: data.msgid }, `lorawan:${ data.device_id }`) - break; - case 'read': - require('../MessageManager').markMessageRead(data.msgid) - break; - case 'operational': - require('../MessageManager').respondToMessage(data.msgid, data.operationalData) - break; + try { + switch (data.ack) { + case 'recv': + require('../ConnectorRegistry').reportDelivered({ id: data.msgid }, `lorawan:${ data.device_id }`) + break; + case 'read': + require('../MessageManager').markMessageRead(data.msgid) + break; + case 'operational': + require('../MessageManager').respondToMessage(data.msgid, data.operationalData) + break; + } + // If we have had a Ack. Event, we should store some Metadata about it too + require('../MessageManager').attachMetadata(data.msgid, { + ack: data.ack, + rssi: data.rssi, + date: data.date, + metadata: data.metadata, + }) + } catch (e) { + console.error('failed to report lorawan data for message', data.msgid) } - // If we have had a Ack. Event, we should store some Metadata about it too - require('../MessageManager').attachMetadata(data.msgid, { - ack: data.ack, - rssi: data.rssi, - date: data.date, - metadata: data.metadata, - }) } break; case 'sos': @@ -71,14 +74,11 @@ class BirdySlim extends PagerDevice { sos: data.sos, date: data.date, } - break; - case 'status': case 'cannedMessage': case 'low_battery': case 'power': case 'battery': - case 'sos': case 'gps': require('../DeviceRegistry').deviceEvent(this.name, data.device_id, data) break;