-
Is there a way on the server side to notify a client when the property value status code has been changed, but the property value not? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
in general only if the client has subscribed it! |
Beta Was this translation helpful? Give feedback.
-
That is not working. Here is short example: import asyncio
import copy
import logging
from datetime import datetime
from asyncua import ua, Server
async def update_node_val(ua_node, value, status):
#The new instance of the ua.DataValue class creates on every call
data_val = ua.DataValue(ua.Variant(value, ua.VariantType.Int16),\
status=ua.StatusCode(status), sourceTimestamp=datetime.now(),serverTimestamp=datetime.now())
await ua_node.write_value(data_val)
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)
dev = await server.nodes.base_object_type.add_object_type(idx, "MyDevice")
await (await dev.add_property(idx, "device_id", 340, ua.VariantType.Int16)).set_modelling_rule(True)
mydevice = await server.nodes.objects.add_object(idx, "Device0001", dev)
dev_id = await mydevice.get_child(f"{idx}:device_id")
async with server:
i = 0
while True:
await asyncio.sleep(1)
if i % 10 < 5:
await update_node_val(dev_id, 100, ua.StatusCodes.Good)
else:
#Nothing will happen on the client side
await update_node_val(dev_id, 100, ua.StatusCodes.BadNotConnected)
# This will trigger a notification
# await update_node_val(dev_id, 101, ua.StatusCodes.BadNotConnected)
i += 1
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.run(main())
Yes, I do it in the same way. But I think it would be nice if I could know exactly what data the client needs and how often. So I would be able to poll only those devices for which data is needed. |
Beta Was this translation helpful? Give feedback.
-
I don't understand why the server should not notify the client when the UA Node changed it's status from good to bad and vice versa? And if the server shoud notify the client about the node status changing, than from what status to what? |
Beta Was this translation helpful? Give feedback.
-
https://reference.opcfoundation.org/v104/Core/docs/Part4/7.34.1/ https://reference.opcfoundation.org/v104/Core/docs/Part8/6.3.2/ |
Beta Was this translation helpful? Give feedback.
-
First of all thank you for answers. Next, summarizing all your answers we have: |
Beta Was this translation helpful? Give feedback.
First of all thank you for answers. Next, summarizing all your answers we have:
The server must not notify the client about changing a monitoring item status or timestamps (source timestamp or server timestamp), when it's value has not been changed. This is part of the OPC UA specification.