From d80761fac03d9c6a315979155313cda2dc939a19 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Wed, 22 Dec 2021 22:20:47 +0300 Subject: [PATCH] =?UTF-8?q?[*]=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BE=D0=BD=D0=BB?= =?UTF-8?q?=D0=B0=D0=B9=D0=BD=20=D0=BC=D0=BE=D0=BD=D0=B8=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3=D0=B0=20=D1=82=D0=B5=D0=BB=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ajax/getSensorsData.php | 32 ++++++++++++++++++++++++++++++++ inc/lib/CIoT.class.php | 38 +++++++++++++++++++++++++++++++++++++- index.php | 39 ++++++++++++++++++++------------------- 3 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 ajax/getSensorsData.php diff --git a/ajax/getSensorsData.php b/ajax/getSensorsData.php new file mode 100644 index 0000000..eddab66 --- /dev/null +++ b/ajax/getSensorsData.php @@ -0,0 +1,32 @@ +query('SELECT * FROM sensors WHERE device="'.$deviceId.'" and sensor="ds'.($i).'" ORDER BY id DESC LIMIT 1'); + if($res) { + $result['ds'.$i]['sensor'] = $res[0]['sensor']; + $result['ds'.$i]['value'] = $res[0]['value']; + } + } + + $res = self::$DB->query('SELECT * FROM sensors WHERE device="'.$deviceId.'" and sensor="dht_t" ORDER BY id DESC LIMIT 1'); + if($res) { + $result['dht_t']['sensor'] = $res[0]['sensor']; + $result['dht_t']['value'] = $res[0]['value']; + } + + $res = self::$DB->query('SELECT * FROM sensors WHERE device="'.$deviceId.'" and sensor="dht_h" ORDER BY id DESC LIMIT 1'); + if($res) { + $result['dht_h']['sensor'] = $res[0]['sensor']; + $result['dht_h']['value'] = $res[0]['value']; + } + + $res = self::$DB->query('SELECT * FROM sensors WHERE device="'.$deviceId.'" and sensor="analog" ORDER BY id DESC LIMIT 1'); + if($res) { + $result['analog']['sensor'] = $res[0]['sensor']; + $result['analog']['value'] = $res[0]['value']; + } + + return $result; + } + /** * Преобразование версии прошивки в человеческий вид * @@ -271,7 +307,7 @@ class CIoT { if (stristr($sensor, 'dht_h')) { $result = ['name' => 'Датчик влажности', 'unit' => '%', 'icon' => 'fa fa-flask']; } elseif (stristr($sensor, 'dht_t')) { - $result = ['name' => 'Датчик температуры', 'unit' => '%', 'icon' => 'ion-thermometer']; + $result = ['name' => 'Датчик температуры', 'unit' => 'C', 'icon' => 'ion-thermometer']; } elseif (stristr($sensor, 'ds')) { $result = ['name' => 'Датчик температуры', 'unit' => 'C', 'icon' => 'ion-thermometer']; } elseif (stristr($sensor, 'analog')) { diff --git a/index.php b/index.php index f79dc00..4c1cc69 100644 --- a/index.php +++ b/index.php @@ -51,26 +51,27 @@ if(CCache::check($cacheId)) { - + +