opcua-asyncio icon indicating copy to clipboard operation
opcua-asyncio copied to clipboard

StartTime and CurrentTime in ServerStatus node not update

Open impet14 opened this issue 8 months ago • 4 comments

Hi,

I found some thing in serverstatus node 2256 that StartTime and CurrentTime in the value of serverstatus node are not updating. But the StartTime Node 2257 and CurrentTime node 2258 work correctly updating.

image

Python-Version: 3.10 opcua-asyncio Version (e.g. master branch, 0.9): 1.0.4

please advice how to resolve.

impet14 avatar Oct 16 '23 10:10 impet14

Which server are you refering to?

SebastianKarnappPTW avatar Oct 18 '23 19:10 SebastianKarnappPTW

here is my personal simple server, I set. just to test sever. let say it from server example.

impet14 avatar Oct 19 '23 11:10 impet14

It seems to me that you need to fix the _set_current_time_loop function in the file internal_server.py.

My version of the fix is probably not a good way:

@@ -72,6 +72,7 @@
             self, self.aspace, self.subscription_service, "Internal", user=User(role=UserRole.Admin)
         )
         self.current_time_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
+        self.serv_status_cur_time = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus))
         self.time_task = None
         self._time_task_stop = False
         self.match_discovery_endpoint_url: bool = True
@@ -207,6 +208,13 @@
 
     async def _set_current_time_loop(self):
         while not self._time_task_stop:
+            try:
+                status = await self.serv_status_cur_time.get_value()
+                if status is not None:
+                    status.CurrentTime = datetime.utcnow()
+                    await self.serv_status_cur_time.write_value(status)
+            except Exception as e:
+                print(e)
             await self.current_time_node.write_value(datetime.utcnow())
             await asyncio.sleep(1)

you can also view the previous version of the library: https://github.com/FreeOpcUa/python-opcua/blob/fdf5f3c6c8655c90b0d36ce6a8db54749e8daeb4/opcua/server/internal_server.py#L198

KondratevAndrei avatar Oct 21 '23 06:10 KondratevAndrei

thanks so much . so what is the good way please?

impet14 avatar Oct 30 '23 10:10 impet14