コード例 #1
0
 public function actionRemoveDevice()
 {
     while (1) {
         $deviceModel = Devices::find()->all();
         foreach ($deviceModel as $device) {
             $deviceLogs = DeviceLogs::find()->where(['device_id' => $device->id])->orderBy(['id' => SORT_DESC])->one();
             if (empty($deviceLogs)) {
                 $device->status = 0;
                 $device->server_id = NULL;
                 if ($device->save()) {
                     echo "Device with id " . $device->controller_id . " Successfully offlined \n";
                 } else {
                     print_r($device);
                 }
             } else {
                 $deviceTime = date("Y-m-d H:i:s", strtotime($deviceLogs->created . " +1 minute"));
                 if (strtotime($deviceTime) < strtotime(date("Y-m-d H:i:s"))) {
                     $device->status = 0;
                     $device->server_id = NULL;
                     if ($device->save()) {
                         echo date("Y-m-d H:i:s", strtotime($deviceTime)) . " = " . date("Y-m-d H:i:s") . "\n";
                         echo "Device with id " . $device->controller_id . " Successfully offlined \n";
                     } else {
                         print_r($device->getErrors());
                     }
                 } else {
                     echo "Device with id " . $device->controller_id . " is Online. \n";
                 }
             }
         }
         sleep(10);
     }
 }
コード例 #2
0
 public function actionDeviceOverview()
 {
     $deviceModel = Devices::find()->all();
     $this->layout = "dashboard";
     $response = array();
     foreach ($deviceModel as $device) {
         $temp = array();
         $deviceLogs = DeviceLogs::find()->where(['device_id' => $device->id])->orderBy(['id' => SORT_DESC])->one();
         $temp['id'] = $device->id;
         $temp['controller_id'] = $device->controller_id;
         $temp['sim_number'] = $device->sim_number;
         $temp['status'] = $device->status == 1 ? "Online" : "Offline";
         if (!empty($deviceLogs)) {
             $temp['current_voltage'] = $deviceLogs->current_voltage;
             $temp['current_load'] = isset($deviceLogs->current_load) ? $deviceLogs->current_load / 10 : $deviceLogs->current_load;
             $temp['voltage_status'] = Helper::voltageStatus($deviceLogs->voltage_status);
             $temp['light_status'] = Helper::lightStatus($deviceLogs->light_status);
             $temp['overload_status'] = Helper::overloadStatus($deviceLogs->overload_status);
             $temp['created'] = date("d-M-Y H:i:s", strtotime($deviceLogs->created));
         }
         $response[] = $temp;
     }
     $dataProvider = new ArrayDataProvider(['key' => 'id', 'allModels' => $response]);
     return $this->render('deviceOverview', ['dataProvider' => $dataProvider]);
 }