Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $inputs = $request->all();
     $i = 0;
     for ($i = 1; $i <= 8; $i++) {
         if (isset($inputs['serial' . $i]) && isset($inputs['temperature' . $i])) {
             Temperature::create(['sensor_id' => $inputs['serial' . $i], 'value' => $inputs['temperature' . $i]]);
         }
     }
 }
Example #2
0
 public function index()
 {
     $controls = Control::all()->keyBy('name');
     // we will get temperatures here as well to pass them to home view
     $temps = collect(Temperature::getLatest())->keyBy('sensor_id');
     // get water level value(s) and pass to view
     $waterLevel = WaterLevel::getLatest()->first();
     $rainSensor = RainSensor::getLatest()->first();
     // pass it to the view
     return view('home', compact('controls', 'temps', 'waterLevel', 'rainSensor'));
 }
Example #3
0
 public function getCurrentEnvironmentValue($id)
 {
     $currentLight = Light::where("sensor_id", "=", $id)->orderBy('created_at', 'desc')->first();
     $currentSoilMoisture = SoilMoisture::where("sensor_id", "=", $id)->orderBy('created_at', 'desc')->first();
     $currentTemperature = Temperature::where("sensor_id", "=", $id)->orderBy('created_at', 'desc')->first();
     $currentAirHumidity = Humidity::where("sensor_id", "=", $id)->orderBy('created_at', 'desc')->first();
     $json = array();
     $json[0] = $currentLight;
     $json[1] = $currentTemperature;
     $json[2] = $currentAirHumidity;
     $json[3] = $currentSoilMoisture;
     return $json;
 }
Example #4
0
     if ($notificationCheck->minLux != 0 && $notificationCheck->minLux > $humid) {
         $notificationController->sentMonitorNotification("Alert!! : " . $id . " reach minimum light <" . $notificationCheck->minLux . " lux", $id);
     }
     if ($notificationCheck->maxLux != 0 && $notificationCheck->maxLux < $humid) {
         $notificationController->sentMonitorNotification("Alert!! : " . $id . " reach maximum light >" . $notificationCheck->maxLux . " lux", $id);
     }
 }
 if ($checkHourly == 6) {
     $lightMin = Light::where('sensor_id', '=', $SensorPrimaryKey)->min('luxValue');
     $lightAverage = Light::where('sensor_id', '=', $SensorPrimaryKey)->avg('luxValue');
     $lightMax = Light::where('sensor_id', '=', $SensorPrimaryKey)->max('luxValue');
     Light::where('sensor_id', 'like', $SensorPrimaryKey)->delete();
     $temperatureMin = Temperature::where('sensor_id', '=', $SensorPrimaryKey)->min('celsiusValue');
     $temperatureAverage = Temperature::where('sensor_id', '=', $SensorPrimaryKey)->avg('celsiusValue');
     $temperatureMax = Temperature::where('sensor_id', '=', $SensorPrimaryKey)->max('celsiusValue');
     Temperature::where('sensor_id', 'like', $SensorPrimaryKey)->delete();
     $humidityMin = Humidity::where('sensor_id', '=', $SensorPrimaryKey)->min('humidityPercentage');
     $humidityAverage = Humidity::where('sensor_id', '=', $SensorPrimaryKey)->avg('humidityPercentage');
     $humidityMax = Humidity::where('sensor_id', '=', $SensorPrimaryKey)->max('humidityPercentage');
     Humidity::where('sensor_id', 'like', $SensorPrimaryKey)->delete();
     $soilMoistureMin = SoilMoisture::where('sensor_id', '=', $SensorPrimaryKey)->min('soilValue');
     $soilMoistureAverage = SoilMoisture::where('sensor_id', '=', $SensorPrimaryKey)->avg('soilValue');
     $soilMoistureMax = SoilMoisture::where('sensor_id', '=', $SensorPrimaryKey)->max('soilValue');
     SoilMoisture::where('sensor_id', 'like', $SensorPrimaryKey)->delete();
     $daily = new Daily();
     $daily->minLight = $lightMin;
     $daily->avgLight = $lightAverage;
     $daily->maxLight = $lightMax;
     $daily->minTemperature = $temperatureMin;
     $daily->avgTemperature = $temperatureAverage;
     $daily->maxTemperature = $temperatureMax;
Example #5
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // this is one user
     Temperature::create(['sensor_id' => '28 f2 68 97 06 00 00 9b', 'value' => 0]);
 }