1

Problems to get the sensor value in Node.js

Тема: Problems to get the sensor value in Node.js

Hi, I'm having trouble getting the sensor value "can_engine_hrs".

Executed the function "core/search_items", to obtain the id, of the sensor in the vehicle.

function searchSensors () {
    var params = {
        "spec":{
                "itemsType": "avl_unit",
                "propName":"sys_id",    
                "propValueMask":"18940679", // ID VEHICLE
                "sortType":"sys_id"
        },
        "force":1,            
        "flags":0x1000,
        "from":0,            
        "to":0
        };
    request.post({
        url: URL + 'svc=core/search_items',
        json: true,
        form: {
            sid: SID,
            params: JSON.stringify(params)
    }
    }, function (error, response, body) {
        async.forEach(body.items, function(result) {
            console.log(result.sens[3]);
        })
    });
}

RESULT: "

 { id: 3,
  n: 'Engine Hours',
  t: 'relative engine hours',
  d: '',
  m: 'hours',
  p: 'can_engine_hrs',
  f: 0,
  c:
   '{"act":1,"appear_in_popup":true,"ci":{},"cm":1,"consumption":0,"mu":0,"pos":
9,"show_time":false,"timeout":0,"uct":0}',
  vt: 1,
  vs: 0,
  tbl: [ { x: 1, a: 0.05, b: 0 } ] } 

Executed the function "messages / load_last", to obtain the latest messages. (When I was finding out how to get the value of the sensor, they indicated that the last messages had to be loaded, I do not understand the reason)

 function msj() {
    var params = {
        "itemId":"18940679", // ID Vehicle
        "lastTime":0,            
        "lastCount":1,
        "flags":0,            
        "flagsMask":0,
        "loadCount":1
    };
    request.post({
        url: URL + 'svc=messages/load_last',
        json: true,
        form: {
            sid: SID,
            params: JSON.stringify(params)
        }
    }, function (error, response, body) {
        console.log(body);
        hr();
    });
} 

RESULT:

 { count: 1,
  messages:
   [ { t: 1555344100,
       f: 1073741827,
       tp: 'ud',
       pos: [Object],
       i: 35025,
       lc: 546811456,
       rt: 1555344109,
       p: [Object] } ] } 

Executed the function "unit / calc_sensors'', to get the value of the sensor, but I get an error.

 function hr() {
    var params = {
        "souce":"",
        "indexFrom":0,            
        "indexTo":1,
        "unitId":"18940679",            
        "sensorId":3
    };
    request.post({
        url: URL + 'svc=unit/calc_sensors',
        json: true,
        form: {
            sid: SID,
            params: JSON.stringify(params)
        }
    }, function (error, response, body) {
        console.log(body);   
    });
}
 

RESULT:

 { error: 4,
  reason:
   'VALIDATE_PARAMS_ERROR: {source: text, indexFrom: uint, indexTo: uint, unitId
: long, sensorId: long}' } 

Reading in the forum, I saw that they gave a page of ejmplo. OK, I change the values that I use, but it gives me a value that does not match my sensor values.

PAGE: https://sdk.wialon.com/playground/nd2rz2kG/2
RESULT:

 sensor values: [
 {
  "3": -348201.3876
 }
] 

On the platform of wialon gives me the following value: can_engine_hrs: 2430

What am I failing ?

  • Problems to get the sensor value in Node.js
2

Problems to get the sensor value in Node.js

Re: Problems to get the sensor value in Node.js

Hello!

1. Error 4 -  it's not correct name for parameter source. Please check, you type '"souce":"" . Just slip of the pen.
2. Example of code https://sdk.wialon.com/playground/nd2rz2kG/2 - you specify unit ID (test unit) which doesn't have parameter  can_engine_hrs and it's sensor with id = 3 doesn't have value (unknown value is the same as -348201.3876)
You need to work with your unit, specify it's id

Diana Cheley
Wialon Hosting Expert
Gurtam