public function removePlotFromDevice($id)
 {
     $device = SensingDevice::find($id);
     $device->plot_id = 0;
     $device->save();
     return $device;
 }
예제 #2
0
 public function sentMonitorNotification($message, $device_id)
 {
     $deviceWithUser = \App\SensingDevice::where("device_id", "=", $device_id)->with("sensor.notification.user")->first();
     $device_token = null;
     $msg = $message;
     foreach ($deviceWithUser->sensor[0]->notification->user as $user) {
         $device_token = $user->device_token;
         if ($user->pivot->status == "on") {
             if ($device_token != null) {
                 $url = 'https://push.ionic.io/api/v1/push';
                 $data = array('tokens' => array($device_token), 'notification' => array('alert' => $msg, "ios" => array('badge' => 1, 'sound' => "chime.aiff", 'expiry' => 1423238641, 'priority' => 10, 'contentAvailable' => true)));
                 $content = json_encode($data);
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $url);
                 curl_setopt($ch, CURLOPT_POST, TRUE);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
                 curl_setopt($ch, CURLOPT_USERPWD, "f9e571076976cd282ce1ded84e3c95c4cb39545374a188ee");
                 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-Ionic-Application-Id: b86d0d75'));
                 $result = curl_exec($ch);
                 curl_close($ch);
             }
         }
     }
     return response("Sent notification success", 200);
 }
예제 #3
0
        }
        if ($notificationCheck->maxCelsius != 0 && $notificationCheck->maxCelsius < $value) {
            $notificationController->sentMonitorNotification("Alert!! : " . $id . " reach minimum temperature >" . $notificationCheck->maxCelsius . " celsius", $id);
        }
    }
    $temperature = new Temperature();
    $temperature->celsiusValue = $value;
    $Sensor->temperature()->save($temperature);
});
Route::get('sensingResister/{device_id}/{temperature}/{soilmoisture}/{light}/{humidity}', function ($id, $temp, $soil, $lux, $humid) {
    $DeviceBaseId = DB::table('sensingdevice')->where('device_id', $id)->value('id');
    $SensorPrimaryKey = DB::table('sensor')->where('sensingDevice_id', $DeviceBaseId)->value('id');
    $checkHourly = Light::where('sensor_id', '=', $SensorPrimaryKey)->count();
    $Sensor = Sensor::find($SensorPrimaryKey);
    $notificationController = new notificationController();
    $device = \App\SensingDevice::where("device_id", "=", $id)->first();
    $sensor = \App\Sensor::where("sensingDevice_id", "=", $device->id)->first();
    $notificationCheck = MinMaxMonitor::where("sensor_id", "=", $sensor->id)->first();
    if ($notificationCheck != null) {
        if ($notificationCheck->minHumidityPercentage != 0 && $notificationCheck->minHumidityPercentage > $humid) {
            $notificationController->sentMonitorNotification("Alert!! : " . $id . " reach minimum humidity <" . $notificationCheck->minHumidityPercentage . " %", $id);
        }
        if ($notificationCheck->maxHumidityPercentage != 0 && $notificationCheck->maxHumidityPercentage < $humid) {
            $notificationController->sentMonitorNotification("Alert!! : " . $id . " reach maximum humidity >" . $notificationCheck->maxHumidityPercentage . " %", $id);
        }
        if ($notificationCheck->minCelsius != 0 && $notificationCheck->minCelsius > $temp) {
            $notificationController->sentMonitorNotification("Alert!! : " . $id . " reach minimum temperature <" . $notificationCheck->minCelsius . " celsius", $id);
        }
        if ($notificationCheck->maxCelsius != 0 && $notificationCheck->maxCelsius < $temp) {
            $notificationController->sentMonitorNotification("Alert!! : " . $id . " reach minimum temperature >" . $notificationCheck->maxCelsius . " celsius", $id);
        }