Doubt with Computed Attributes - Protocol Suntech

Turbovix7 years ago

Hi Anton, I need help on the following question:
In the Suntech protocol the events are displayed by means of the attribute "io1", which results in a chain of 6 digits with value 0 or 1, and each digit represents an event (ignition on or off, input 1 on or off, output 1 On or off ...) I would like to use Computed Attributes to correctly display this information, but at the time of creating Computed Attributes, Attributes does not show the attribute "io1". How can I solve this?

Anton Tananaev7 years ago

I believe you can just type the key, if it's not available in the drop-down menu.

Turbovix7 years ago

Anton, I could not make it work!
I'm trying to create an event with the following expression: event ? (io1 & 2) != 0 : true since the attribute "io1" is given a string of 6 characters 0 or 1, I need to analyze the second character representing one of the 3 entries and if the character analyzed is 1 result Will be true.

Can you help me ?

Anton Tananaev7 years ago

In case of Suntech the IO value is of String type, so you need to convert it to Integer first. I'm not sure if this syntax is supported, but in Java it's done like this:

Integer.parseInt(io1)
abyss7 years ago

This works
new ("java.lang.Integer",0).parseInt(io1)
I believe it might be optimized.

abyss7 years ago

Or even more simple
new ("java.lang.Integer", io1)

socstur6 years ago

Hi Guys,
I have a similar issue of a gps103 protocol reporting fuel as io3 string with % sign; ex. io3=67%. Do you think I can convert this to a number to use in computed attributes? I'll like to assign it to the fuel attribute for fuel calculation. I tried the above examples but I think the % symbol is throwing it off in computed attributes.

Thanks

Anton Tananaev6 years ago

You can probably use something like this:

new ("java.lang.Integer", io1.substring(0, io1.length() - 1))
socstur6 years ago

Thanks for the quick response Anton. Using io1.length() - 1 inside io1.substring() does not seem to work; throws error below

org.traccar.processing.ComputedAttributesHandler.computeAttribute@86![6,69]: 'io3? (new ('java.lang.Integer', io3.substring(0, (io3.length() - 1)))) * (34.0687) / (100) : null;' constructor invocation error - JexlException (... < ComputedAttributesHandler:86 < AttributeResource:51 < ...)

Using a fixed value ex. 3 seems to work

io3 ? (new ("java.lang.Integer", io3.substring (0, 3)))*(34.0687)/(100) : null
socstur6 years ago

Anton, Using Float instead of Integer works with your suggestion.

For future reference and for anyone that needs to convert fuel value reported as string with % sign. The below computed attribute works for me.

o3? (new ("java.lang.Float", io3.substring (0,(io3.length()-1))))*(34.0687)/(100):null 
JSilva6 years ago

Hello, I canĀ“t change my fuel value as string with %

Teltonika protocol io87 = "Fuel level 1-102 (%)"
If i choose the the "Fuel" attribute shows in Liters

How can I change it, or create a new attribute?