added TTN v2 MQTT Support

master
cheetah 4 years ago
parent 1155bef544
commit 22f835cefc

@ -3,7 +3,8 @@
"amqp": [ "amqp": [
"amqp://daemon:daemon@10.13.37.37:5672/" "amqp://daemon:daemon@10.13.37.37:5672/"
], ],
"port": 3000 "port": 3000,
"configPort": 3001
}, },
"connectors": { "connectors": {
"dummy": { "dummy": {
@ -16,15 +17,16 @@
}, },
"lorawan": { "lorawan": {
"enabled": true, "enabled": true,
"mqttserver": "mqtt://eu1.cloud.thethings.network:1883", "mqttserver": "mqtt://eu.thethings.network:1883",
"username": "TTN_v3_MQTT_Username", "username": "TTN_v2_APP_ID___OR___v3_MQTT_Username",
"password": "TTN_v3_MQTT_Password" "password": "TTN_v2_APP_APIKEY__OR__TTN_v3_MQTT_Password"
}, },
"dapnet": { "dapnet": {
"enabled": true, "enabled": true,
"endpoint": "http://hampager.de:8080/calls", "endpoint": "http://hampager.de:8080/calls",
"username": "DAPNET_Username", "username": "DAPNET_Username",
"password": "DAPNET_Passwort" "password": "DAPNET_Passwort",
"duplexTimeout": 300
} }
}, },
"pagers": { "pagers": {

@ -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
Loading…
Cancel
Save