added lorawan downlink+duplexTimeout
This commit is contained in:
parent
b0195e8e49
commit
2e614ccc6a
3 changed files with 37 additions and 0 deletions
|
@ -22,6 +22,7 @@
|
||||||
},
|
},
|
||||||
"lorawan": {
|
"lorawan": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
|
"duplexTimeout": 1800,
|
||||||
"mqttserver": "mqtt://eu.thethings.network:1883",
|
"mqttserver": "mqtt://eu.thethings.network:1883",
|
||||||
"username": "TTN_v2_APP_ID___OR___v3_MQTT_Username",
|
"username": "TTN_v2_APP_ID___OR___v3_MQTT_Username",
|
||||||
"password": "TTN_v2_APP_APIKEY__OR__TTN_v3_MQTT_Password"
|
"password": "TTN_v2_APP_APIKEY__OR__TTN_v3_MQTT_Password"
|
||||||
|
|
|
@ -48,6 +48,9 @@
|
||||||
<label for="lorawan_enabled">Enabled:</label>
|
<label for="lorawan_enabled">Enabled:</label>
|
||||||
<input type="checkbox" id="lorawan_enabled"/>
|
<input type="checkbox" id="lorawan_enabled"/>
|
||||||
</br>
|
</br>
|
||||||
|
<label for="lorawan_duplex_timeout">Duplex Timeout(in seconds) : recommended value equals LPWAN-FetchTime</label>
|
||||||
|
<input type="number" min="10" max="9000" id="lorawan_duplex_timeout"/>
|
||||||
|
</br>
|
||||||
<label for="lorawan_mqttserver">MQTT Endpoint:</label>
|
<label for="lorawan_mqttserver">MQTT Endpoint:</label>
|
||||||
<input type="text" id="lorawan_mqttserver"/>
|
<input type="text" id="lorawan_mqttserver"/>
|
||||||
<button onClick="setLoRaWANMQTT('mqtt://eu.thethings.network:1883')">Preset TTNv2</button>
|
<button onClick="setLoRaWANMQTT('mqtt://eu.thethings.network:1883')">Preset TTNv2</button>
|
||||||
|
@ -104,6 +107,7 @@
|
||||||
$('#dapnet_password').val(config.connectors.dapnet.password)
|
$('#dapnet_password').val(config.connectors.dapnet.password)
|
||||||
// connectors.dapnet
|
// connectors.dapnet
|
||||||
$('#lorawan_enabled').attr('checked', config.connectors.lorawan.enabled)
|
$('#lorawan_enabled').attr('checked', config.connectors.lorawan.enabled)
|
||||||
|
$('#lorawan_duplex_timeout').val(config.connectors.lorawan.duplexTimeout)
|
||||||
$('#lorawan_mqttserver').val(config.connectors.lorawan.mqttserver)
|
$('#lorawan_mqttserver').val(config.connectors.lorawan.mqttserver)
|
||||||
$('#lorawan_username').val(config.connectors.lorawan.username)
|
$('#lorawan_username').val(config.connectors.lorawan.username)
|
||||||
$('#lorawan_password').val(config.connectors.lorawan.password)
|
$('#lorawan_password').val(config.connectors.lorawan.password)
|
||||||
|
@ -125,6 +129,7 @@
|
||||||
newConfig.connectors.dapnet.password = $('#dapnet_password').val()
|
newConfig.connectors.dapnet.password = $('#dapnet_password').val()
|
||||||
// connectors.lorawan
|
// connectors.lorawan
|
||||||
newConfig.connectors.lorawan.enabled = $('#lorawan_enabled').prop('checked')
|
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.mqttserver = $('#lorawan_mqttserver').val()
|
||||||
newConfig.connectors.lorawan.username = $('#lorawan_username').val()
|
newConfig.connectors.lorawan.username = $('#lorawan_username').val()
|
||||||
newConfig.connectors.lorawan.password = $('#lorawan_password').val()
|
newConfig.connectors.lorawan.password = $('#lorawan_password').val()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const Connector = require("./Connector")
|
const Connector = require("./Connector")
|
||||||
const config = require('../../config.json')
|
const config = require('../../config.json')
|
||||||
|
const md5 = require('md5')
|
||||||
|
|
||||||
class LoRaWANConnector extends Connector {
|
class LoRaWANConnector extends Connector {
|
||||||
// this is optimized for only receiving LoRa uplink Messages (from Birdy Pagers)
|
// 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/#`)
|
await this.client.subscribe(`${ config.connectors.lorawan.username }/devices/#`)
|
||||||
console.log('[lorawan] subscribed')
|
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 <deviceID#fPort>'
|
||||||
|
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) {
|
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'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue