1

Get sensors values for all vehicles

Тема: Get sensors values for all vehicles

Hello
I use Wialon Local Remote API and I need to get sensors with its values for all vehicals.
I saw I can use messages/load_last and then unit/calc_sensors to get sensors values for a single unit. But I have to repeat it a hundreds times.

Is it good to do this in a batch command (core/batch) successively executing load_last -> calc_sensors for every unit or it has a simple solution?

Can someone give me advice?

2

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

Only in a batch. Try to do it not very often.

Head of Wialon Local Department
Gurtam
3

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

Hello

There are 3 ways how to get sensor value
- load_messages (or load_last) and then calc_sensor
- exec trace sensor report
- using SDK JS http://sdk.wialon.com/api/#wialon.item.MUnitSensor~calculateSensorValue!method_public

Also you can exec one batch request with several units (e.g all units you need???)

Can you tell more about your task?
Do you need only last sensor value or values for time range?
All units at once or units can be divided?
Do you need this info for every new message (like every second) or once an hour?
What programming language do you use?

4

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

Hello,

I am using node.js and I need sensors values for a given date and time. It will be executed few times a day.

I did it using batch command with load_last and calc_sensor, but at the beginning I received "url exceed the maximum length" (or something like that).
I work with approximately 100 vehicles and not sure if it is limitation in wialon or in node request module. Removed some quotes and it works now, but after couple of months the count of the vehicles will be increased.

5

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

lbtomov
Please ensure you're sending POST request.
Here's how i do it in Node.js

var request = require('request');

/** Perform Remote API request
 */
var remoteApi = function(svc, sid, params, cb) {
  params = params || {};

  var form = {
    svc: svc,
    params: JSON.stringify(params)
  };

  if (sid) {
    form.sid = sid;
  }

  request.post({
    url: config.url + '/wialon/ajax.html',
    json: true,
    form: form
  }, cb);
};

remoteApi('token/login', '', {token: 'TOKEN'}, function(error, response, body) {
  console.log(body);
});
6

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

shmi you are absolutely right.
It was GET request . I changed it to POST and now it works like a charm.

Thank you.

7

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

Hi

https://hst-api.wialon.com/wialon/ajax.html?svc=unit/sid=calc_sensors&params={"source":"","indexFrom": 0, "indexTo":1, "unitId":20783118 , "sensorId": 0}&sid=09b6c89eda2497c8f9b942c35f25b3fc

Error :

{
    "error": 2
}


Please help me.

Thanks you

8

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

csanchezb пишет:

Hi

https://hst-api.wialon.com/wialon/ajax.html?svc=unit/sid=calc_sensors&params={"source":"","indexFrom": 0, "indexTo":1, "unitId":20783118 , "sensorId": 0}&sid=09b6c89eda2497c8f9b942c35f25b3fc

Error :

{
    "error": 2
}


Please help me.

Thanks you

Hello!

error 2 means Invalid service name (svc). In your case svc=unit/sid=calc_sensors  sid is mistake, the correct is svc=unit/calc_sensors

Diana Cheley
Wialon Hosting Expert
Gurtam
9

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

Hi

Thanks you!

but error again....


https://hst-api.wialon.com/wialon/ajax.html?svc=unit/calc_sensors&params={"source":" ","indexFrom":0,"indexTo":1,"unitId":20783118,"sensorId":0}&sid=096c82259f8d537e0db47d589c492044

{
    "error": 4
}

Please help me.

Thanks you

10

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

Hi!

Before get sensor's values it needs to load required raw messages to message loader :

Execute request svc=messages/load_interval to load messages from interval  or svc=messages/load_last to load last messages.
After you can execute request svc=unit/calc_sensonrs with empty source paramter "source":"" (please note - without any space in value) as messages are put from message loader directly.

For example,

https://hst-api.wialon.com/wialon/ajax.html?svc=messages/load_interval&params={"itemId":135,"timeFrom":1583010000,"timeTo":1584392399,"flags":1,"flagsMask":65281,"loadCount":3}&sid=029b7fbf397b30239da8a43332fbc49d

response - fisrt 3 messages

{"count":6915,"messages":[{"t":1583232345,"f":1073741825,"tp":"ud","pos":{"y":53.9057559,"x":27.456982,"c":295,"z":315,"s":8,"sc":8},"lc":0,"rt":1583232413,"p":{"pass":"15","pass_index":0,"a":25.5520000458}},{"t":1583232345,"f":1073741825,"tp":"ud","pos":{"y":53.9057478,"x":27.4570056,"c":290,"z":315.5,"s":6,"sc":8},"lc":0,"rt":1583232413,"p":{"pass":"15","pass_index":0,"a":25.3220005035}},{"t":1583232348,"f":1073741825,"tp":"ud","pos":{"y":53.9057735,"x":27.4569488,"c":278,"z":315,"s":0,"sc":8},"lc":0,"rt":1583232413,"p":{"pass":"15","pass_index":0,"a":25.954000473}}]}

get sensors from 2 first messages

https://hst-api.wialon.com/wialon/ajax.html?svc=unit/calc_sensors&params={"source":"","indexFrom":0,"indexTo":1,"unitId":135,"sensorId":0}&sid=029b7fbf397b30239da8a43332fbc49d

responce

[{"1":8,"2":0,"3":0,"4":-348201.3876,"5":25.5520000458,"6":0,"7":0,"8":0,"9":0,"10":1583232345,"11":295,"12":315,"13":-348201.3876,"14":-348201.3876,"15":0,"16":-348201.3876,"17":-348201.3876,"18":1583232413,"19":-348201.3876,"20":-348201.3876,"21":25.5520000458,"22":25.5520000458},{"1":6,"2":0,"3":0,"4":-348201.3876,"5":25.3220005035,"6":0,"7":0,"8":0,"9":0,"10":1583232345,"11":290,"12":315.5,"13":-348201.3876,"14":-348201.3876,"15":0,"16":-348201.3876,"17":-348201.3876,"18":1583232413,"19":-348201.3876,"20":-348201.3876,"21":25.3220005035,"22":25.3220005035}]
Diana Cheley
Wialon Hosting Expert
Gurtam
11

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

Hi, I want to get history of unit locations with sensor values (eg. Ignition On/Off)
Just like in the image.

What API should I use?

  • Get sensors values for all vehicles
12

Get sensors values for all vehicles

Re: Get sensors values for all vehicles

kruyvanna пишет:

Hi, I want to get history of unit locations with sensor values (eg. Ignition On/Off)
Just like in the image.

What API should I use?


Hello!

The response above https://forum.gurtam.com/viewtopic.php? … 83#p177683

Diana Cheley
Wialon Hosting Expert
Gurtam