What makes you think it's a string?
I have tried just putting io305 into the expression, I get this error when testing it
class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap') - ClassCastException (AttributeResource:67 < ...)
What does your expression look like? What's in the database for the position attributes?
So my expression is just 'io305'.
The current position attribute row looks like this.
{"obdSpeed":10.799140000000001,"rpm":1669,"throttle":16,"engineLoad":14,"io305":"5333","io422":"48211","io270":"5","battery":15.32,"acceleration":"-0.19;0;0.03","sat":7,"hdop":28,"deviceTemp":4.9,"distance":6.56,"totalDistance":45.38,"motion":true}
io values look to be stored as strings. I am using a freematics OBD module and after checking the traccar freematics protocol process code, all io fields look to be stored unprocessed as strings.
case 0x111:
position.set(Position.KEY_THROTTLE, Integer.parseInt(value));
break;
default:
position.set(Position.PREFIX_IO + key, value);
break;
Does Integer.parseInt(io305)
work?
That was the first I tried. When I click test, it returns nothing. It does not return an error though either.
Maybe new ("java.lang.Integer", io305)
?
No good either. Error below. I have processing.computedAttributes.localVariables set to true also.
@1:1 create instance error in '' - Feature (... < ComputedAttributesHandler:119 < AttributeResource:63 < ...)
You have to enable processing.computedAttributes.newInstanceCreation
.
Heh progressing, but still no good. Sorry for the delay in replying, the forum was blocking me for too many requests.
org.traccar.handler.ComputedAttributesHandler.computeAttribute:119@1:1 unsolvable function/method 'java.lang.Integer(String)' - Method (ComputedAttributesHandler:120 < AttributeResource:63 < ...)
The error doesn't really make sense to me. There should be a constructor that takes a string.
Thanks for the help Anton.
I ended up adding code to process the ODO PID (A6) directly when it is sent through the Freematics protocol.
Hey all,
I am having a hard time trying to convert an attribute from a string to an int so it can be the OBD Odometer. The value is currently stored in io305 which by default appears to be stored as a string.
I have looked all through the JEXL documentation but cannot find how I am supposed to use parseInt or something similar.
Thanks