Implementing Door Sensors using Teltonika Eye Beacons

Hussain Bulawa 3 years ago

Hello All,

We have teltonika eye sensors and they report in hex. To detect door open/close, we need to convert the hex value to binary and check the value of bit 3 (LSB). Door is closed if the bit is set and open otherwise.

In GPSGate, we use something like flag = parseInt(io331, 16).toString(2).substr(4,1) ) to get the value of bit 3.

We have tried io331 ? ( parseInt(io331, 16).toString(2).substr(4,1) ) == 0 ? "doorOpen" : "doorClosed" : null in traccar computed attributes but it does not work.

Any assistance will be appreciated.

Anton Tananaev 3 years ago

Does something like this work?

(io331 & 8) > 0
Hussain Bulawa 3 years ago

Thank you Anton,

Will check this and revert.

My appreciations

Hussain Bulawa 3 years ago

Hi Anton,

See error below I am having:

For input string: "bf" - NumberFormatException (... < ComputedAttributesHandler:102 < AttributeResource:57 < ...)

I am using io331 ? (io331 & 8) > 0 ? "doorOpen" : "doorClosed" : null

Anton Tananaev 3 years ago

What is "bf"?

Hussain Bulawa 3 years ago

Its the value of io331 from the eye sensor in hex.

When converted to binary is 10111111 and the bit 3 (lsb) is 1 which is what I need to determine open or close.

Anton Tananaev 3 years ago

I see. In that case you need something like

(parseInt(io331, 16) & 8) > 0

assuming parseInt works.

Hussain Bulawa 3 years ago

Yes, this seems to work

io331 ? (new("java.lang.Integer", 0).parseInt(io331, 16) & 8)  > 0? "doorClosed" : "doorOpen" : null

I will monitor it for a while.

Many thanks Anton.

Doggy Chan 3 years ago

Hello, Someone Helps me to solve.I import formula substr(x,2,1) for door sensor and i setup for 0 and 1 for closed and opened.After all setup ,sever show me that while sensor is 0 is NaN.Why they show thant Nan instead of close.Someone help me with this.Best Regards.

Anton Tananaev 3 years ago

I don't think substr returns a number.

Doggy Chan 3 years ago

what formula should i use.Can you tell me.Sir.
Regards,

Doggy Chan 3 years ago

Actually my formula is work but in user interface they show that NaN instead of close .If you have time,help me to solve it.
Best Regards,