Skip to content

Commit

Permalink
fix(read): history read
Browse files Browse the repository at this point in the history
feat(discovery): new server discovery options
  • Loading branch information
biancode committed Jul 12, 2018
1 parent 3a6dcc4 commit 9c1b2be
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/locales/en-US/opcua-iiot-flex-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"users": "Users & Sets",
"settings": "Settings",
"security": "Security",
"ass": "Address Space"
"ass": "Address Space",
"discovery": "Discovery"
}
}
}
3 changes: 2 additions & 1 deletion src/locales/en-US/opcua-iiot-read.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"maxAge": "Max. Age",
"depth": "Depth",
"justValue": "Send Just Values",
"parseStrings": "Parse Result"
"parseStrings": "Parse Result",
"historyDays": "History Days"
}
}
}
8 changes: 6 additions & 2 deletions src/locales/en-US/opcua-iiot-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
"asoDemo": "ASO Demo",
"serverDiscovery": "Discovery",
"maxNodesPerRead": "Max per Read",
"maxNodesPerBrowse": "Max per Browse"
"maxNodesPerBrowse": "Max per Browse",
"registerServerMethod": "Register Server Method",
"discoveryServerEndpointUrl": "Endpoint Url",
"capabilitiesForMDNS": "MDNS capabilities"
},
"tabs-label": {
"users": "Users & Sets",
"settings": "Settings",
"security": "Security"
"security": "Security",
"discovery": "Discovery"
}
}
}
5 changes: 5 additions & 0 deletions src/opcua-iiot-discovery.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
color: "#ABCDEF",
defaults: {
name: {value: ""},
discoveryPort: {value: ''}
},
inputs: 1,
outputs: 1,
Expand All @@ -32,6 +33,10 @@
<label for="node-input-name"><i class="icon-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-input-name" placeholder="">
</div>
<div class="form-row">
<label for="node-input-discoveryPort"><i class="icon-tag"></i> <span data-i18n="node-red:common.label.discoveryPort"></span></label>
<input type="text" id="node-input-discoveryPort" placeholder="4840">
</div>
</script>

<script type="text/x-red" data-help-name="OPCUA-IIoT-Discovery">
Expand Down
6 changes: 5 additions & 1 deletion src/opcua-iiot-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ module.exports = function (RED) {
function OPCUAIIoTDiscovery (config) {
RED.nodes.createNode(this, config)
this.name = config.name
this.discoveryPort = config.discoveryPort || 4840

let discoveryServer = new coreDiscovery.core.nodeOPCUA.OPCUADiscoveryServer({})
let node = this
let discoveryServer = new coreDiscovery.core.nodeOPCUA.OPCUADiscoveryServer({port: node.discoveryPort})

node.status({fill: 'blue', shape: 'ring', text: 'new'})

Expand All @@ -47,8 +48,11 @@ module.exports = function (RED) {
if (discoveryServer !== null) {
discoveryServer.shutdown(function () {
coreDiscovery.internalDebugLog('shutdown')
done()
})
discoveryServer = null
} else {
done()
}
})
}
Expand Down
3 changes: 1 addition & 2 deletions src/opcua-iiot-flex-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,12 @@ module.exports = function (RED) {

let serverOptions = {
port: node.port,
// registerServerMethod: coreServer.core.nodeOPCUA.RegisterServerMethod.LDS, // TODO: Hidden, MDNS or LDS
nodeset_filename: xmlFiles,
resourcePath: node.endpoint || 'UA/NodeREDFlexIIoTServer',
buildInfo: {
productName: node.name || 'Node-RED Flex IIoT Server',
buildNumber: '24122017',
buildDate: new Date(2017, 12, 24)
buildDate: new Date(2018, 12, 24)
},
serverCapabilities: {
operationLimits: {
Expand Down
16 changes: 15 additions & 1 deletion src/opcua-iiot-read.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
justValue: {value: true},
showStatusActivities: {value: false},
showErrors: {value: false},
parseStrings: {value: false}
parseStrings: {value: false},
historyDays: {value: 1}
},
inputs: 1,
outputs: 1,
Expand All @@ -35,6 +36,7 @@
oneditprepare: function () {
try {
let depthRow = $("#node-input-depth-row")
let historyRow = $("#node-input-history-row")

if (parseInt(this.attributeId) === 99) {
depthRow.show();
Expand All @@ -50,6 +52,12 @@
} else {
depthRow.hide()
}

if ($(this).val() === "130") {
historyRow.show()
} else {
historyRow.hide()
}
})
} catch
(err) {
Expand Down Expand Up @@ -78,6 +86,12 @@
<option value="130">History</option>
</select>
</div>
<div id="node-input-history-row">
<div class="form-row">
<label for="node-input-historyDays"><i class="icon-calendar"></i> <span data-i18n="opcua-iiot-contrib.label.historyDays"></span></label>
<input type="text" id="node-input-historyDays" placeholder="1">
</div>
</div>
<div class="form-row">
<label for="node-input-maxAge"><i class="icon-random"></i> <span data-i18n="opcua-iiot-contrib.label.maxAge"></span></label>
<input type="text" id="node-input-maxAge" placeholder="1">
Expand Down
42 changes: 24 additions & 18 deletions src/opcua-iiot-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ module.exports = function (RED) {

function OPCUAIIoTRead (config) {
RED.nodes.createNode(this, config)
this.attributeId = config.attributeId || 0
this.maxAge = config.maxAge || 1
this.depth = config.depth || 1
this.attributeId = parseInt(config.attributeId) || 0
this.maxAge = parseInt(config.maxAge) || 1
this.depth = parseInt(config.depth) || 1
this.name = config.name
this.justValue = config.justValue
this.showStatusActivities = config.showStatusActivities
this.showErrors = config.showErrors
this.parseStrings = config.parseStrings
this.historyDays = parseInt(config.historyDays) || 1

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

let node = this
Expand Down Expand Up @@ -86,22 +88,26 @@ module.exports = function (RED) {
})
break
case 130:
let historyDate = new Date()
node.historyStart = new Date(historyDate.getDate() - 1)
node.historyEnd = historyDate

coreClient.readHistoryValue(session, itemsToRead, node.historyStart, node.historyEnd).then(function (readResult) {
try {
let message = node.buildResultMessage(msg, 'HistoryValue', readResult)
message.historyStart = node.historyStart
message.historyEnd = node.historyEnd
node.send(message)
} catch (err) {
let startDate = new Date()
node.historyStart = new Date()
node.historyStart.setDate(startDate - node.historyDays)
node.historyEnd = new Date()

coreClient.readHistoryValue(session, itemsToRead,
msg.payload.historyStart || node.historyStart,
msg.payload.historyEnd || node.historyEnd)
.then(function (readResult) {
try {
let message = node.buildResultMessage(msg, 'HistoryValue', readResult)
message.historyStart = node.historyStart
message.historyEnd = node.historyEnd
node.send(message)
} catch (err) {
node.handleReadError(err, msg)
}
}).catch(function (err) {
node.handleReadError(err, msg)
}
}).catch(function (err) {
node.handleReadError(err, msg)
})
})
break
default:
let item = null
Expand Down
49 changes: 44 additions & 5 deletions src/opcua-iiot-server.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
xmlsets: { value: [] },
publicCertificateFile: {value: ''},
privateCertificateFile: {value: ''},
registerServerMethod: {value: 1},
discoveryServerEndpointUrl: {value: ''},
capabilitiesForMDNS: {value: ''},
maxNodesPerRead: {value: 1000, validate:function(v) { return ((v === '') || (RED.validators.number(v) && (v > 0) && (v <= 100000))) }},
maxNodesPerBrowse: {value: 2000, validate:function(v) { return ((v === '') || (RED.validators.number(v) && (v > 0) && (v <= 200000))) }}
},
Expand Down Expand Up @@ -72,6 +75,11 @@
label: this._("opcua-iiot-contrib.tabs-label.users")
})

tabs.addTab({
id: "opcuaiiot-server-tab-discovery",
label: this._("opcua-iiot-contrib.tabs-label.discovery")
})

// User Management
if(node.users && node.users.length > 0) {
cacheItemCount = node.users.length
Expand Down Expand Up @@ -394,6 +402,42 @@
<input type="checkbox" id="node-input-showErrors" style="max-width:30px">
</div>
</div>
<div id="opcuaiiot-server-tab-discovery" style="display:none">
<div class="form-row">
<!-- SecurityPolicy enum via REST -->
<label for="node-input-registerServerMethod" style="min-width:160px"><i class="fa fa-discover"></i>
<span data-i18n="opcua-iiot-contrib.label.registerServerMethod"></span></label>
<select type="text" id="node-input-registerServerMethod">
<option value="1">HIDDEN</option>
<option value="2">MDNS</option>
<option value="3">LDS</option>
</select>
</div>
<div class="form-row">
<span style="min-width:160px">
<ul>
<li>HIDDEN: the server doesn't expose itself to the external world
<li>MDNS: the server publish itself to the mDNS Multicast network directly
<li>LDS: the server registers itself to the LDS or LDS-ME (Local Discovery Server)
</ul>
</span>
</div>
<div class="form-row">
<label for="node-input-serverDiscovery" style="min-width:160px"><i class="fa fa-cc-discover"></i>
<span data-i18n="opcua-iiot-contrib.label.serverDiscovery"></span></label>
<input type="checkbox" id="node-input-serverDiscovery" style="max-width:35px">
</div>
<div class="form-row">
<label for="node-input-discoveryServerEndpointUrl" style="min-width:160px"><i class="icon-discover"></i>
<span data-i18n="opcua-iiot-contrib.label.discoveryServerEndpointUrl"></span></label>
<input type="text" id="node-input-discoveryServerEndpointUrl" placeholder="opc.tcp://localhost:4840">
</div>
<div class="form-row">
<label for="node-input-capabilitiesForMDNS" style="min-width:160px"><i class="icon-discover"></i>
<span data-i18n="opcua-iiot-contrib.label.capabilitiesForMDNS"></span></label>
<input type="text" id="node-input-capabilitiesForMDNS" placeholder="NA,DA,..." >
</div>
</div>
<div id="opcuaiiot-server-tab-security" style="display:none">
<div class="form-row">
<!-- SecurityPolicy enum via REST -->
Expand Down Expand Up @@ -441,11 +485,6 @@
<span data-i18n="opcua-iiot-contrib.label.allowAnonymous"></span></label>
<input type="checkbox" id="node-input-allowAnonymous" style="max-width:35px">
</div>
<div class="form-row">
<label for="node-input-serverDiscovery" style="min-width:140px"><i class="fa fa-cc-discover"></i>
<span data-i18n="opcua-iiot-contrib.label.serverDiscovery"></span></label>
<input type="checkbox" id="node-input-serverDiscovery" style="max-width:35px">
</div>
</div>
<div id="opcuaiiot-server-tab-users" style="display:none">
<h4><span data-i18n="opcua-iiot-contrib.label.users"></span></h4>
Expand Down
29 changes: 27 additions & 2 deletions src/opcua-iiot-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ module.exports = function (RED) {
this.asoDemo = config.asoDemo
// discovery
this.disableDiscovery = !config.serverDiscovery
this.registerServerMethod = config.registerServerMethod || 1
this.discoveryServerEndpointUrl = config.discoveryServerEndpointUrl
this.capabilitiesForMDNS = (config.capabilitiesForMDNS) ? config.capabilitiesForMDNS.split(',') : [config.capabilitiesForMDNS]
// limits
this.maxNodesPerRead = config.maxNodesPerRead || 1000
this.maxNodesPerBrowse = config.maxNodesPerBrowse || 2000
Expand Down Expand Up @@ -122,15 +125,25 @@ module.exports = function (RED) {

coreServer.name = 'NodeREDIIoTServer'

switch (parseInt(node.registerServerMethod)) {
case 2:
node.registerServerMethod = coreServer.core.nodeOPCUA.RegisterServerMethod.MDNS
break
case 3:
node.registerServerMethod = coreServer.core.nodeOPCUA.RegisterServerMethod.LDS
break
default:
node.registerServerMethod = coreServer.core.nodeOPCUA.RegisterServerMethod.HIDDEN
}

let serverOptions = {
port: node.port,
// registerServerMethod: coreServer.core.nodeOPCUA.RegisterServerMethod.LDS, // TODO: Hidden, MDNS or LDS
nodeset_filename: xmlFiles,
resourcePath: node.endpoint || 'UA/NodeREDIIoTServer',
buildInfo: {
productName: node.name || 'NodeOPCUA IIoT Server',
buildNumber: '160417',
buildDate: new Date(2017, 4, 16)
buildDate: new Date(2018, 4, 16)
},
serverCapabilities: {
operationLimits: {
Expand Down Expand Up @@ -160,6 +173,18 @@ module.exports = function (RED) {
disableDiscovery: node.disableDiscovery
}

if (!node.disableDiscovery) {
serverOptions.registerServerMethod = node.registerServerMethod

if (node.discoveryServerEndpointUrl && node.discoveryServerEndpointUrl !== '') {
serverOptions.discoveryServerEndpointUrl = node.discoveryServerEndpointUrl
}

if (node.capabilitiesForMDNS && node.capabilitiesForMDNS.length) {
serverOptions.capabilitiesForMDNS = node.capabilitiesForMDNS
}
}

coreServer.detailDebugLog('serverOptions:' + JSON.stringify(serverOptions))
node.opcuaServer = new coreServer.core.nodeOPCUA.OPCUAServer(serverOptions)
node.opcuaServer.initialize(node.postInitialize)
Expand Down

0 comments on commit 9c1b2be

Please sign in to comment.