I have a requirement where I have to calculate the time difference between two instances of the PumpRunSignal property (Boolean), we need to determine the duration in minutes. The Pump Run Signal is a Boolean property that triggers an event data subscription and a service call when there is a change from true to false in the input from the PLC. We calculate the time difference by comparing the timestamps of index values 1 and 0 of the PumpRunSignal. However, there is a delay in loading data from Thingworx to InfluxDB when there is a false signal. To address this delay, we have implemented a 30-second Pause every time there is a false signal. While this pause logic seems effective, there is some uncertainty about its reliability, especially when dealing with multiple calculations for each Thing within Thingworx.
Thank you!
Solved! Go to Solution.
Hi @MM_9023322
I can see there is a one-minute time difference between the actual and logged values. This could be due to Math.floor method.
Instead of Math.floor use Math.round method.
For your reference:
If you want a more accurate time. You need to get the decimal value from the minute and multiply it with 60 which will give you exact seconds. And you can add seconds to your minutes.
/VR
Hi @MM_9023322
You can use subscription input EventData - NewValue Time and OldValue Time to get the time difference
Sample Code in Subscription
if (!eventData.newValue.value) // If new value is false
{
// Calculate time
me.timeDifference = dateDifference(eventData.newValue.time, eventData.oldValue.time); // Returns milliseconds
}
/VR
Hi @Velkumar,
Whenever the signal triggers from true to false, the time difference is calculated. But the false trigger time and the time stored in the Database are not the same, so there is some conflict in the time difference calculations.
Below is the code:
The time difference is calculated using the above code in Thingworx and manually for the PumpRunSignal property. The highlighted in Red are mismatching.
Hi @MM_9023322
I can see there is a one-minute time difference between the actual and logged values. This could be due to Math.floor method.
Instead of Math.floor use Math.round method.
For your reference:
If you want a more accurate time. You need to get the decimal value from the minute and multiply it with 60 which will give you exact seconds. And you can add seconds to your minutes.
/VR