|
|
@ -19,13 +19,14 @@ class LoRaWANConnector extends Connector {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async onMQTTConnect() {
|
|
|
|
async onMQTTConnect() {
|
|
|
|
await this.client.subscribe(`v3/${ config.connectors.lorawan.username }/devices/#`)
|
|
|
|
await this.client.subscribe(`v3/${ config.connectors.lorawan.username }/devices/#`)
|
|
|
|
|
|
|
|
await this.client.subscribe(`${ config.connectors.lorawan.username }/devices/#`)
|
|
|
|
console.log('[lorawan] subscribed')
|
|
|
|
console.log('[lorawan] subscribed')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async onMQTTMessage(topic, message) {
|
|
|
|
async onMQTTMessage(topic, message) {
|
|
|
|
//if (topic.indexOf('/up') > -1) return
|
|
|
|
//if (topic.indexOf('/up') > -1) return
|
|
|
|
const json = JSON.parse(Buffer.from(message).toString('utf-8'))
|
|
|
|
const json = JSON.parse(Buffer.from(message).toString('utf-8'))
|
|
|
|
console.log(topic, json)
|
|
|
|
console.log(topic, json)
|
|
|
|
if (!!json.uplink_message) {
|
|
|
|
if (!!json.uplink_message) { // TTN v3
|
|
|
|
this.connectorRegistry.events.emit('response', {
|
|
|
|
this.connectorRegistry.events.emit('response', {
|
|
|
|
...json.uplink_message.decoded_payload,
|
|
|
|
...json.uplink_message.decoded_payload,
|
|
|
|
port: json.uplink_message.f_port,
|
|
|
|
port: json.uplink_message.f_port,
|
|
|
@ -34,6 +35,15 @@ class LoRaWANConnector extends Connector {
|
|
|
|
metadata: json,
|
|
|
|
metadata: json,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!!json.app_id && json.app_id == config.connectors.lorawan.username) { // TTN v2
|
|
|
|
|
|
|
|
this.connectorRegistry.events.emit('response', {
|
|
|
|
|
|
|
|
...json.payload_fields,
|
|
|
|
|
|
|
|
port: json.port,
|
|
|
|
|
|
|
|
date: new Date(json.metadata.time),
|
|
|
|
|
|
|
|
device_id: json.dev_id,
|
|
|
|
|
|
|
|
metadata: json,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = LoRaWANConnector
|
|
|
|
module.exports = LoRaWANConnector
|