| @@ -4,8 +4,6 @@ file: carpark.php 停車管理 | |||||
| */ | */ | ||||
| if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||||
| require_once(MQ_CLASS_FILE); | |||||
| // ----- 定義常數(路徑, cache秒數) ----- | // ----- 定義常數(路徑, cache秒數) ----- | ||||
| define('APP_VERSION', '100'); // 版本號 | define('APP_VERSION', '100'); // 版本號 | ||||
| define('MAX_AGE', 604800); // cache秒數, 此定義1個月 | define('MAX_AGE', 604800); // cache秒數, 此定義1個月 | ||||
| @@ -53,6 +51,14 @@ class Carpark extends CI_Controller | |||||
| $this->load->model('sync_data_model'); | $this->load->model('sync_data_model'); | ||||
| $this->sync_data_model->init($this->vars); // for memcache | $this->sync_data_model->init($this->vars); // for memcache | ||||
| // mqtt | |||||
| $station_setting = $this->sync_data_model->station_setting_query(); | |||||
| $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | |||||
| $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | |||||
| $this->vars['mqtt_ip'] = $mqtt_ip; | |||||
| $this->vars['mqtt_port'] = $mqtt_port; | |||||
| $this->sync_data_model->init($this->vars); // for mqtt | |||||
| // 產生 excel 報表 | // 產生 excel 報表 | ||||
| $this->load->model('excel_model'); | $this->load->model('excel_model'); | ||||
| $this->excel_model->init($this->vars); | $this->excel_model->init($this->vars); | ||||
| @@ -213,19 +219,6 @@ class Carpark extends CI_Controller | |||||
| trigger_error($LOG_FLAG . __FUNCTION__ . '..' . print_r($parms, true)); | trigger_error($LOG_FLAG . __FUNCTION__ . '..' . print_r($parms, true)); | ||||
| // mqtt subscribe | |||||
| $station_setting = $this->sync_data_model->station_setting_query(); | |||||
| $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | |||||
| $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | |||||
| // 字幕 MQTT | |||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| // 開門 MQTT | |||||
| $this->vars['mqtt_opendoor'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt_opendoor']->connect(); | |||||
| // 載入模組 | // 載入模組 | ||||
| $this->load->model('cars_model'); | $this->load->model('cars_model'); | ||||
| $this->cars_model->init($this->vars); | $this->cars_model->init($this->vars); | ||||
| @@ -252,15 +245,6 @@ class Carpark extends CI_Controller | |||||
| trigger_error($LOG_FLAG . __FUNCTION__ . '..' . print_r($parms, true)); | trigger_error($LOG_FLAG . __FUNCTION__ . '..' . print_r($parms, true)); | ||||
| // mqtt subscribe | |||||
| $station_setting = $this->sync_data_model->station_setting_query(); | |||||
| $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | |||||
| $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | |||||
| // 開門 MQTT | |||||
| $this->vars['mqtt_opendoor'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt_opendoor']->connect(); | |||||
| // 載入模組 | // 載入模組 | ||||
| $this->load->model('cars_model'); | $this->load->model('cars_model'); | ||||
| $this->cars_model->init($this->vars); | $this->cars_model->init($this->vars); | ||||
| @@ -978,17 +962,7 @@ class Carpark extends CI_Controller | |||||
| $value = $this->uri->segment(4, 0); // value | $value = $this->uri->segment(4, 0); // value | ||||
| $station_no = $this->uri->segment(5); // station_no | $station_no = $this->uri->segment(5); // station_no | ||||
| // mqtt subscribe | |||||
| $station_setting = $this->sync_data_model->station_setting_query(); | |||||
| $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | |||||
| $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | |||||
| // 字幕 MQTT | |||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| // 重新載入 | // 重新載入 | ||||
| $this->sync_data_model->init($this->vars); | |||||
| $data = $this->sync_data_model->pks_availables_update($group_id, $value, true, $station_no); | $data = $this->sync_data_model->pks_availables_update($group_id, $value, true, $station_no); | ||||
| echo json_encode($data, JSON_UNESCAPED_UNICODE); | echo json_encode($data, JSON_UNESCAPED_UNICODE); | ||||
| } | } | ||||
| @@ -30,8 +30,6 @@ var ip='66.249.82.183';var clientid='565162cb67dfb';var mqtt_ip='192.168.51.11'; | |||||
| define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path name | define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path name | ||||
| define('LOG_FILE', FILE_BASE.APP_NAME.'/logs/cario.'); // log file name | define('LOG_FILE', FILE_BASE.APP_NAME.'/logs/cario.'); // log file name | ||||
| require_once(MQ_CLASS_FILE); | |||||
| class Cars extends CI_Controller | class Cars extends CI_Controller | ||||
| { | { | ||||
| var $vars = array(); | var $vars = array(); | ||||
| @@ -103,14 +101,12 @@ class Cars extends CI_Controller | |||||
| $this->load->model('sync_data_model'); | $this->load->model('sync_data_model'); | ||||
| $this->sync_data_model->init($this->vars); // for memcache | $this->sync_data_model->init($this->vars); // for memcache | ||||
| // mqtt subscribe | |||||
| // mqtt | |||||
| $station_setting = $this->sync_data_model->station_setting_query(); | $station_setting = $this->sync_data_model->station_setting_query(); | ||||
| $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | ||||
| $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | ||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| $this->vars['mqtt_opendoor'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt_opendoor']->connect(); | |||||
| $this->vars['mqtt_ip'] = $mqtt_ip; | |||||
| $this->vars['mqtt_port'] = $mqtt_port; | |||||
| // init again | // init again | ||||
| $this->sync_data_model->init($this->vars); // for mqtt | $this->sync_data_model->init($this->vars); // for mqtt | ||||
| @@ -21,8 +21,6 @@ method: POST | |||||
| 上傳圖檔欄位名稱為cars | 上傳圖檔欄位名稱為cars | ||||
| */ | */ | ||||
| require_once(MQ_CLASS_FILE); | |||||
| class Pks extends CI_Controller | class Pks extends CI_Controller | ||||
| { | { | ||||
| var $vars = array(); // 共用變數 | var $vars = array(); // 共用變數 | ||||
| @@ -93,8 +91,10 @@ class Pks extends CI_Controller | |||||
| $station_setting = $this->sync_data_model->station_setting_query(); | $station_setting = $this->sync_data_model->station_setting_query(); | ||||
| $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | ||||
| $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | ||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| //$this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| //$this->vars['mqtt']->connect(); | |||||
| $this->vars['mqtt_ip'] = $mqtt_ip; | |||||
| $this->vars['mqtt_port'] = $mqtt_port; | |||||
| // init sync model | // init sync model | ||||
| $this->sync_data_model->init($this->vars); | $this->sync_data_model->init($this->vars); | ||||
| @@ -3,6 +3,7 @@ | |||||
| file: cars_model.php | file: cars_model.php | ||||
| */ | */ | ||||
| require_once(ALTOB_SYNC_FILE) ; | require_once(ALTOB_SYNC_FILE) ; | ||||
| require_once(MQ_CLASS_FILE); | |||||
| define('CARS_TMP_LOG', 'cars_tmp_log'); // 暫存進出車號 | define('CARS_TMP_LOG', 'cars_tmp_log'); // 暫存進出車號 | ||||
| @@ -23,6 +24,17 @@ class Cars_model extends CI_Model | |||||
| public function init($vars) | public function init($vars) | ||||
| { | { | ||||
| $this->vars = $vars; | $this->vars = $vars; | ||||
| if(isset($this->vars['mqtt_ip']) && isset($this->vars['mqtt_port'])) | |||||
| { | |||||
| // 一般 | |||||
| $this->vars['mqtt'] = new phpMQTT($this->vars['mqtt_ip'], $this->vars['mqtt_port'], uniqid(). 'mqtt'); | |||||
| $this->vars['mqtt']->connect(); | |||||
| // 開門專用 | |||||
| $this->vars['mqtt_opendoor'] = new phpMQTT($this->vars['mqtt_ip'], $this->vars['mqtt_port'], uniqid() . 'mqtt_opendoor'); | |||||
| $this->vars['mqtt_opendoor']->connect(); | |||||
| } | |||||
| } | } | ||||
| // 車輛進出傳入車牌號碼 (2016/07/27) | // 車輛進出傳入車牌號碼 (2016/07/27) | ||||
| @@ -3,6 +3,8 @@ | |||||
| file: pks_model.php 車位在席資料庫處理模組 | file: pks_model.php 車位在席資料庫處理模組 | ||||
| */ | */ | ||||
| require_once(MQ_CLASS_FILE); | |||||
| class Pks_model extends CI_Model | class Pks_model extends CI_Model | ||||
| { | { | ||||
| var $vars = array(); | var $vars = array(); | ||||
| @@ -16,6 +18,13 @@ class Pks_model extends CI_Model | |||||
| public function init($vars) | public function init($vars) | ||||
| { | { | ||||
| $this->vars = $vars; | $this->vars = $vars; | ||||
| if(isset($this->vars['mqtt_ip']) && isset($this->vars['mqtt_port'])) | |||||
| { | |||||
| // 一般 | |||||
| $this->vars['mqtt'] = new phpMQTT($this->vars['mqtt_ip'], $this->vars['mqtt_port'], uniqid(). 'mqtt'); | |||||
| $this->vars['mqtt']->connect(); | |||||
| } | |||||
| } | } | ||||