1

How to get value of a sensor called "sensorName"

Тема: How to get value of a sensor called "sensorName"

How can I get value of a sensor called "sensorName" in unit ID 99999 at an specific time in the past?

I need to know the value of the sensor "sensorName" for the unit whose ID is 99999 at a given date / time.

I am reading this article: https://sdk.wialon.com/wiki/en/sidebar/ … lc_sensors but I do not realize how to complete the request.

Thanks!

2

How to get value of a sensor called "sensorName"

Re: How to get value of a sensor called "sensorName"

You need to call messages/load_interval or messages/load_last (in your case you need second one with your time and lastCount=1).

Then call unit/calc_sensors with empty source and unitId=0.

3

How to get value of a sensor called "sensorName"

Re: How to get value of a sensor called "sensorName"

I call "messages/load_last" like this:

https://hst-api.wialon.com/wialon/ajax.html?svc=messages/load_last&sid=0...3d8&params={
                  "itemId":1...0, 
                   "lastTime":1550671200,
                   "lastCount":1,
                   "flags":0,
                   "flagsMask":0,
                   "loadCount":99}

Then I get JSON data and call unit/calc_sensors with empty source and unitid=0

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

but I get     "error": 4

What am I doing wrong?

4

How to get value of a sensor called "sensorName"

Re: How to get value of a sensor called "sensorName"

error 4 for this request can be in the following cases:

  • Wrong params
  • No such layer if source is specified
  • No messages
  • Unit has no sensors

Params are looking valid, source is not specified, I think that messages are present.

Also, I discovered, that unitId must be specified even if source is empty, else you'll get error 7 (and this check is before check that unit has no sensors).

Are you executing unit/calc_sensors after messages/load_last is finished?

Here is working example, that successfully takes last sensor values.

5

How to get value of a sensor called "sensorName"

Re: How to get value of a sensor called "sensorName"

Thanks!
I first execute messages/load_last and then unit/calc_sensors.
Documentation (https://sdk.wialon.com/wiki/en/sidebar/ … lc_sensors) says that unitID is not used in this cases: "If source is NOT defined then write down any value in unitId (it is not used) – messages are put from message loader directly."
But IT IS necessary...
It is working now...

https://hst-api.wialon.com/wialon/ajax.html?svc=unit/calc_sensors&sid=[sessionID]&params={"source":"","indexFrom":0, "indexTo":999, "unitId":[unitID], "sensorId":3}