diff --git a/inc/lib/CAPI.class.php b/inc/lib/CAPI.class.php index 9099af4..37def3b 100644 --- a/inc/lib/CAPI.class.php +++ b/inc/lib/CAPI.class.php @@ -16,6 +16,22 @@ class CAPI { foreach($result['devices'] as $key => $value) { $result['devices'][$key]['config'] = CIoT::getBoardConfig($value['id']); } + $result['status'] = 'ok'; return $result; } + + public static function getSensorValue() { + global $USER; + $sensor = $_REQUEST['sensor']; + $deviceId = $_REQUEST['deviceId']; + + $arUserDevices = getUserDevices($USER['id']); + if (!in_array($deviceId, $arUserDevices)) { + return ['status' => 'fail', 'message' => 'Выбранное устройство не принадлежит текущему пользователю']; + } + + $sensorValue = CIoT::getSensorData($deviceId, $sensor); + return ['status' => 'ok', 'deviceId' => $deviceId, 'sensor' => $sensor, 'value' => $sensorValue]; + + } } \ No newline at end of file