I have a lot (some hundreds) of dps with same name pattern: "*.ERR2".
I need to receive a notification when the _online.._stime of any of them gets older then a time value, given by getCurrentTime() + a number of seconds given by _original.._value of a dp whose name matches a pattern with the same prefix: "*.TIMESCAN".
Is there a efficient way to achieve this, for example with a single QueryConnect or a single work function?
At the moment, this is my solution:
- when the event that update ERR2:_online.._stime is triggered, a second string dp ERR2TS:_original.._value is updated with formatTime("%Y%m%d%H%M%S", ts) where ts = ERR2:_online.._stime + setPeriod(TIMESCAN:_original.._value)
- in the main loop of my script, there is a query polling:
ts = formatTime("%Y%m%d%H%M%S", getCurrentTime());
sprintf(query, "SELECT '_original.._value' FROM '*.ERR2TS' WHERE _LEAF AND _DPT = \\"MY_DPT\\" AND ('_original.._value' < \\"%s\\")", ts);
- the dps returned by the query allow to retrieve the "*.ERR2" ones that match the condition
I would like to know if there is a better solution that doesn't require additional dps or a cyclic polling od the database.
Thanks.
Query for old _stime
- leoknipp
- Posts:2928
- Joined: Tue Aug 24, 2010 7:28 pm
Re: Query for old _stime
Doing a dpQuery() all the time is possibly not the best solution.
Please try if the following solution fits your requirements:
-- Do a dpQueryConnectSingle() to the dp elements for the pattern *ERR2:_online.._stime
-- Write the current times to a global mapping where the key is the name of the dp element
-- In a while-loop (e.g. every 5 seconds) read the entries in the mapping and check the saved time compared to the current time
-- If the deviation is too high start the function for the notification
Best Regards
Leopold Knipp
Senior Support Specialist
Please try if the following solution fits your requirements:
-- Do a dpQueryConnectSingle() to the dp elements for the pattern *ERR2:_online.._stime
-- Write the current times to a global mapping where the key is the name of the dp element
-- In a while-loop (e.g. every 5 seconds) read the entries in the mapping and check the saved time compared to the current time
-- If the deviation is too high start the function for the notification
Best Regards
Leopold Knipp
Senior Support Specialist