コード例 #1
0
 public function getMinMaxMonitor($id)
 {
     if (is_numeric($id)) {
         $minMaxMonitor = MinMaxMonitor::where("id", "=", $id)->first();
         return $minMaxMonitor;
     }
     $device = \App\SensingDevice::where("device_id", "=", $id)->first();
     $sensor = \App\Sensor::where("sensingDevice_id", "=", $device->id)->first();
     $minMaxMonitor = MinMaxMonitor::where("sensor_id", "=", $sensor->id)->first();
     return $minMaxMonitor;
 }
コード例 #2
0
 /**
  * @return Builder
  */
 public function sensors()
 {
     return Sensor::join('products', 'sensors.product_id', '=', 'products.id')->join('locations', 'locations.product_id', '=', 'products.id')->where('locations.user_id', $this->getKey());
 }
コード例 #3
0
 public function show($id)
 {
     $sensor = Sensor::where('sensingDevice_id', '=', $id)->first();
     return $sensor;
 }
コード例 #4
0
ファイル: routes.php プロジェクト: bossgame1234/MS4SF
                $weeklyHistory->maxSoilMoisture = $soilMoistureWeeklyMax;
                $Sensor->weeklyHistory()->save($weeklyHistory);
                Weekly::where('sensor_id', 'like', $SensorPrimaryKey)->delete();
            }
        }
    }
    $temperature = new Temperature();
    $soilMoisture = new SoilMoisture();
    $light = new Light();
    $humidity = new Humidity();
    $temperature->celsiusValue = $temp;
    $soilMoisture->soilValue = $soil;
    $light->luxValue = $lux;
    $humidity->humidityPercentage = $humid;
    $Sensor->temperature()->save($temperature);
    $Sensor->soilMoisture()->save($soilMoisture);
    $Sensor->light()->save($light);
    $Sensor->humidity()->save($humidity);
});
//add sensor to sensingDevice
Route::get('device/access/{id}', function ($id) {
    $DeviceBaseId = DB::table('sensingdevice')->where('device_id', $id)->value('id');
    $deviceA = new Sensor();
    $deviceA->sensingDevice_id = $DeviceBaseId;
    $deviceA->name = "basic package";
    $deviceA->save();
});
Route::get('test', function () {
    echo url();
});
//delete sensor
コード例 #5
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CreateSamplingsRequest $request)
 {
     $samplings_groupBy_gsIds = collect($request->samplings)->groupBy('generic_sensor_id');
     /**
      * for querying the sensors, we remove any object that didn't have a "generic_sensor_id" field
      *
      * Parameters:
      * "samplings": [
      *     {
      *         "generic_sensor_id": 2,
      *         "value": 49.72
      *     },
      *     {
      *         "generic_sensor_id": 3,
      *         "value": 104.693
      *     },
      *     {
      *         "generic_sensor_id": 4,
      *         "value": 22.1
      *     },
      *     {
      *         "generic": 1
      *     }
      * ]
      *
      *
      * After group:
      * {
      *     "2": [
      *         {
      *             "generic_sensor_id": 2,
      *             "value": 49.72
      *         }
      *     ],
      *     "3": [
      *         {
      *             "generic_sensor_id": 3,
      *             "value": 104.693
      *         }
      *     ],
      *     "4": [
      *         {
      *             "generic_sensor_id": 4,
      *             "value": 22.1
      *         }
      *     ],
      *     "": [
      *         {
      *             "generic": 1
      *         }
      *     ]
      * }
      */
     $samplings_groupBy_gsIds->forget("");
     $sensors = Sensor::join('generic_sensors', 'sensors.generic_sensor_id', '=', 'generic_sensors.id')->join('products', 'sensors.product_id', '=', 'products.id')->whereIn('generic_sensors.id', $samplings_groupBy_gsIds->keys())->where('products.id', $request->product_id)->get(['sensors.id', 'sensors.generic_sensor_id']);
     $sensor_for_gsId = array();
     foreach ($sensors as $sensor) {
         $sensor_for_gsId[$sensor->generic_sensor_id] = $sensor->getKey();
     }
     $newSamplings = array();
     $today = Carbon::now();
     foreach ($request->samplings as $sampling) {
         if (!array_has($sampling, 'generic_sensor_id') || !array_has($sampling, 'value')) {
             continue;
         }
         $created_at = $today;
         if (array_has($sampling, 'created_at') && strtotime($sampling['created_at'])) {
             $created_at = Carbon::createFromTimestamp(strtotime($sampling['created_at']));
         }
         array_push($newSamplings, array('sensor_id' => $sensor_for_gsId[$sampling['generic_sensor_id']], 'sampled' => $sampling['value'], 'created_at' => $created_at));
     }
     $successfully_inserted = DB::table('samplings')->insert($newSamplings);
     return $successfully_inserted ? 'Created ' . count($newSamplings) . ' sampling(s)' : 'Error during inserting';
 }
コード例 #6
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function deleteall()
 {
     Sensor::truncate();
     return [];
 }
コード例 #7
0
 /**
  * Display a listing of the sensors.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $sensors = Sensor::take(100)->get();
     return view('sensors.sensors', ['sensors' => $sensors, 'user' => Auth::user()]);
 }
コード例 #8
0
 /**
  * Display the specified scans by id_sensor
  * @param  App\Sensor $idSensor [id of the sensor]
  * @return Collection of App\Scan
  */
 public function showBySensor($idSensor)
 {
     $sensor = Sensor::findOrFail($idSensor);
     $scans = $sensor->scans;
     return view('scans.showBySensor', ['scans' => $scans, 'user' => Auth::user()]);
 }