Limit, what we send

This commit is contained in:
rasta5man 2025-01-01 13:12:02 +01:00
parent 41d1ec28dd
commit ef7817bf22
5 changed files with 122 additions and 74 deletions

View file

@ -11,6 +11,34 @@ class DataToTbHandler {
this.messageCounter = 0;
this.sender = "";
// if attribute difference is less than limit value, we do not send to tb.
this.attributeChangeLimit = {
temperature: 0.5,
Phase_1_voltage: 2,
Phase_2_voltage: 2,
Phase_3_voltage: 2,
Phase_1_current: 0.1,
Phase_2_current: 0.1,
Phase_3_current: 0.1,
Phase_1_power: 2,
Phase_2_power: 2,
Phase_3_power: 2,
total_power: 2,
Phase_1_pow_factor: 0.1,
Phase_2_pow_factor: 0.1,
Phase_3_pow_factor: 0.1,
power_factor: 0.1,
lifetime: 0.5,
voltage: 2,
power: 2,
frequency: 3,
energy: 0.1,
current: 2,
inclination_x: 10,
inclination_y: 10,
inclination_z: 10
};
}
dump() {
@ -101,16 +129,20 @@ class DataToTbHandler {
continue;
}
if(this.previousValues[tbname][key].value === value)
// attributeData ==> voltage: {ts:333333, value:5}
let attributeData = this.previousValues[tbname][key];
let attributeToChange = false;
if(key in this.attributeChangeLimit) attributeToChange = true;
let limit = this.attributeChangeLimit[key];
if(attributeData.value === value || attributeToChange && Math.abs(attributeData.value - value) < limit)
{
let diff = timestamp - this.previousValues[tbname][key].ts;
let diff = timestamp - attributeData.ts;
let timestampDiffToRemoveKey = this.getDiffTimestamp(key);
if(diff > timestampDiffToRemoveKey)
{
this.previousValues[tbname][key].ts = Date.now();
attributeData.ts = Date.now();
//if(this.debug) console.log(this.sender + ": update ts for key", key, "diff is", diff, "messageCounter", this.messageCounter);
}
else
{
@ -120,8 +152,8 @@ class DataToTbHandler {
}
else
{
this.previousValues[tbname][key].value = value;
this.previousValues[tbname][key].ts = timestamp;
attributeData.value = value;
attributeData.ts = timestamp;
}
}
@ -131,3 +163,4 @@ class DataToTbHandler {
}
module.exports = DataToTbHandler;