diff --git a/config.json b/config.json index 6a05db2..f587ee7 100644 --- a/config.json +++ b/config.json @@ -3,7 +3,8 @@ "amqp": [ "amqp://daemon:daemon@10.13.37.37:5672/" ], - "port": 3000 + "port": 3000, + "configPort": 3001 }, "connectors": { "dummy": { @@ -16,15 +17,16 @@ }, "lorawan": { "enabled": true, - "mqttserver": "mqtt://eu1.cloud.thethings.network:1883", - "username": "TTN_v3_MQTT_Username", - "password": "TTN_v3_MQTT_Password" + "mqttserver": "mqtt://eu.thethings.network:1883", + "username": "TTN_v2_APP_ID___OR___v3_MQTT_Username", + "password": "TTN_v2_APP_APIKEY__OR__TTN_v3_MQTT_Password" }, "dapnet": { "enabled": true, "endpoint": "http://hampager.de:8080/calls", "username": "DAPNET_Username", - "password": "DAPNET_Passwort" + "password": "DAPNET_Passwort", + "duplexTimeout": 300 } }, "pagers": { diff --git a/types/connectors/LoRaWANConnector.js b/types/connectors/LoRaWANConnector.js index 6080f5f..1aa3bbf 100644 --- a/types/connectors/LoRaWANConnector.js +++ b/types/connectors/LoRaWANConnector.js @@ -19,13 +19,14 @@ class LoRaWANConnector extends Connector { } async onMQTTConnect() { await this.client.subscribe(`v3/${ config.connectors.lorawan.username }/devices/#`) + await this.client.subscribe(`${ config.connectors.lorawan.username }/devices/#`) console.log('[lorawan] subscribed') } async onMQTTMessage(topic, message) { //if (topic.indexOf('/up') > -1) return const json = JSON.parse(Buffer.from(message).toString('utf-8')) console.log(topic, json) - if (!!json.uplink_message) { + if (!!json.uplink_message) { // TTN v3 this.connectorRegistry.events.emit('response', { ...json.uplink_message.decoded_payload, port: json.uplink_message.f_port, @@ -34,6 +35,15 @@ class LoRaWANConnector extends Connector { 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 \ No newline at end of file