OPC
15 min
the opc ua module manages the opc ua server on litmus edge service configuration, security policies, and the node hierarchy imports from litmussdk import opc all functions are accessible directly from the opc namespace service management start / stop opc start stop opc(start=true) opc start stop opc(start=false) service configuration \# get current config config = opc get service config() \# {host, port, nodesunderroot, } \# update config opc change service config( host="0 0 0 0", port=4840, nodes under root=true, ) security and authentication \# get current settings settings = opc get security and auth settings() \# update policies opc change security and auth settings( enabled security modes=\["none", "sign", "signandencrypt"], enabled security policies=\["basic256sha256", "aes128 sha256 rsaoaep"], enabled auth modes=\["anonymous", "password"], ) valid enabled security modes "none" , "sign" , "signandencrypt" valid enabled security policies "basic256sha256" , "basic256" , "basic128rsa15" , "aes128 sha256 rsaoaep" , "aes256 sha256 rsapss" valid enabled auth modes "anonymous" , "certificate" , "password" certificates and metrics certs = opc get server certificates() # dict metrics = opc get server metrics() # dict hierarchy the opc hierarchy is a tree of folder , device , and tag nodes viewing the hierarchy \# root node root = opc get root node() \# specific nodes by path nodes = opc get node by paths(\["edgedevice/myfolder", "edgedevice/myfolder/mydevice"]) \# export entire hierarchy as json hierarchy = opc export as json() adding nodes \# folder folder id = opc add node folder( name="myfolder", parent id="edgedevice", worker node id mode="hierarchical", # or "fixed" ) \# device (under a folder) device id = opc add node device( name="mydevice", parent id=folder id, ) \# tag (under a device) tag = opc add node tag( name="pressure", parent id=device id, data type="uint32", topic name="plant/pump/01/pressure", ) worker node id mode "hierarchical" (default) node id is auto generated from the tree position "fixed" provide an explicit worker node id updating a node all fields must be specified opc update node by id( node id=folder id, parent id="edgedevice", name="renamedfolder", node type="folder", worker node id="edgedevice renamedfolder", worker node id mode="fixed", ) for tag nodes, also pass data type and topic name removing a node opc remove single node(node id) reset hierarchy opc reset manual hierarchy() # removes manually created nodes opc reset imported hierarchy() # removes auto imported nodes opc reset all hierarchy() # removes everything import from devicehub auto import all devicehub tags as opc nodes opc import all dh tags() import / export json import json \# export hierarchy = opc export as json() with open("opc hierarchy json", "w") as f json dump(hierarchy, f) \# import (replaces current hierarchy) with open("opc hierarchy json") as f opc import json(json load(f)) license copyright (c) litmus automation inc