fastiot_core_services.opc_ua_reader package
Service to read out OPC UA data
For configuration please consult fastiot_core_services.opc_ua_reader.env.OPCUAEnv
and use a CSV-file.
The main idea is to configure the opc-ua nodes via a csv-file and deploy this service to publish the data as FastIoT-Things on a nats broker. See below example how to create your CSV-file.
- Features included:
Running multiple instances with different configurations
Different modes (polling & subscriptions)
A variety of connection params, e.g. security strings
Error handling of opcua connections
- Known limitations:
No “auto”-detection of opc-ua nodes supported
OPC-UA nodes must always be specified with nodeid (no browse name support)
No dynamic parsing of opc-ua nodes
No support of opc-ua functions
No support of opc-ua historic requests
Only nats-broker as data output supported
Example CSV configuration
Example CSV, to be stored as opc_ua_reader_things.csv
in a directory defined with
FASTIOT_OPC_UA_CONFIG_NAME
in the config_dir
.
nodeid,thing_name,machine
ns=2;i=5,a_sensor,sim_machine
Submodules
fastiot_core_services.opc_ua_reader.env module
- class fastiot_core_services.opc_ua_reader.env.OPCUARetrievalMode(value)[source]
An enumeration.
- subscription = 'subscription'
- polling = 'polling'
- polling_always = 'polling_always'
- class fastiot_core_services.opc_ua_reader.env.OPCUAEnv[source]
Environment variables for opc ua monitoring
- property endpoint_url: str
- FASTIOT_OPCUA_ENDPOINT_URL
The Endpoint Url to the OPC-UA Server, e.g. “opc.tcp://127.0.0.1:5000”
- property security_string: str
- FASTIOT_OPCUA_SECURITY_STRING
A security string if its needed, e.g. “Basic256Sha256,Sign,/path/to/certificate/test_certificate.der,/path/to/key/test_key.pem”
It is recommended to place needed certificates inside a config dir and locate it there.
- property application_uri: str
- FASTIOT_OPCUA_APPLICATION_URI
In rare cases it is needed to specify an application uri to connect to an OPC-UA Server which can be set with this env variable, e.g. “urn:freeopcua:client”
- property max_allowed_data_delay: float
- FASTIOT_OPCUA_MAX_ALLOWED_DATA_DELAY
The maximum allowed data delay for opc-ua connections in seconds. If no data changes happen over this timespan, the connection to the machine is considered lost. This value must be positive. A value of zero means the connection is never considered lost.
- property polling_delay: float
- FASTIOT_OPCUA_POLLING_DELAY
The polling delay specifies the delay between polling opcua node cycles. This value is only applied if retrieval mode is polling, which is the default behavior, or polling_always. Otherwise this variable is ignored. Must be positive. A value of zero means no wait interval which may result in high server load.
- property retrieval_mode: OPCUARetrievalMode
- FASTIOT_OPCUA_RETRIEVAL_MODE
Can be one of ‘polling’ (default), ‘polling_always’ or ‘subscription’.
Polling mode requests all OPC-UA nodes in a loop. You can specify the loop delay via ‘FASTIOT_OPCUA_POLLING_DELAY’. If you use ‘polling_always’, it will publish a value for each value retrieved. Running in ‘polling’ will only publish all values in the first run and in consecutive loop runs it will only publish value changes.
If using subscriptions mode, it will utilize OPC-UA Subscriptions to publish retrieved value changes; depending on the OPC-UA Server implementation. This can be useful when working with many OPC-UA nodes where polling takes too long to complete. Please note that Subscriptions are an optional OPC-UA feature and not all Servers might support it nor might provide a stable implementation. It is recommended when using subscriptions, to also use ‘FASTIOT_OPCUA_MAX_ALLOWED_DATA_DELAY’ to handle connection errors.
Generally speaking, polling is useful for a small number of nodes <10 and subscriptions for many nodes >1000 depending on the usecase. (There is no general answer what is better for values between 10 and 1000.)
- property opc_ua_reader_config_dir: str
- FASTIOT_OPC_UA_CONFIG_NAME
Specify a config name. This can be useful when running multiple instances of machine monitoring with a different opc-ua node configuration inside the config_dir. Defaults to “opc_ua_reader” and is relative to the config dir.
- property opc_ua_reader_error_logfile: str
- FASTIOT_OPC_UA_ERROR_LOGFILE
Specify an error log file. In this error log file are connection errors logged. If there is any error logged, the machine monitor is marked as unhealthy and depending on the deployment is restarted.
This can be useful if the OPC-UA Server has unstable subscriptions - so when they break the service is restarted.