You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I needed some assistance with a personal project where I am developing an OPC server, that would dynamically add tags on client subscription. Below is my current implementation, but I see that the connection with the client is not persistent (UAExpert). I often see errors like.
Error 'BadTimeout' was returned during OpenSecureChannel
Error 'BadSessionIdInvalid' was returned during ActivateSession
Later a new session starts.
import logging
import asyncio
try:
from IPython import embed
except ImportError:
import code
def embed():
vars = globals()
vars.update(locals())
shell = code.InteractiveConsole(vars)
shell.interact()
from asyncua import Server,ua
from asyncua.common.callback import CallbackType
l = []
myobj = None
async def create_monitored_items(event, dispatcher):
global myobj
for idx in range(len(event.response_params)):
nodeId = event.request_params.ItemsToCreate[idx].ItemToMonitor.NodeId
if nodeId.Identifier not in l and myobj is not None:
l.append(nodeId.Identifier)
try:
var_nodeid = ua.NodeId(str(nodeId.Identifier), idx)
myvar = await myobj.add_variable(nodeid=var_nodeid,bname=str(nodeId.Identifier),val=0)
await myvar.set_writable()
except:
print('Error :', nodeId.Identifier)
async def main():
server = Server()
await server.init()
server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
server.set_server_name("FreeOpcUa Example Server")
uri = "http://examples.freeopcua.github.io"
idx = await server.register_namespace(uri)
objects = server.nodes.objects
await server.start()
global myobj
myobj = await objects.add_object(idx, "Test1")
# Create Callback for item event
server.subscribe_server_callback(CallbackType.ItemSubscriptionCreated, create_monitored_items)
while True:
await asyncio.sleep(1)
if __name__ == "__main__":
asyncio.run(main())
The objective is for the client to be able to subscribe to around 30,000 nodes and ensure a resilient connection.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I needed some assistance with a personal project where I am developing an OPC server, that would dynamically add tags on client subscription. Below is my current implementation, but I see that the connection with the client is not persistent (UAExpert). I often see errors like.
Error 'BadTimeout' was returned during OpenSecureChannel
Error 'BadSessionIdInvalid' was returned during ActivateSession
Later a new session starts.
The objective is for the client to be able to subscribe to around 30,000 nodes and ensure a resilient connection.
Beta Was this translation helpful? Give feedback.
All reactions