diff --git a/config.json b/config.json
index 62730fd..19e68d0 100644
--- a/config.json
+++ b/config.json
@@ -22,6 +22,7 @@
},
"lorawan": {
"enabled": true,
+ "duplexTimeout": 1800,
"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"
diff --git a/html/index.html b/html/index.html
index 101b349..750412f 100644
--- a/html/index.html
+++ b/html/index.html
@@ -48,6 +48,9 @@
+
+
+
@@ -104,6 +107,7 @@
$('#dapnet_password').val(config.connectors.dapnet.password)
// connectors.dapnet
$('#lorawan_enabled').attr('checked', config.connectors.lorawan.enabled)
+ $('#lorawan_duplex_timeout').val(config.connectors.lorawan.duplexTimeout)
$('#lorawan_mqttserver').val(config.connectors.lorawan.mqttserver)
$('#lorawan_username').val(config.connectors.lorawan.username)
$('#lorawan_password').val(config.connectors.lorawan.password)
@@ -125,6 +129,7 @@
newConfig.connectors.dapnet.password = $('#dapnet_password').val()
// connectors.lorawan
newConfig.connectors.lorawan.enabled = $('#lorawan_enabled').prop('checked')
+ newConfig.connectors.lorawan.duplexTimeout = parseInt($('#lorawan_duplex_timeout').val())
newConfig.connectors.lorawan.mqttserver = $('#lorawan_mqttserver').val()
newConfig.connectors.lorawan.username = $('#lorawan_username').val()
newConfig.connectors.lorawan.password = $('#lorawan_password').val()
diff --git a/types/connectors/LoRaWANConnector.js b/types/connectors/LoRaWANConnector.js
index 48bbad6..ddfe023 100644
--- a/types/connectors/LoRaWANConnector.js
+++ b/types/connectors/LoRaWANConnector.js
@@ -1,5 +1,6 @@
const Connector = require("./Connector")
const config = require('../../config.json')
+const md5 = require('md5')
class LoRaWANConnector extends Connector {
// this is optimized for only receiving LoRa uplink Messages (from Birdy Pagers)
@@ -22,6 +23,36 @@ class LoRaWANConnector extends Connector {
await this.client.subscribe(`${ config.connectors.lorawan.username }/devices/#`)
console.log('[lorawan] subscribed')
}
+
+ async transmitMessage(msg, params) {
+ const UUID = this.name+':'+md5(JSON.stringify([this.name,...params]))
+ if (params.length < 1) return false
+ const target = params[0]
+ if (target.split('#').length !== 2) throw 'No valid LoRaWAN Parameter '
+ const deviceID = target.split('#')[ 0 ], fPort = target.split('#')[ 1 ]
+ const mqttTopic = `v3/${ config.connectors.lorawan.username }/devices/${ deviceID }/down/push`
+ const mqttPayload = {
+ downlinks:[
+ {
+ f_port: fPort,
+ frm_payload: Buffer.from(msg.payload, 'utf-8').toString('base64'),
+ priority: "NORMAL",
+ }
+ ]
+ }
+
+ console.log (mqttTopic, mqttPayload)
+ this.client.publish(mqttTopic, JSON.stringify(mqttPayload))
+ .then(() => {
+ this.connectorRegistry.reportState(msg, UUID, 'routed')
+ return true
+ })
+ .catch((err) => {
+ console.error(err)
+ this.connectorRegistry.reportFail(msg, UUID)
+ return false
+ })
+ }
async onMQTTMessage(topic, message) {
//if (topic.indexOf('/up') > -1) return
const json = JSON.parse(Buffer.from(message).toString('utf-8'))