calc_sensors
To get sensor values, use the unit/calc_sensors method.
svc=unit/calc_sensors¶ms={"source":<text>,
"indexFrom":<uint>,
"indexTo":<uint>,
"unitId":<long>,
"sensorId":<long>,
"width":<uint>}
Parameters
| Parameter | Description |
|---|---|
source |
Source of messages (layer name). If this parameter is empty, the message loader is used by default. |
indexFrom |
Index of the first message. |
indexTo |
Index of the last message. |
unitId |
Unit ID. |
sensorId |
Sensor ID. If set to 0, the values of all sensors are returned. |
width |
Number of items to return. Optional. This parameter is used when you need a fixed number of aggregated (that is, preprocessed) sensor values. This is particularly useful for generating and zooming in on charts with preprocessed data. The process works as follows:
|
The
unitIdparameter is required even ifsourceis empty. The server uses it to check access rights to the unit and to get the unit sensors. Ifsourceis empty, messages are obtained from the message loader, so specify the ID of the unit whose messages are loaded.
Response
If the request with no specified width is completed successfully, a response of the following format is returned:
[ /* array of message data */
{ /* values of sensors from one message */
<text>:<double|text>, /* sensor ID: sensor value */
...
}
]
If a sensor value can’t be calculated for a message (for example, the message doesn’t contain the parameter used by the sensor), -348201.3876 is returned for this sensor.
If width is specified, a response of the following format is returned. Each sensor is returned in a separate array:
[
[
{
"name": <text>, /* Sensor ID */
"data": [
{
"left": [<unix_time1>, <value1>], /* First recorded sensor value in the subinterval and its time */
"right": [<unix_time2>, <value2>], /* Last recorded sensor value in the subinterval and its time */
"bottom": [<unix_time3>, <value3>], /* Minimum sensor value in the subinterval and its time */
"top": [<unix_time4>, <value4>] /* Maximum sensor value in the subinterval and its time */
},
...
]
}
],
...
]
If the request hasn’t been completed, an error code is returned.
Error codes
| Error code | Description |
|---|---|
| 4 | One of the following errors:
|
| 7 | The unit doesn’t exist, or the user doesn’t have the View object and its basic properties access right to it. |