diff --git a/asyncua/common/node.py b/asyncua/common/node.py index b8c647620..4123f61f7 100644 --- a/asyncua/common/node.py +++ b/asyncua/common/node.py @@ -553,6 +553,46 @@ async def read_raw_history(self, starttime=None, endtime=None, numvalues=0, retu break return history + + async def read_processed_history(self, aggregate_type, aggregation_configuration, starttime=None, endtime=None, processing_interval=60000): + """ + Read processed history of a node + result code from server is checked and an exception is raised in case of error + exemples of values for the arguments : + aggregate_type = [2000] //with 2000 is the 'average' nodeId in the opc ua server. + aggregation_configuration = 948 + """ + + details = ua.ReadProcessedDetails() + details.AggregateConfiguration = ua.AggregateConfiguration(aggregation_configuration) + details.ProcessingInterval = processing_interval + d0 = [] + for i in aggregate_type : + d0.append(ua.NodeId(i)) + details.AggregateType =d0 + + if starttime: + details.StartTime = starttime + else: + details.StartTime = ua.get_win_epoch() + if endtime: + details.EndTime = endtime + else: + details.EndTime = ua.get_win_epoch() + + history = [] + continuation_point = None + while True: + result = await self.history_read(details, continuation_point) + result.StatusCode.check() + continuation_point = result.ContinuationPoint + history.extend(result.HistoryData.DataValues) + # No more data available + if continuation_point is None: + break + + return history + async def history_read(self, details, continuation_point=None): """