I am trying to listen to an event called 'EventPretreatDone'.
Using the example to minitor an Event found in the node-opcua library i can't get any results.
async createSubscription() {
const session = await this.opcClient.createSession();
const subscription = ClientSubscription.create(session, {
requestedPublishingInterval: 1000,
requestedLifetimeCount: 100,
requestedMaxKeepAliveCount: 10,
maxNotificationsPerPublish: 100,
publishingEnabled: true,
priority: 10,
});
const filter = new EventFilter({
selectClauses: [
{ browsePath: [{ name: 'ActiveState' }, { name: 'id' }] },
{ browsePath: [{ name: 'ConditionName' }] },
],
});
subscription.monitor(
// itemToMonitor:
{
nodeId: 'ns=1;s=EventPretreatDone',
attributeId: AttributeIds.EventNotifier,
indexRange: null,
dataEncoding: { namespaceIndex: 0, name: null },
},
// requestedParameters:
{
samplingInterval: 3000,
filter: filter,
queueSize: 1000,
discardOldest: true,
},
TimestampsToReturn.Neither,
);
}
There is a Pyhton script provided in the machines (server) documentation that shows it is possible to listen to this specific event.
import asyncio
import logging
import json
from asyncua import Client, ua
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
logging.getLogger("asyncua").setLevel(logging.ERROR)
async def print_event(event):
data = json.loads(event.Message.Text)
logger.debug(event.EventType)
logger.debug(json.dumps(data, indent=4, sort_keys=True))
class EventListener:
def __init__(self, url):
self._URL = url
async def event_notification(self, event):
async def debug_print(event):
logger.debug(event)
fun = {
ua.StringNodeId('EventPretreatDone', 1): print_event,
}.get(event.EventType, debug_print)
await fun(event)
async def process_opcua(self):
while True:
try:
logger.info("Trying to connect...")
async with Client(url=self._URL) as client:
logger.info("Connected")
logger.info("Subscribing events")
sub = await client.create_subscription(10, self)
handle = await sub.subscribe_events(queuesize=10)
while True:
await asyncio.gather(
asyncio.sleep(1.0)
)
except Exception as ex:
logger.warning(ex)
await asyncio.sleep(0.5)
async def main():
listener = EventListener("opc.tcp://10.0.6.107:4840")
await asyncio.gather(
listener.process_opcua()
)
if __name__ == "__main__":
asyncio.run(main())
I would like to avoid a mix of python and javascript in my service.