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; }
$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; $daily->minAirHumidity = $humidityMin; $daily->avgAirHumidity = $humidityAverage; $daily->maxAirHumidity = $humidityMax; $daily->minSoilMoisture = $soilMoistureMin;