Capatitative fuel Sensor

IñakiTanken5 years ago

Hi,
We are currently using Eskort 3TD-online which is a fuel sensor for a couple of trucks.
Traccar is reading the fuel value but it is the RAW value (Lls1) which has to be converted int liters.

We have done as follows to compute an attribute in order to convert the values the sensor are sending:

if (lls1 < 1) {
  return 0;
}
if ((lls1 >= 1) && (lls1 < 127)) {
  return (0.078740157480315 * lls1) + 0;
}
if ((lls1 >= 127) && (lls1 < 249)) {
  return (0.0819672131147541 * lls1) + -0.409836065573769;
}
if ((lls1 >= 249) && (lls1 < 350)) {
  return (0.099009900990099 * lls1) + -4.65346534653466;
}
if ((lls1 >= 350) && (lls1 < 445)) {
  return (0.105263157894737 * lls1) + -6.84210526315789;
}
if ((lls1 >= 454) && (lls1 < 524)) {
   return (0.126582278481013 * lls1) + -16.3291139240506;
}
if ((lls1 >= 524) && (lls1 < 617)) {
   return (0.10752688172043 * lls1) + -6.34408602150538;
}
if ((lls1 >= 617) && (lls1 < 682)) {
   return (0.153846153846154 * lls1) + -34.9230769230769;  
}
if ((lls1 >= 682) && (lls1 < 760)) {
   return (0.128205128205128 * lls1) + -17.4358974358974;
}
if ((lls1 >= 760) && (lls1 < 839)) {
   return (0.126582278481013 * lls1) + -16.2025316455696;
}
if ((lls1 >= 839) && (lls1 < 910)) {
   return (0.140845070422535 * lls1) + -28.16901408;
}
if ((lls1 >= 910) && (lls1 < 973)) {
   return (0.158730159 * lls1) + -44.44444444;
}
if ((lls1 >= 973) && (lls1 < 1039)) {
   return (0.151515152 * lls1) + -37.42424242;
}
if ((lls1 >= 1039) && (lls1 < 1108)) {
   return (0.144927536 * lls1) + -30.57971014;
}
if ((lls1 >= 1108) && (lls1 < 1173)) {
   return (0.153846154 * lls1) + -40.46153846;
}
if ((lls1 >= 1173) && (lls1 < 1236)) {
   return (0.158730159 * lls1) + -46.19047619;
}
if ((lls1 >= 1236) && (lls1 < 1305)) {
   return (0.144927536 * lls1) + -29.13043478;
}
if ((lls1 >= 1305) && (lls1 < 1358)) {
   return (0.188679245 * lls1) + -86.22641509;
}
if ((lls1 >= 1358) && (lls1 < 1411)) {
   return (0.188679245 * lls1) + -86.22641509;
}
if ((lls1 >= 1411) && (lls1 < 1475)) {
   return (0.15625 * lls1) + -40.46875;
}
if ((lls1 >= 1475) && (lls1 < 1534)) {
   return (0.169491525 * lls1) + -60;
}
if ((lls1 >= 1534) && (lls1 < 1596)) {
   return (0.161290323 * lls1) + -47.41935484;
}
if ((lls1 >= 1596) && (lls1 < 1665)) {
   return (0.144927536 * lls1) + -21.30434783;
}
if ((lls1 >= 1665) && (lls1 < 1712)) {
   return (0.212765957 * lls1) + -134.2553191;
}
if ((lls1 >= 1712) && (lls1 < 1787)) {
   return (0.133333333 * lls1) + 1.733333333;  
}
if ((lls1 >= 1787) && (lls1 < 1840)) {
   return (0.188679245 * lls1) + -97.16981132;  
}
if ((lls1 >= 1840) && (lls1 < 1881)) {
   return (0.243902439 * lls1) + -198.7804878;
}
if ((lls1 >= 1881) && (lls1 < 1942)) {
   return (0.163934426 * lls1) + -48.36065574;
}
if ((lls1 >= 1942) && (lls1 < 2010)) {
   return (0.147058824 * lls1) + -15.58823529;
}
if ((lls1 >= 2010) && (lls1 <= 4095)) {
  return 580.00;
}

Can anyone help me know why is this wrong?
I am not familiar with the JEXL syntax, nevertheless of what I have been reading the code "Seems" right.

Why this doesn't
Should we divide each range in a different computed attribute?
Should it be just one line of formula?
In that case, the sensor is capacitative and it read different ranges of values which need to be converted into the liters, and doing the y=mx+b would loose precision in the fuel level.

Cheers!

Anton Tananaev5 years ago

It has to be a single expression. What you have is multiple expressions.

Please read documentation here:

https://commons.apache.org/proper/commons-jexl/reference/syntax.html

Anton Tananaev5 years ago

It should look something like this:

lls1 < 1 ? 0 : (lls1 >= 1) && (lls1 < 127) ? (0.078740157480315 * lls1) + 0 : ...