diff --git a/controllers/Carpark.php b/controllers/Carpark.php index 5283318..9bd533a 100644 --- a/controllers/Carpark.php +++ b/controllers/Carpark.php @@ -197,7 +197,7 @@ class Carpark extends CI_Controller $this->load->model('cars_model'); $this->cars_model->init($this->vars); $this->cars_model->lprio($parms); - + $this->cars_model->stop(); echo 'ok'; exit; } @@ -223,7 +223,7 @@ class Carpark extends CI_Controller $this->load->model('cars_model'); $this->cars_model->init($this->vars); $this->cars_model->opendoor_lprio($parms); - + $this->cars_model->stop(); echo 'ok'; exit; } @@ -260,7 +260,7 @@ class Carpark extends CI_Controller { $this->cars_model->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}"); // 月租訊號 } - + $this->cars_model->stop(); echo 'ok'; exit; } @@ -298,6 +298,7 @@ class Carpark extends CI_Controller if(sizeof($msg_arr) != 4) { + $this->sync_data_model->stop(); trigger_error($LOG_FLAG . __FUNCTION__ . "..error_size.." . print_r($msg_arr, true)); echo 'error_size'; exit; @@ -305,6 +306,7 @@ class Carpark extends CI_Controller if($msg_arr[0] != 'N888' || $msg_arr[3] != 'altob') { + $this->sync_data_model->stop(); trigger_error($LOG_FLAG . __FUNCTION__ . "..unknown_msg.." . print_r($msg_arr, true)); echo 'unknown_msg'; exit; @@ -315,8 +317,9 @@ class Carpark extends CI_Controller $value = isset($msg_arr[2]) ? $msg_arr[2] : 0; $result = $this->sync_data_model->force_sync_888($first_station_no, $group_id, $value); trigger_error($LOG_FLAG . __FUNCTION__ . "..{$first_station_no}|{$group_id}|{$value}..result..{$result}.."); - } + } + $this->sync_data_model->stop(); echo 'ok'; exit; } @@ -333,6 +336,7 @@ class Carpark extends CI_Controller if(!$station_setting) { + $this->sync_data_model->stop(); echo json_encode('fail', JSON_UNESCAPED_UNICODE); exit; // 中斷 } @@ -363,11 +367,15 @@ class Carpark extends CI_Controller if(!$station_setting) { + $this->sync_data_model->stop(); echo json_encode('fail', JSON_UNESCAPED_UNICODE); exit; // 中斷 } } + + $this->sync_data_model->stop(); echo json_encode($station_setting, JSON_UNESCAPED_UNICODE); + exit; } // [排程 or 強制] 同步場站資訊 @@ -414,6 +422,7 @@ class Carpark extends CI_Controller $this->sync_data_model->sync_switch_lpr($switch_lpr_arr); } + $this->sync_data_model->stop(); } // [API] 取得最新未結清 @@ -434,6 +443,7 @@ class Carpark extends CI_Controller } $data = $this->sync_data_model->get_last_unbalanced_cario($lpr, $station_no); + $this->sync_data_model->stop(); echo json_encode($data, JSON_UNESCAPED_UNICODE); } @@ -497,6 +507,7 @@ class Carpark extends CI_Controller public function sync_minutely() { $this->sync_data_model->sync_pks_groups(); // 同步在席現況 + $this->sync_data_model->stop(); } // 20170816 手動新增入場資料 @@ -964,6 +975,7 @@ class Carpark extends CI_Controller // 重新載入 $data = $this->sync_data_model->pks_availables_update($group_id, $value, true, $station_no); + $this->sync_data_model->stop(); echo json_encode($data, JSON_UNESCAPED_UNICODE); } diff --git a/controllers/Cars.php b/controllers/Cars.php index 065c542..8b64199 100644 --- a/controllers/Cars.php +++ b/controllers/Cars.php @@ -159,6 +159,7 @@ class Cars extends CI_Controller $parms = $this->uri->uri_to_assoc(3); $parms['lpr'] = urldecode($parms['lpr']); // 中文車牌 $this->cars_model->opendoor_lprio($parms); + $this->cars_model->stop(); } // IVS -> 車號, 影像 @@ -224,6 +225,7 @@ http://192.168.10.201/cars.html/ipcam/sno/12119/ivsno/0/io/O/type/C/lpr/4750YC/c $parms['pic_name'] = $config['file_name']; // 圖片檔名 $this->cars_model->lprio($parms); // 測試eTag + $this->cars_model->stop(); } // 用車牌與eTag, 檢查資料庫 @@ -232,7 +234,8 @@ http://192.168.10.201/cars.html/ipcam/sno/12119/ivsno/0/io/O/type/C/lpr/4750YC/c $lpr = $this->uri->segment(3); $etag = $this->uri->segment(4); - $this->cars_model->check_lpr_etag($lpr, $etag); + $this->cars_model->check_lpr_etag($lpr, $etag); + $this->cars_model->stop(); exit; } diff --git a/controllers/Pks.php b/controllers/Pks.php index a71022a..c346ede 100644 --- a/controllers/Pks.php +++ b/controllers/Pks.php @@ -254,6 +254,7 @@ class Pks extends CI_Controller */ $this->pks_model->pksio($parms); // 車輛進出車格資料庫處理 + $this->pks_model->stop(); exit; } @@ -263,6 +264,7 @@ class Pks extends CI_Controller public function reculc() { $this->pks_model->reculc(); + $this->pks_model->stop(); } @@ -273,6 +275,7 @@ class Pks extends CI_Controller { $station_no = $this->uri->segment(3); $data = $this->pks_model->query_station_status($station_no); + $this->pks_model->stop(); echo json_encode($data, JSON_UNESCAPED_UNICODE); } @@ -282,6 +285,7 @@ class Pks extends CI_Controller $station_no = $this->uri->segment(3); $pksno = $this->uri->segment(4); $data = $this->pks_model->query_station_pks($station_no, $pksno); + $this->pks_model->stop(); echo json_encode($data, JSON_UNESCAPED_UNICODE); } diff --git a/models/Cars_model.php b/models/Cars_model.php index 79236be..e5269a8 100644 --- a/models/Cars_model.php +++ b/models/Cars_model.php @@ -34,8 +34,21 @@ class Cars_model extends CI_Model $this->vars['mqtt_opendoor'] = new phpMQTT($this->vars['mqtt_ip'], $this->vars['mqtt_port'], uniqid() . 'mqtt_opendoor'); $this->vars['mqtt_opendoor']->connect(); } - } + + // 結束 + public function stop() + { + if(isset($this->vars['mqtt'])) + { + $this->vars['mqtt']->close(); + } + + if(isset($this->vars['mqtt_opendoor'])) + { + $this->vars['mqtt_opendoor']->close(); + } + } // 車輛進出傳入車牌號碼 (2016/07/27) public function opendoor_lprio($parms) diff --git a/models/Pks_model.php b/models/Pks_model.php index 92d74c9..285c069 100644 --- a/models/Pks_model.php +++ b/models/Pks_model.php @@ -26,6 +26,15 @@ class Pks_model extends CI_Model $this->vars['mqtt']->connect(); } } + + // 結束 + public function stop() + { + if(isset($this->vars['mqtt'])) + { + $this->vars['mqtt']->close(); + } + } // 車輛進出傳入車牌號碼 diff --git a/models/Sync_data_model.php b/models/Sync_data_model.php index fc92207..9bb53f2 100644 --- a/models/Sync_data_model.php +++ b/models/Sync_data_model.php @@ -25,6 +25,15 @@ class Sync_data_model extends CI_Model $this->vars = $vars; } + // 結束 + public function stop() + { + if(isset($this->vars['mqtt'])) + { + $this->vars['mqtt']->close(); + } + } + // 送出至message queue(目前用mqtt) public function mq_send($topic, $msg) {