| @@ -82,6 +82,31 @@ define('MEMCACHE_PORT', 11211); // memcache post no (default:11211) | |||||
| /* | /* | ||||
| |-------------------------------------------------------------------------- | |-------------------------------------------------------------------------- | ||||
| | DELIMITER - 共用設定 | |||||
| |-------------------------------------------------------------------------- | |||||
| */ | |||||
| define('SYNC_DELIMITER_ST_NAME', ' & '); // (拆分) 場站名稱 | |||||
| define('SYNC_DELIMITER_ST_NO', ','); // (拆分) 場站編號 | |||||
| define('SYNC_DELIMITER_ST_INFO', '|'); // (拆分) 其它 | |||||
| /* | |||||
| |-------------------------------------------------------------------------- | |||||
| | MEMCACHE KEY - 共用設定 | |||||
| |-------------------------------------------------------------------------- | |||||
| */ | |||||
| define('MCACHE_STATION_NO_STR', 'station_no_str'); | |||||
| define('MCACHE_STATION_NAME_STR', 'station_name_str'); | |||||
| define('MCACHE_STATION_IP_STR', 'station_ip_str'); | |||||
| define('MCACHE_STATION_PORT_STR', 'station_port_str'); | |||||
| define('MCACHE_STATION_888_STR', 'station_888_str'); | |||||
| define('MCACHE_SYNC_888_TMP_LOG', 'sync_888_tmp_log'); // 暫存 888 進出 | |||||
| define('MCACHE_STATION_SETTINGS', 'altob_station_settings'); // 場站設定匯整 | |||||
| /* | |||||
| |-------------------------------------------------------------------------- | |||||
| | 自定義連結 - 共用設定 | | 自定義連結 - 共用設定 | ||||
| |-------------------------------------------------------------------------- | |-------------------------------------------------------------------------- | ||||
| */ | */ | ||||
| @@ -39,18 +39,27 @@ class Carpark extends CI_Controller | |||||
| $this->vars['mcache'] = new Memcache; | $this->vars['mcache'] = new Memcache; | ||||
| $this->vars['mcache']->connect(MEMCACHE_HOST, MEMCACHE_PORT) or die ('Could not connect memcache'); | $this->vars['mcache']->connect(MEMCACHE_HOST, MEMCACHE_PORT) or die ('Could not connect memcache'); | ||||
| // mqtt subscribe | |||||
| /* | |||||
| // mqtt subscribe | |||||
| $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid()); | $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid()); | ||||
| //if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); } | //if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); } | ||||
| $this->vars['mqtt']->connect(); | $this->vars['mqtt']->connect(); | ||||
| */ | |||||
| $this->load->model('carpark_model'); | $this->load->model('carpark_model'); | ||||
| $this->carpark_model->init($this->vars); | $this->carpark_model->init($this->vars); | ||||
| // 微調剩餘車位數 | |||||
| // 資料介接模組 | |||||
| $this->load->model('sync_data_model'); | $this->load->model('sync_data_model'); | ||||
| $this->sync_data_model->init($this->vars); | $this->sync_data_model->init($this->vars); | ||||
| // 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; | |||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| // 產生 excel 報表 | // 產生 excel 報表 | ||||
| $this->load->model('excel_model'); | $this->load->model('excel_model'); | ||||
| $this->excel_model->init($this->vars); | $this->excel_model->init($this->vars); | ||||
| @@ -89,10 +89,23 @@ class Cars extends CI_Controller | |||||
| $this->vars['mcache'] = new Memcache; | $this->vars['mcache'] = new Memcache; | ||||
| $this->vars['mcache']->pconnect(MEMCACHE_HOST, MEMCACHE_PORT) or die ('Could not connect memcache'); | $this->vars['mcache']->pconnect(MEMCACHE_HOST, MEMCACHE_PORT) or die ('Could not connect memcache'); | ||||
| /* | |||||
| // mqtt subscribe | // mqtt subscribe | ||||
| $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid()); | $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid()); | ||||
| //if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); } | //if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); } | ||||
| if(!$this->vars['mqtt']->connect()){ trigger_error('..Could not connect mqtt..go on..'); } | if(!$this->vars['mqtt']->connect()){ trigger_error('..Could not connect mqtt..go on..'); } | ||||
| */ | |||||
| // 資料介接模組 | |||||
| $this->load->model('sync_data_model'); | |||||
| $this->sync_data_model->init($this->vars); | |||||
| // 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; | |||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| $this->load->model('cars_model'); | $this->load->model('cars_model'); | ||||
| $this->cars_model->init($this->vars); | $this->cars_model->init($this->vars); | ||||
| @@ -170,8 +183,6 @@ http://192.168.10.201/cars.html/ipcam/sno/12119/ivsno/0/io/O/type/C/lpr/4750YC/c | |||||
| $parms['lpr'] = urldecode($parms['lpr']); // 中文車牌 | $parms['lpr'] = urldecode($parms['lpr']); // 中文車牌 | ||||
| // 同步並送出一次出入口 888 | // 同步並送出一次出入口 888 | ||||
| $this->load->model('sync_data_model'); | |||||
| $this->sync_data_model->init($this->vars); | |||||
| $this->sync_data_model->sync_888($parms); | $this->sync_data_model->sync_888($parms); | ||||
| $pic_folder = CAR_PIC.$this->vars['date_num'].'/'; // 今日資料夾名(yyyymmdd) | $pic_folder = CAR_PIC.$this->vars['date_num'].'/'; // 今日資料夾名(yyyymmdd) | ||||
| @@ -60,10 +60,11 @@ class Pks extends CI_Controller | |||||
| } | } | ||||
| set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log | set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log | ||||
| /* | |||||
| // mqtt subscribe | // mqtt subscribe | ||||
| $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid()); | $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid()); | ||||
| if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); } | if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); } | ||||
| */ | |||||
| // ----- 定義常數(路徑, cache秒數) ----- | // ----- 定義常數(路徑, cache秒數) ----- | ||||
| define('APP_VERSION', '100'); // 版本號 | define('APP_VERSION', '100'); // 版本號 | ||||
| @@ -83,6 +84,17 @@ class Pks extends CI_Controller | |||||
| $this->load->model('pks_model'); | $this->load->model('pks_model'); | ||||
| $this->pks_model->init($this->vars); | $this->pks_model->init($this->vars); | ||||
| // 資料介接模組 | |||||
| $this->load->model('sync_data_model'); | |||||
| $this->sync_data_model->init($this->vars); | |||||
| // 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; | |||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| } | } | ||||
| @@ -10,20 +10,6 @@ define('SYNC_PKS_GROUP_ID_MI', 'M888'); // 機車 888 | |||||
| define('SYNC_API_URL', 'http://61.219.172.11:60123/admins_station.html/'); | define('SYNC_API_URL', 'http://61.219.172.11:60123/admins_station.html/'); | ||||
| define('SYNC_DELIMITER_ST_NAME', ' & '); // (拆分) 場站名稱 | |||||
| define('SYNC_DELIMITER_ST_NO', ','); // (拆分) 場站編號 | |||||
| define('SYNC_DELIMITER_ST_INFO', '|'); // (拆分) 其它 | |||||
| define('MCACHE_STATION_NO_STR', 'station_no_str'); | |||||
| define('MCACHE_STATION_NAME_STR', 'station_name_str'); | |||||
| define('MCACHE_STATION_IP_STR', 'station_ip_str'); | |||||
| define('MCACHE_STATION_PORT_STR', 'station_port_str'); | |||||
| define('MCACHE_STATION_888_STR', 'station_888_str'); | |||||
| define('MCACHE_MQTT_IP_STR', 'mqtt_ip_str'); | |||||
| define('MCACHE_MQTT_PORT_STR', 'mqtt_port_str'); | |||||
| define('MCACHE_SYNC_888_TMP_LOG', 'sync_888_tmp_log'); // 暫存 888 進出 | |||||
| class Sync_data_model extends CI_Model | class Sync_data_model extends CI_Model | ||||
| { | { | ||||
| var $vars = array(); | var $vars = array(); | ||||
| @@ -614,21 +600,27 @@ class Sync_data_model extends CI_Model | |||||
| $station_no_arr = array(); | $station_no_arr = array(); | ||||
| $station_name_arr = array(); | $station_name_arr = array(); | ||||
| $station_888_arr = array(); | $station_888_arr = array(); | ||||
| $mqtt_ip_arr = array(); | |||||
| $mqtt_port_arr = array(); | |||||
| $settings = array(); | |||||
| foreach($station_setting_arr as $data) | foreach($station_setting_arr as $data) | ||||
| { | { | ||||
| array_push($station_no_arr, $data['station_no']); | |||||
| $station_no = $data['station_no']; | |||||
| array_push($station_no_arr, $station_no); | |||||
| array_push($station_name_arr, $data['short_name']); | array_push($station_name_arr, $data['short_name']); | ||||
| array_push($station_888_arr, $data['station_888']); | array_push($station_888_arr, $data['station_888']); | ||||
| array_push($mqtt_ip_arr, empty($data['mqtt_ip']) ? MQ_HOST : $data['mqtt_ip']); | |||||
| array_push($mqtt_port_arr, empty($data['mqtt_port']) ? MQ_PORT : $data['mqtt_port']); | |||||
| if(!isset($settings[$station_no])) | |||||
| { | |||||
| $settings[$station_no] = array(); | |||||
| } | |||||
| $settings[$station_no]['station_888'] = empty($data['station_888']) ? 1 : $data['station_888']; | |||||
| $settings[$station_no]['mqtt_ip'] = empty($data['mqtt_ip']) ? MQ_HOST : $data['mqtt_ip']; | |||||
| $settings[$station_no]['mqtt_port'] = empty($data['mqtt_port']) ? MQ_PORT : $data['mqtt_port']; | |||||
| } | } | ||||
| $station_no_str = implode(SYNC_DELIMITER_ST_NO, $station_no_arr); // 取值時會用到 | $station_no_str = implode(SYNC_DELIMITER_ST_NO, $station_no_arr); // 取值時會用到 | ||||
| $station_name_str = implode(SYNC_DELIMITER_ST_NAME, $station_name_arr); // 純顯示 | $station_name_str = implode(SYNC_DELIMITER_ST_NAME, $station_name_arr); // 純顯示 | ||||
| $station_888_str = implode(SYNC_DELIMITER_ST_INFO, $station_888_arr); // 場站 888 設定 | $station_888_str = implode(SYNC_DELIMITER_ST_INFO, $station_888_arr); // 場站 888 設定 | ||||
| $mqtt_ip_str = implode(SYNC_DELIMITER_ST_INFO, $mqtt_ip_arr); // 場站 MQTT ip | |||||
| $mqtt_port_str = implode(SYNC_DELIMITER_ST_INFO, $mqtt_port_arr); // 場站 MQTT port | |||||
| // 設定到 mcache | // 設定到 mcache | ||||
| $this->vars['mcache']->set(MCACHE_STATION_NO_STR, $station_no_str); | $this->vars['mcache']->set(MCACHE_STATION_NO_STR, $station_no_str); | ||||
| @@ -636,8 +628,7 @@ class Sync_data_model extends CI_Model | |||||
| $this->vars['mcache']->set(MCACHE_STATION_IP_STR, $station_ip_str); | $this->vars['mcache']->set(MCACHE_STATION_IP_STR, $station_ip_str); | ||||
| $this->vars['mcache']->set(MCACHE_STATION_PORT_STR, $station_port_str); | $this->vars['mcache']->set(MCACHE_STATION_PORT_STR, $station_port_str); | ||||
| $this->vars['mcache']->set(MCACHE_STATION_888_STR, $station_888_str); | $this->vars['mcache']->set(MCACHE_STATION_888_STR, $station_888_str); | ||||
| $this->vars['mcache']->set(MCACHE_MQTT_IP_STR, $mqtt_ip_str); | |||||
| $this->vars['mcache']->set(MCACHE_MQTT_PORT_STR, $mqtt_port_str); | |||||
| $this->vars['mcache']->set(MCACHE_STATION_SETTINGS, $settings); | |||||
| return 'ok'; | return 'ok'; | ||||
| } | } | ||||
| @@ -649,14 +640,13 @@ class Sync_data_model extends CI_Model | |||||
| $station_ip_str = $this->vars['mcache']->get(MCACHE_STATION_IP_STR); | $station_ip_str = $this->vars['mcache']->get(MCACHE_STATION_IP_STR); | ||||
| $station_port_str = $this->vars['mcache']->get(MCACHE_STATION_PORT_STR); | $station_port_str = $this->vars['mcache']->get(MCACHE_STATION_PORT_STR); | ||||
| $station_888_str = $this->vars['mcache']->get(MCACHE_STATION_888_STR); | $station_888_str = $this->vars['mcache']->get(MCACHE_STATION_888_STR); | ||||
| $mqtt_ip_str = $this->vars['mcache']->get(MCACHE_MQTT_IP_STR); | |||||
| $mqtt_port_str = $this->vars['mcache']->get(MCACHE_MQTT_PORT_STR); | |||||
| $settings = $this->vars['mcache']->get(MCACHE_STATION_SETTINGS); | |||||
| if( $reload || | if( $reload || | ||||
| empty($station_no_str) || empty($station_name_str) || | empty($station_no_str) || empty($station_name_str) || | ||||
| empty($station_ip_str) || empty($mqtt_ip_str) || | empty($station_ip_str) || empty($mqtt_ip_str) || | ||||
| empty($station_port_str) || empty($mqtt_port_str) || | |||||
| empty($station_888_str) | |||||
| empty($station_888_str) || | |||||
| empty($settings) | |||||
| ) | ) | ||||
| { | { | ||||
| $result = $this->reload_station_setting(); | $result = $this->reload_station_setting(); | ||||
| @@ -668,8 +658,7 @@ class Sync_data_model extends CI_Model | |||||
| $station_ip_str = $this->vars['mcache']->get(MCACHE_STATION_IP_STR); | $station_ip_str = $this->vars['mcache']->get(MCACHE_STATION_IP_STR); | ||||
| $station_port_str = $this->vars['mcache']->get(MCACHE_STATION_PORT_STR); | $station_port_str = $this->vars['mcache']->get(MCACHE_STATION_PORT_STR); | ||||
| $station_888_str = $this->vars['mcache']->get(MCACHE_STATION_888_STR); | $station_888_str = $this->vars['mcache']->get(MCACHE_STATION_888_STR); | ||||
| $mqtt_ip_str = $this->vars['mcache']->get(MCACHE_MQTT_IP_STR); | |||||
| $mqtt_port_str = $this->vars['mcache']->get(MCACHE_MQTT_PORT_STR); | |||||
| $settings = $this->vars['mcache']->get(MCACHE_STATION_SETTINGS); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -684,14 +673,19 @@ class Sync_data_model extends CI_Model | |||||
| } | } | ||||
| } | } | ||||
| // 第一個場站編號 | |||||
| $station_no_arr = explode(SYNC_DELIMITER_ST_NO, $station_no_str); | |||||
| $first_station_no = $station_no_arr[0]; | |||||
| $station_setting = array(); | $station_setting = array(); | ||||
| $station_setting['station_no'] = $station_no_str; | $station_setting['station_no'] = $station_no_str; | ||||
| $station_setting['station_name'] = $station_name_str; | $station_setting['station_name'] = $station_name_str; | ||||
| $station_setting['station_ip'] = $station_ip_str; | $station_setting['station_ip'] = $station_ip_str; | ||||
| $station_setting['station_port'] = $station_port_str; | $station_setting['station_port'] = $station_port_str; | ||||
| $station_setting['station_888'] = $station_888_str; | $station_setting['station_888'] = $station_888_str; | ||||
| $station_setting['mqtt_ip'] = $mqtt_ip_str; | |||||
| $station_setting['mqtt_port'] = $mqtt_port_str; | |||||
| $station_setting['settings'] = $settings; | |||||
| $station_setting['mqtt_ip'] = $settings[$first_station_no]['mqtt_ip']; | |||||
| $station_setting['mqtt_port'] = $settings[$first_station_no]['mqtt_port']; | |||||
| return $station_setting; | return $station_setting; | ||||
| } | } | ||||
| @@ -24,8 +24,9 @@ | |||||
| <input id="ss_station_service_url" name='station_service_url' class="form-control" style="font-size:28px" readonly> | <input id="ss_station_service_url" name='station_service_url' class="form-control" style="font-size:28px" readonly> | ||||
| </div> | </div> | ||||
| <div class="form-group"> | <div class="form-group"> | ||||
| <label style="font-size:22px">場站 MQTT</label> | |||||
| <input id="ss_station_mqtt" name='station_mqtt' class="form-control" style="font-size:28px" readonly> | |||||
| <label style="font-size:22px">其它設定</label> | |||||
| <textarea readonly id="ss_station_info" name='station_info' class="form-control" style="font-size:28px" rows="4"> | |||||
| </textarea> | |||||
| </div> | </div> | ||||
| <!--button type="submit" class="btn btn-default">存檔</button> | <!--button type="submit" class="btn btn-default">存檔</button> | ||||
| <button type="reset" class="btn btn-default">重填</button--> | <button type="reset" class="btn btn-default">重填</button--> | ||||
| @@ -49,53 +50,25 @@ | |||||
| function reset_station_setting() | function reset_station_setting() | ||||
| { | { | ||||
| event.preventDefault(); | event.preventDefault(); | ||||
| $.ajax | |||||
| ({ | |||||
| url: "<?=APP_URL?>station_setting_query", | |||||
| type: "post", | |||||
| dataType:"json", | |||||
| data:{ 'reload': 1 }, | |||||
| error:function(xhr, ajaxOptions, thrownError) | |||||
| { | |||||
| alertify_msg(xhr.responseText); | |||||
| console.log("error:"+xhr.responseText+"|"+ajaxOptions+"|"+thrownError); | |||||
| return false; | |||||
| }, | |||||
| success: function(jdata) | |||||
| { | |||||
| var station_service_url = jdata['station_ip'] + ' : ' + jdata['station_port']; | |||||
| var station_mqtt_url = jdata['mqtt_ip'] + ' : ' + jdata['mqtt_port']; | |||||
| if(jdata == 'fail') | |||||
| { | |||||
| $("#ss_station_name").val('未設定'); | |||||
| $("#ss_station_no").val(''); | |||||
| $("#ss_station_service_url").val(station_service_url); | |||||
| $("#ss_station_mqtt").val(station_mqtt_url); | |||||
| alertify_error('載入失敗。。'); | |||||
| return false; | |||||
| } | |||||
| $("#ss_station_name").val(jdata['station_name']); | |||||
| $("#ss_station_no").val(jdata['station_no']); | |||||
| $("#ss_station_service_url").val(station_service_url); | |||||
| $("#ss_station_mqtt").val(station_mqtt_url); | |||||
| alertify_success('完成。。'); | |||||
| } | |||||
| }); | |||||
| do_reload_station_setting(1); | |||||
| } | } | ||||
| // 載入目前設定 | // 載入目前設定 | ||||
| function reload_station_setting(type) | function reload_station_setting(type) | ||||
| { | { | ||||
| do_reload_station_setting(0); | |||||
| } | |||||
| // 執行 | |||||
| function do_reload_station_setting(reload=0) | |||||
| { | |||||
| $.ajax | $.ajax | ||||
| ({ | ({ | ||||
| url: "<?=APP_URL?>station_setting_query", | url: "<?=APP_URL?>station_setting_query", | ||||
| type: "post", | type: "post", | ||||
| dataType:"json", | dataType:"json", | ||||
| data:{ 'reload': 0 }, | |||||
| data:{ 'reload': reload }, | |||||
| error:function(xhr, ajaxOptions, thrownError) | error:function(xhr, ajaxOptions, thrownError) | ||||
| { | { | ||||
| alertify_msg(xhr.responseText); | alertify_msg(xhr.responseText); | ||||
| @@ -104,18 +77,23 @@ function reload_station_setting(type) | |||||
| }, | }, | ||||
| success: function(jdata) | success: function(jdata) | ||||
| { | { | ||||
| var station_service_url = jdata['station_ip'] + ' : ' + jdata['station_port']; | |||||
| var station_info = JSON.stringify(jdata['settings']); | |||||
| if(jdata == 'fail') | if(jdata == 'fail') | ||||
| { | { | ||||
| $("#ss_station_name").val('未設定'); | $("#ss_station_name").val('未設定'); | ||||
| $("#ss_station_no").val(''); | $("#ss_station_no").val(''); | ||||
| $("#ss_station_ip").val(jdata['station_ip']); | |||||
| $("#ss_station_service_url").val(station_service_url); | |||||
| $("#ss_station_info").val(station_info); | |||||
| alertify_error('載入失敗。。'); | alertify_error('載入失敗。。'); | ||||
| return false; | return false; | ||||
| } | } | ||||
| $("#ss_station_name").val(jdata['station_name']); | $("#ss_station_name").val(jdata['station_name']); | ||||
| $("#ss_station_no").val(jdata['station_no']); | $("#ss_station_no").val(jdata['station_no']); | ||||
| $("#ss_station_ip").val(jdata['station_ip']); | |||||
| $("#ss_station_service_url").val(station_service_url); | |||||
| $("#ss_station_info").val(station_info); | |||||
| alertify_success('完成。。'); | alertify_success('完成。。'); | ||||
| } | } | ||||
| }); | }); | ||||