Difference between revisions of "Script Adapter (Push)"

From Datonis
Jump to: navigation, search
m
(Script Tags)
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
| colspan="1" |Connect JS Script
 
| colspan="1" |Connect JS Script
 
| colspan="1" |String
 
| colspan="1" |String
| colspan="1" |URL address of the OPC UA server e.g. opc.tcp://localhost:12686/example
+
| colspan="1" |Script to be executed to connect to target device and set up listener. Script Tags can be used to do various jobs like sending (sender_val), receiving (receiver_val), alerting (alerter_val), logging (logger_val), publishing instruction to other adapters (writer_val), scheduling operations (executor_val).
 +
Context var persistent_val and transient_val are also available.  
 
|-
 
|-
 
| colspan="1" |Disconnect JS Script
 
| colspan="1" |Disconnect JS Script
 
| colspan="1" |String
 
| colspan="1" |String
| colspan="1" |Signifies whether the connection to OPC UA server is secure or not. If it is true then cert_alias option will be used
+
| colspan="1" |Script to be executed to disconnect to target device and clean up listener. Context var 'connection_val' holds return value of Connect JS script's return value. Context var 'executor_val', 'transient_val', 'presistent_val', 'kvstore_val' and 'logger_val' are available.
 
|-
 
|-
 
|Write Connection JS Script
 
|Write Connection JS Script
 
|String
 
|String
|Alias of the client certificate used for secure communication with OpcUA server. The private and public key of the certificate in .pem format has to be
+
|Script to be executed while executing instruction. Context var 'instruction_val' is set to instruction json values. Context var 'transient_val', 'presistent_val', 'kvstore_val' and 'logger_val' are available.
updated via Settings→Device SSL Certificate. The alias mentioned for certificate must match with the one specified in config-json. A default alias named opcua is available, its certificate can be found at {install_location}\aliot-4.0\data\keystore\opcua.pem
 
 
|-
 
|-
 
| colspan="1" |Additional Java library URLs
 
| colspan="1" |Additional Java library URLs
 
| colspan="1" |String
 
| colspan="1" |String
| colspan="1" |true value denotes that the connection endpoints will be discovered from the server_url and endpoint matching with security policy will be used for connection. 
+
| colspan="1" |URL paths of additional Java libraries (.jar) required by this connection and associated read/write tag scripts. All library URL paths must be comma seperated. e.g. file:/c:/mongo-driver/mongo-java-driver-3.6.2.jar, file:/c:/mongo-driver/snappy-java-1.1.4.jar
false value means the endpoint will be the same as server_url. Default value is true.
 
 
|-
 
|-
 
| colspan="1" |Tag JS Script
 
| colspan="1" |Tag JS Script
 
| colspan="1" |String
 
| colspan="1" |String
| colspan="1" |Possible values are http://opcfoundation.org/UA/SecurityPolicy#None, http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15, http://opcfoundation.org/UA/SecurityPolicy#Basic256,
+
| colspan="1" |Script to be executed during each to retrieve Tag value. Context var 'scan_val' holds received value of current scan. In case of write tag, context var 'tag_val' holds tag value set by instruction and 'connection_val' holds return value of write connection script. Context var 'transient_val', 'presistent_val', 'kvstore_val' and 'logger_val' are available.
http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256. The uri ending with None means no security policy is applied. Default value is Basic128Rsa15 uri.
 
 
|}
 
|}
  
Line 30: Line 28:
 
{| class="wikitable"
 
{| class="wikitable"
 
| colspan="1" |executor_val
 
| colspan="1" |executor_val
| colspan="1" |String
+
| colspan="1" |Is available for firing async tasks. Ex. This can be used to schedule at intervals etc.
| colspan="1" |Unique tag id defined in the context of the current thing_config. This is used further in metric_mappings or derived_tags or scan_tag_ids or monitor_tag_ids to refer to this tag value.
+
|-
 +
|sender_val
 +
|Sends value which is available in the scan_val for the tags. Example - sender_val.send()
 +
Usage - send(Object scanValue)
 
|-
 
|-
 
|transient_val
 
|transient_val
|String
+
|In memory map and can be used across connect/disconnect and through different adapters.
|The OPC UA tag definition which is present at OPC UA server e.g. ns=2;s=Channel1.Machine1.Tag1 or ns=0;i=2259. The format for tag is as follows:
+
Usage - transient_val.put(Object value)
ns=<namespace id>;s=<string identifier of the tag> OR ns=<namespace id>;i=<integer identifier of the tag>
 
 
 
For example: ns=2;s=Channel1.Machine1.Tag1
 
 
|-
 
|-
 
|persistent_val
 
|persistent_val
|String
+
|In memory file storage map which can be used across restart of Edge.
|
+
 
 +
Usage - persistent_val.put(Object value)
 
|-
 
|-
 
|kvstore_val
 
|kvstore_val
|String
+
|Can be used to create custom persistent maps.
|
 
 
|-
 
|-
 
|logger_val
 
|logger_val
|String
+
|Used for logging. Example - logger_val.info()
|
 
 
|-
 
|-
|reciever_val
+
|receiver_val
|String
+
|Receive values from other adapters which have send/scan internal set in their settings. Example - receiver_val.register()
|
+
 
 +
Usage - register(String adapterId, String messageType, Consumer<String> consumer)
 +
 
 +
Pass consumer by implementing method 'accept' which consumes the received message. 
 
|-
 
|-
 
|writer_val
 
|writer_val
|String
+
|This variable is used for publishing instruction to other sources (adapters). Example - writer_val.write()
|
+
 
 +
Usage - write(String adapterId, String thingKey, String instructionJson)
 
|-
 
|-
|Alerter_val
+
|alerter_val
|String
+
|This variable is used to generate alerts. Usage - alerter_val.alert()
|
+
 
 +
Usage - alert(String alertType, String message, String dataJson)
 +
 
 +
alert types - INFO, WARNING, ERROR, CRITICAL
 
|-
 
|-
 
|scan_val
 
|scan_val
|String
+
|This variable contains the value of the sent value which was sent using sender_val.send
|
 
 
|-
 
|-
|Tag_val
+
|tag_val
|String
+
|This variable contains the value of the write tag that is to be set by the instruction received by Edge.
|
 
|-
 
|Connection_val
 
|String
 
|
 
|}
 
 
 
== OPC UA Write Tag ==
 
{| class="wikitable"
 
| colspan="1" |tag_id
 
| colspan="1" |String
 
| colspan="1" |Unique tag id defined in the context of the current thing_config. This is used in Datonis instruction json to address this OPC UA tag.
 
 
|-
 
|-
|node_id
+
|connection_val
|String
+
|This holds the return value of the Write Connection JS script.
|The OPC UA tag definition which is present at OPC UA server e.g. ns=2;s=Channel1.Machine1.Tag1 or ns=0;i=2259. This tag must be writable i.e. Client Access property must be set to Read/Write. The format for tag is as follows:
 
ns=<namespace id>;s=<string identifier of the tag> OR ns=<namespace id>;i=<integer identifier of the tag> For example: ns=2;s=Channel1.Machine1.Tag1
 
 
|}
 
|}
  
== Launching OPC UA configuration screen ==
+
== Flow ==
 
+
Script Adapter (Push) is like writing a custom adapter with custom logic. Flexibility is given to do anything in the Script Adapter (Push). The Connect JS Script is executed when the Adapter is enabled. Functionality to send the data to datonis, receive values from other sources/adapters, generating alerts, publishing instructions to other sources, firing async tasks is provided using the above Script variables available in the script. If an instruction is executed from datonis then the Write Connection JS Script is executed and the return value is stored in connection_val and the value of the instruction tag is present in the tag_val. When the adapter is disabled, the Disconnect Js Script is executed and a variable - connection_val is available in this script which contains the return value of the Connect JS Script. logger_val and transient_val, persistent_val maps are available in all the scripts.
== Noting OPC UA url ==
 
 
 
== Adding Edge certificate to the trusted list ==
 
On configuring the Datonis Edge Gateway, it will error out with a certificate error: ServiceResultException: Bad_CertificateInvalid (0x80120000) "The certificate provided as a parameter is not valid.
 
 
 
In the OPC UA configuration window, select the Trusted Clients tab, you will find a new entry for 'OPC UA Adapter'. Right click it and select “Trust”. Disable and enable Gateway again.
 

Latest revision as of 06:56, 12 February 2020

Edge Gateway Home > Script Adapter (Push)

Script Adapter Fields

Connect JS Script String Script to be executed to connect to target device and set up listener. Script Tags can be used to do various jobs like sending (sender_val), receiving (receiver_val), alerting (alerter_val), logging (logger_val), publishing instruction to other adapters (writer_val), scheduling operations (executor_val).

Context var persistent_val and transient_val are also available.

Disconnect JS Script String Script to be executed to disconnect to target device and clean up listener. Context var 'connection_val' holds return value of Connect JS script's return value. Context var 'executor_val', 'transient_val', 'presistent_val', 'kvstore_val' and 'logger_val' are available.
Write Connection JS Script String Script to be executed while executing instruction. Context var 'instruction_val' is set to instruction json values. Context var 'transient_val', 'presistent_val', 'kvstore_val' and 'logger_val' are available.
Additional Java library URLs String URL paths of additional Java libraries (.jar) required by this connection and associated read/write tag scripts. All library URL paths must be comma seperated. e.g. file:/c:/mongo-driver/mongo-java-driver-3.6.2.jar, file:/c:/mongo-driver/snappy-java-1.1.4.jar
Tag JS Script String Script to be executed during each to retrieve Tag value. Context var 'scan_val' holds received value of current scan. In case of write tag, context var 'tag_val' holds tag value set by instruction and 'connection_val' holds return value of write connection script. Context var 'transient_val', 'presistent_val', 'kvstore_val' and 'logger_val' are available.

Script Tags

executor_val Is available for firing async tasks. Ex. This can be used to schedule at intervals etc.
sender_val Sends value which is available in the scan_val for the tags. Example - sender_val.send()

Usage - send(Object scanValue)

transient_val In memory map and can be used across connect/disconnect and through different adapters.

Usage - transient_val.put(Object value)

persistent_val In memory file storage map which can be used across restart of Edge.

Usage - persistent_val.put(Object value)

kvstore_val Can be used to create custom persistent maps.
logger_val Used for logging. Example - logger_val.info()
receiver_val Receive values from other adapters which have send/scan internal set in their settings. Example - receiver_val.register()

Usage - register(String adapterId, String messageType, Consumer<String> consumer)

Pass consumer by implementing method 'accept' which consumes the received message.

writer_val This variable is used for publishing instruction to other sources (adapters). Example - writer_val.write()

Usage - write(String adapterId, String thingKey, String instructionJson)

alerter_val This variable is used to generate alerts. Usage - alerter_val.alert()

Usage - alert(String alertType, String message, String dataJson)

alert types - INFO, WARNING, ERROR, CRITICAL

scan_val This variable contains the value of the sent value which was sent using sender_val.send
tag_val This variable contains the value of the write tag that is to be set by the instruction received by Edge.
connection_val This holds the return value of the Write Connection JS script.

Flow

Script Adapter (Push) is like writing a custom adapter with custom logic. Flexibility is given to do anything in the Script Adapter (Push). The Connect JS Script is executed when the Adapter is enabled. Functionality to send the data to datonis, receive values from other sources/adapters, generating alerts, publishing instructions to other sources, firing async tasks is provided using the above Script variables available in the script. If an instruction is executed from datonis then the Write Connection JS Script is executed and the return value is stored in connection_val and the value of the instruction tag is present in the tag_val. When the adapter is disabled, the Disconnect Js Script is executed and a variable - connection_val is available in this script which contains the return value of the Connect JS Script. logger_val and transient_val, persistent_val maps are available in all the scripts.