Kaynağa Gözat

sensor get random values

tags/0.1.0
Robin Thoni 9 yıl önce
ebeveyn
işleme
355a3186bc

+ 6
- 0
app/Http/Business/SensorsBusiness.php Dosyayı Görüntüle

@@ -48,4 +48,10 @@ class SensorsBusiness extends LuBusiness {
48 48
         $sensor->setId($sensor_id);
49 49
         return SensorsDataAccess::editById($sensor_id, $sensor);
50 50
     }
51
+
52
+    public static function getValue($sensor_id)
53
+    {
54
+        self::getById($sensor_id);
55
+        return rand(0, 42) * ($sensor_id % 2 == 0 ? 1 : -1);
56
+    }
51 57
 }

+ 10
- 0
app/Http/Controller/SensorsController.php Dosyayı Görüntüle

@@ -78,4 +78,14 @@ class SensorsController extends LuController {
78 78
     {
79 79
         return SensorsBusiness::deleteById($sensor_id);
80 80
     }
81
+
82
+    /**
83
+     * Get the sensor value
84
+     * @param $sensor_id int The sensor id
85
+     * @return float
86
+     */
87
+    public function getValue($sensor_id)
88
+    {
89
+        return SensorsBusiness::getValue($sensor_id);
90
+    }
81 91
 }

+ 1
- 0
app/Http/routes.php Dosyayı Görüntüle

@@ -38,6 +38,7 @@ $route->get("/sensors/$sensor_id", "Sensors", "get", CamotionPermissions::SENSOR
38 38
 $route->post("/sensors/add", "Sensors", "add", array(CamotionPermissions::SENSOR_GET, CamotionPermissions::SENSOR_ADD));
39 39
 $route->post("/sensors/$sensor_id/edit", "Sensors", "edit", array(CamotionPermissions::SENSOR_GET, CamotionPermissions::SENSOR_EDIT));
40 40
 $route->post("/sensors/$sensor_id/del", "Sensors", "del", array(CamotionPermissions::SENSOR_GET, CamotionPermissions::SENSOR_DEL));
41
+$route->post("/sensors/$sensor_id/value", "Sensors", "getValue", array(CamotionPermissions::SENSOR_GET, CamotionPermissions::SENSOR_EXEC));
41 42
 
42 43
 
43 44
 $route->get("/commands/types", "Commands", "getAllTypes", array(CamotionPermissions::COMMAND_GET, CamotionPermissions::COMMAND_ADD));

Loading…
İptal
Kaydet