26.03.2021, 06:25
As Daniel said you need to enable logging for this object and use data from the objects logs. Make sure that the object log size (Utilities > General configuration) is large enough to store data for the last 4 days.
Since you want to check for temperature variation you probably need to find the difference between the minimum and maximum temperature in the given period instead of using average. Here's how you can find min/max:
Since you want to check for temperature variation you probably need to find the difference between the minimum and maximum temperature in the given period instead of using average. Here's how you can find min/max:
Code:
logaddress = '32/1/7'
obj = grp.find(logaddress)
time = os.time() - 86400 * 4 -- last 4 days
logs = db:getall('SELECT * FROM objectlog WHERE address=? AND logtime>?', obj.id, time)
for _, item in ipairs(logs) do
value = busdatatype.decode(item.datahex, obj.datatype)
min = min and math.min(min, value) or value
max = max and math.max(max, value) or value
end
log(min, max)