1

Trouble getting the sensors info from units

Тема: Trouble getting the sensors info from units

Good afternoon.
Today i was doing some testing trying to get some sensor values from one of my units using the API search_items by property, I was reading and apparently using the next query it should give me the values of the sensors or at the very least show me the sensors on the unit, the query i used is the following:

-/ https://hst-api.wialon.com/wialon/ajax.html?svc=core/search_items&params={"spec":{"itemsType":"_unit","propName":"unit_sensors","propValueMask":"*XXUNITXX*","sortType":"unit_sensors"},"force":1,"flags":1439,"from":0,"to":0}&sid="sid" /-

The problem is that in the response it gives me an empty response, it returns nothing not even an error message either.
My question is what I’m I doing wrong, or what im malinterpretating here?

also i'll like to ask if there's a way using the API to know for when there's conectivity with the unit.

Thank you, any help is appreciated.

2

Trouble getting the sensors info from units

Re: Trouble getting the sensors info from units

jornadadgps22 пишет:

Good afternoon.
Today i was doing some testing trying to get some sensor values from one of my units using the API search_items by property, I was reading and apparently using the next query it should give me the values of the sensors or at the very least show me the sensors on the unit, the query i used is the following:

-/ https://hst-api.wialon.com/wialon/ajax.html?svc=core/search_items&params={"spec":{"itemsType":"_unit","propName":"unit_sensors","propValueMask":"*XXUNITXX*","sortType":"unit_sensors"},"force":1,"flags":1439,"from":0,"to":0}&sid="sid" /-

The problem is that in the response it gives me an empty response, it returns nothing not even an error message either.
My question is what I’m I doing wrong, or what im malinterpretating here?

also i'll like to ask if there's a way using the API to know for when there's conectivity with the unit.

Thank you, any help is appreciated.

Hello,
With the search_items request you can get sensors' properties and internal IDs.
If you want to arrange search by the prop item (e.g. unit_sensors), you need to add corresponding parameter in the request -- "propType":"propitemname"
propValueMask - should contains name or part of the name of sensor.
Here is the example: https://hst-api.wialon.com/wialon/ajax.html?svc=core/search_items&params={"spec":{"itemsType":"avl_unit","propName":"unit_sensors","propValueMask":"*New*","sortType":"sys_name","propType":"propitemname"},"force":1,"flags":4097,"from":0,"to":0}&sid=

Also, pay attention to the flags value, to get a sensors it should contains 4096.
This request respond with all units with the sensors that include "New" in their names.

In order to get sensors values from the last message, you can use 'unit/calc_last_message' request -- https://sdk.wialon.com/wiki/en/sidebar/ … st_message
You can set specific sensor ID in the array or leave it empty to get values of all sensors. 

Second option to get sensors values is 'unit/calc_sensors' request -- https://sdk.wialon.com/wiki/en/sidebar/ … lc_sensors
But this request work with the messages from loader, so you need to request messages first -- https://sdk.wialon.com/wiki/en/sidebar/ … s/messages


Regarding the connectivity - you can try to use search_items request by avl_unit with flags values 2097153 -- https://sdk.wialon.com/wiki/en/sidebar/ … connection

Anton Zinovyev
Technical Care Engineer (L2)
Wialon
3

Trouble getting the sensors info from units

Re: Trouble getting the sensors info from units

Good afternoon, thank you for your answer, i finally got the sensors but now my question is when getting the value using the sensors values from the last message it gives me this response: " -348201.3876 "
aparently has it says in the docs "If there is parameter in messages,but the sensor is validated by table/other sensors, then it will return the NA (-348201.3876) value in any case". i dont get it, what does it mean???

Thank you

4

Trouble getting the sensors info from units

Re: Trouble getting the sensors info from units

jornadadgps22 пишет:

Good afternoon, thank you for your answer, i finally got the sensors but now my question is when getting the value using the sensors values from the last message it gives me this response: " -348201.3876 "
aparently has it says in the docs "If there is parameter in messages,but the sensor is validated by table/other sensors, then it will return the NA (-348201.3876) value in any case". i dont get it, what does it mean???

Thank you

Good day,
Sometimes the sensor value could be invalid. In the monitoring website you can see it as the dashes (--) in the messages tab.
There could be different reason affecting such behavior. For example, the parameter used in the sensor could be missing in the messages, or the sensor configuration and calculation table specifically set to cut specific value and set them as invalid. 

As an alternative, you can try to use events to get sensors' value.
You need to add unit and sensors in the events with the 'events/update_units' request and then get the result using 'events/load' request.
Thus the sensor value will be last known valid value.
Here you can find video tutorial regarding events -- https://forum.wialon.com/viewtopic.php? … 53#p189953

Anton Zinovyev
Technical Care Engineer (L2)
Wialon
5

Trouble getting the sensors info from units

Re: Trouble getting the sensors info from units

Hi,

The API call mentioned return all sensors of unit which has a sensor name as propValueMask, if I want to return only the sensor as propValueMask, for example, I want to return the sensor has the name 'Movement' or has the type 'real-time motion sensor', how can I do that by API call?

6

Trouble getting the sensors info from units

Re: Trouble getting the sensors info from units

mshamsan , hello. If I understand you correctly - search_items request provide search by ItemsType (avl_unit, avl_resource, etc.). If you add filter by prop items (sensors, geofences, etc.) it returns all available items (according to the itemsType) that contains prop item with the name indicated in propValueMask. You can try to achieve your requirement on the side of your app. Execute search_items request, get all available units with the required sensor name and then parse JSON response to get required sensor information.

Anton Zinovyev
Technical Care Engineer (L2)
Wialon