Skip to content

Commit

Permalink
Merge pull request #38 from kueblc/fix-config-issues
Browse files Browse the repository at this point in the history
Fix config issues
  • Loading branch information
biancode authored May 23, 2024
2 parents dfd8650 + 96cfeab commit daafd7f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
},
{
"name": "Fabio Huser (node-bacstack)"
},
{
"name": "Colin Kuebler (kueblc)"
}
],
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/bacnet-client.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
</div>
<div class="form-row">
<label for="node-config-input-interface"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.interface"></span></label>
<input type="text" id="node-config-input-interface" placeholder="127.0.0.1">
<input type="text" id="node-config-input-interface" placeholder="0.0.0.0">
</div>
<div class="form-row">
<label for="node-config-input-broadcastAddress"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.broadcastAddress"></span></label>
<input type="text" id="node-config-input-broadcastAddress" placeholder="127.0.0.255">
<input type="text" id="node-config-input-broadcastAddress" placeholder="0.0.0.255">
</div>
<div class="form-row">
<label for="node-config-input-port"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.port"></span></label>
Expand Down
16 changes: 6 additions & 10 deletions src/bacnet-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@ module.exports = function (RED) {
this.name = config.name
this.adpuTimeout = parseInt(config.adpuTimeout) || 6000
this.port = parseInt(config.port) || 47808
this.IPAddress = config.IPAddress || '0.0.0.0'
this.interface = config.interface || '0.0.0.0'
this.broadcastAddress = config.broadcastAddress || '0.0.0.255'

const node = this
node.devices = []

if (node.IPAddress) {
bacnetCore.internalDebugLog('client with IP settings')
node.client = new BACnet({ adpuTimeout: node.adpuTimeout, port: node.port, interface: node.IPAddress, broadcastAddress: node.broadcastAddress })
} else {
bacnetCore.internalDebugLog('client without IP settings')
node.client = new BACnet({ adpuTimeout: node.adpuTimeout, port: node.port })
}
function setupClient () {
node.client = new BACnet({ adpuTimeout: node.adpuTimeout, port: node.port, interface: node.interface, broadcastAddress: node.broadcastAddress })

if (node.client) {
node.client.on('iAm', (device) => {
node.devices.push(device)
bacnetCore.internalDebugLog('iAm Event')
Expand All @@ -52,10 +46,12 @@ module.exports = function (RED) {
node.client.close()
node.client = null
node.devices = []
node.client = new BACnet({ adpuTimeout: node.adpuTimeout, port: node.port, interface: node.IPAddress, broadcastAddress: node.broadcastAddress })
setupClient()
})
}

setupClient()

node.on('input', function (msg) {
msg.devices = node.devices
node.send(msg)
Expand Down
4 changes: 2 additions & 2 deletions src/bacnet-read.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
defaults: {
name: {value: ''},
objectType: {value: ''},
instance: {type: "BACnet-Instance", required:true},
instance: {type: "BACnet-Instance"},
propertyId: {value: ''},
device: {type: "BACnet-Device", required:true},
device: {type: "BACnet-Device"},
server: {type: "BACnet-Client", required:true},
multipleRead: {value: false}
},
Expand Down
18 changes: 13 additions & 5 deletions src/bacnet-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ module.exports = function (RED) {
this.propertyId = parseInt(config.propertyId)
this.multipleRead = config.multipleRead

this.instance = RED.nodes.getNode(config.instance)
this.objectInstance = parseInt(this.instance.instanceAddress) || 0

this.device = RED.nodes.getNode(config.device)
this.deviceIPAddress = this.device.deviceAddress || '127.0.0.1'
if (config.instance) {
this.instance = RED.nodes.getNode(config.instance)
this.objectInstance = this.instance.instanceAddress
} else {
this.objectInstance = 0
}

if (config.device) {
this.device = RED.nodes.getNode(config.device)
this.deviceIPAddress = this.device.deviceAddress
} else {
this.deviceIPAddress = '127.0.0.1'
}

this.connector = RED.nodes.getNode(config.server)

Expand Down
8 changes: 4 additions & 4 deletions src/bacnet-write.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
defaults: {
name: {value: ''},
objectType: {value: '', required:true, validate: RED.validators.number()},
instance: {type: "BACnet-Instance", required:true},
valueTag: {value: '', required:true, validate: RED.validators.number()},
instance: {type: "BACnet-Instance"},
valueTag: {value: '', validate: RED.validators.number()},
valueValue: {value: ''},
propertyId: {value: '', required:true, validate: RED.validators.number()},
propertyId: {value: '', validate: RED.validators.number()},
priority: {value: ''},
device: {type: "BACnet-Device", required:true},
device: {type: "BACnet-Device"},
server: {type: "BACnet-Client", required:true},
multipleWrite: {value: false}
},
Expand Down
16 changes: 12 additions & 4 deletions src/bacnet-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ module.exports = function (RED) {

this.multipleWrite = config.multipleWrite

this.instance = RED.nodes.getNode(config.instance)
this.objectInstance = parseInt(this.instance.instanceAddress) || 0
if (config.instance) {
this.instance = RED.nodes.getNode(config.instance)
this.objectInstance = this.instance.instanceAddress
} else {
this.objectInstance = 0
}

this.device = RED.nodes.getNode(config.device)
this.deviceIPAddress = this.device.deviceAddress || '127.0.0.1' // IPv6 it is :: - but configure Node-RED too
if (config.device) {
this.device = RED.nodes.getNode(config.device)
this.deviceIPAddress = this.device.deviceAddress
} else {
this.deviceIPAddress = '127.0.0.1'
}

this.connector = RED.nodes.getNode(config.server)

Expand Down

0 comments on commit daafd7f

Please sign in to comment.