birdy slim iot now has real random ID

master
cheetah 2 years ago
parent 7d116cfe95
commit e786715ab3

@ -12,7 +12,7 @@ class BirdySlim extends PagerDevice {
this.name = "birdyslim" this.name = "birdyslim"
} }
RandID() { RandID() {
return `B${ Str.random(4) }` return `${ Str.random(5) }`
} }
async formatTX(msg) { async formatTX(msg) {
msg.id = this.RandID() msg.id = this.RandID()
@ -38,7 +38,6 @@ class BirdySlim extends PagerDevice {
longitude: data.longitude, longitude: data.longitude,
} }
stateSet.lastLoRaPacket = data.metadata stateSet.lastLoRaPacket = data.metadata
console.log(data, stateSet)
/*if (!!data.metadata && !!data.metadata.uplink_message.rx_metadata) { /*if (!!data.metadata && !!data.metadata.uplink_message.rx_metadata) {
const rx_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) { switch (data.type) {
case 'ack': { case 'ack': {
switch (data.ack) { try {
case 'recv': switch (data.ack) {
require('../ConnectorRegistry').reportDelivered({ id: data.msgid }, `lorawan:${ data.device_id }`) case 'recv':
break; require('../ConnectorRegistry').reportDelivered({ id: data.msgid }, `lorawan:${ data.device_id }`)
case 'read': break;
require('../MessageManager').markMessageRead(data.msgid) case 'read':
break; require('../MessageManager').markMessageRead(data.msgid)
case 'operational': break;
require('../MessageManager').respondToMessage(data.msgid, data.operationalData) case 'operational':
break; 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; break;
case 'sos': case 'sos':
@ -71,14 +74,11 @@ class BirdySlim extends PagerDevice {
sos: data.sos, sos: data.sos,
date: data.date, date: data.date,
} }
break;
case 'status': case 'status':
case 'cannedMessage': case 'cannedMessage':
case 'low_battery': case 'low_battery':
case 'power': case 'power':
case 'battery': case 'battery':
case 'sos':
case 'gps': case 'gps':
require('../DeviceRegistry').deviceEvent(this.name, data.device_id, data) require('../DeviceRegistry').deviceEvent(this.name, data.device_id, data)
break; break;

Loading…
Cancel
Save