1

JS API: Get Unit's last ignition-off time

Тема: JS API: Get Unit's last ignition-off time

Hello Developers,

I really need your help to determine the last time a Unit's ignition was off.
I thought I could fetch its ignition history by running gthe line of code below an iterate through the results to get it


 var igH = u.getIgnitionHistory(1, 1527973200, 1530565200);

However, Am getting undefined for all the 400+ units I have.

I am looking forward to your feedback.

2

JS API: Get Unit's last ignition-off time

Re: JS API: Get Unit's last ignition-off time

pnanvuma пишет:

var igH = u.getIgnitionHistory(1, 1527973200, 1530565200);

This method is asynchronous, try this:

u.getIgnitionHistory(1, 1527973200, 1530565200, 0, null, function(error, result) {
    console.log(error, result);
});

(0 and null is sensorId and sensorsNameMask respectively)

3

JS API: Get Unit's last ignition-off time

Re: JS API: Get Unit's last ignition-off time

Thanks for the response.

Is there a better way you would suggest I get the last ignition time?

4

JS API: Get Unit's last ignition-off time

Re: JS API: Get Unit's last ignition-off time

pnanvuma пишет:

Is there a better way you would suggest I get the last ignition time?

I think, that it is a best and simplier way to do this.

There is also Message params. If your ignition is a single param and can have only two values, then there is ct field, that represents time of last value change.

And then if value is 1, ignition is on right now. If 0 — ct is a time, when it is switched from 1. But if ignition is inside bitmask, this method can't help you.

Other alternatives is to fetch messages/execute report, but getIgnitionHistory is preferred.

5

JS API: Get Unit's last ignition-off time

Re: JS API: Get Unit's last ignition-off time

I appreciate your response

6

JS API: Get Unit's last ignition-off time

Re: JS API: Get Unit's last ignition-off time

So I am now running the code below

u.getIgnitionHistory(1, t_from, t_to, 0, 'Ignition', function(error, result) {
                        console.log("ignition history");
                        console.log(error, result);
 });

And for some units I get an empty array as below

ignition:{}

And for others I get the result below but all have value 1. Does it mean that the vehicles ignition never goes off or am I pulling the wrong data?

ignition:{3: Array(20)}

{
f:0
from:{t: 1530163228, y: 0.295774489641, x: 30.1825046539}
hours:668713
m:1530163660
state:1
switches:255
to:{t: 1530163663, y: 0.295774489641, x: 30.1825046539}
type:1
value:1
}
7

JS API: Get Unit's last ignition-off time

Re: JS API: Get Unit's last ignition-off time

No, this method just returns only intervals on which ignition was enabled. There is no zero values.

Also, I found out, that for your case, you can use a bit different parameters:

ivalType
1 – from – to,
2 – ivalFrom messages from ivalTo,
3 – ivalFrom messages before ivalTo,
4 – from – to plus 1 event before ivalFrom and current event

So, if you need only last interval, you can try this:

u.getIgnitionHistory(3, 1, t_to, ...

This must return you single interval that was before t_to.

8

JS API: Get Unit's last ignition-off time

Re: JS API: Get Unit's last ignition-off time

Thank you for the response.

Let me try using your example.


I also see that u.getMessageParams() returns the results below. Can I also get the last ignition from the "in" params. Also when I compare the params returned, they dont tally with what is in the system for a particular Unit under the Messages tab.

battery_charge:{v: 0, ct: 1530640247, at: 1530712847}
in:{v: 0, ct: 1530640247, at: 1530712847}
in1:{v: 0, ct: 1530640247, at: 1530712847}
in2:{v: 0, ct: 1502871241, at: 1530712847}
.......