|
@@ -725,79 +725,50 @@ class Project extends Base_Controller {
|
|
|
}
|
|
|
|
|
|
// 巡检设置
|
|
|
- public function patrol() {
|
|
|
+ public function patrol(){
|
|
|
+ $username = $this->input->post('username',true);
|
|
|
+ $role = $this->input->post('role',true);
|
|
|
+ $client_key = $this->input->post('client_key',true);
|
|
|
+ $token = $this->input->post('token',true);
|
|
|
+ $clientid = $this->input->post('clientid',true);
|
|
|
+ $version = $this->session->userdata('version');
|
|
|
|
|
|
- $role = $this->get_user_info('role');
|
|
|
- // if ($role == COMPANY_CUSTOMER) {
|
|
|
- // exit(json_result('0011', $this->response['0011'], array()));
|
|
|
+ $lampid = intval($this->input->post('lampid', true));
|
|
|
+ $interval = $this->input->post('interval',true);
|
|
|
+
|
|
|
+ $lampArr = explode(',', $lamp_id);
|
|
|
+
|
|
|
+ // $lampList = $this->Lamp_model->get_list_in('L.id', $lampArr, 'L.id,N.protocoltype', array());
|
|
|
+ $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/project/patrol_asy';
|
|
|
+
|
|
|
+ // foreach ($lampArr as $l) {
|
|
|
+ doAsyncRequest($url,['clientid'=>$clientid,'lampid'=>$lampid,'interval'=>$interval,'username'=>$username,'client_key'=>$client_key,'token'=>$token,'version'=>$version,'role'=>$role]);
|
|
|
// }
|
|
|
+
|
|
|
+ exit();
|
|
|
+ }
|
|
|
+ public function patrol_asy() {
|
|
|
|
|
|
- $type = $this->input->post('type', true);
|
|
|
- $value = $this->input->post('value', true);
|
|
|
- $switch = $this->input->post('switch',true);
|
|
|
+ $lampid = intval($this->input->post('lampid', true));
|
|
|
$interval = $this->input->post('interval',true);
|
|
|
|
|
|
- if(!in_array($type, array('project','network','lamp')) || empty($interval) || empty($value)) {
|
|
|
- exit(json_result('0005', $this->response['0005'], array()));
|
|
|
- }
|
|
|
+ if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
|
|
|
|
|
|
- $nowtime = time();
|
|
|
- $data['patroltype'] = intval($switch);
|
|
|
- $data['patrolinterval'] = intval($interval);
|
|
|
- $data['updatetime'] = date("Y-m-d H:i:s", $nowtime);
|
|
|
- $data['nextquerytime'] = date("Y-m-d H:i:s", time());
|
|
|
- if ($type == 'project') {
|
|
|
- $idArr = $this->Lamp_model->getLampIds(array('project'=>$value));
|
|
|
- }elseif ($type == 'network') {
|
|
|
- $idArr = $this->Lamp_model->getLampIds(array('network'=>$value));
|
|
|
- }else{
|
|
|
+ $lampData = $this->Lamp_model->get_one(['id'=>$lampid],'address');
|
|
|
+ $address = substr($lampData['address'], 2);
|
|
|
|
|
|
- $id = $value;
|
|
|
- $ret = $this->Patrol_model->getOne($id);
|
|
|
- if(empty($ret)){
|
|
|
- $data['id'] = $id;
|
|
|
- $this->Patrol_model->insert($data);
|
|
|
- } else {
|
|
|
- $this->Patrol_model->update(array('id'=>$id), $data);
|
|
|
- }
|
|
|
- $res = $this->Lamp_model->getOne($id,'N.protocoltype,L.address,L.protocoltype as lampprotocoltype');
|
|
|
- if ($res['protocoltype'] == 4) {
|
|
|
- $sendData = '000101A501';;
|
|
|
- $sendData .= bitSubStr(base_convert(intval($interval/5), 10, 16));
|
|
|
- lampMqttCmd('/lamp/WriteIn/'.$res['address'],'/lamp/WriteOut/'.$res['address'],pack('H*', $sendData),0);
|
|
|
- }else{
|
|
|
- if (isset($res['protocoltype']) && $res['protocoltype'] != 0) {
|
|
|
- $cmd = '{"cmd_type":"set_patrol_cmd","cmd_id":'.$id.',"broadcast":0}';
|
|
|
- $cmdret = send_cmd($cmd,1,0,$res['protocoltype']);
|
|
|
- // if (empty($cmdret)) exit(json_result('0016',$this->response['0016'], array('number'=>$lampData['number'])));
|
|
|
- // if($cmdret === false){
|
|
|
- // exit(json_result('0008', $this->response['0008']));
|
|
|
- // } else {
|
|
|
- // $res = json_decode($cmdret, true);
|
|
|
- // }
|
|
|
-
|
|
|
- // if (isset($res['result']) && $res['result'] == true) {
|
|
|
- // exit(json_result('0000', $this->response['0000']));
|
|
|
- // } else {
|
|
|
- // $version = $this->session->userdata('version');
|
|
|
- // if (empty($version)) {
|
|
|
- // $res['msg'] = empty($res['msg']) ? '未知错误' : transfer_error_tips($res['msg']);
|
|
|
- // exit(json_result('0010', $res['msg']));
|
|
|
- // }else{
|
|
|
- // $res['msg'] = empty($res['msg']) ? 'Unknown error' : $res['msg'];
|
|
|
- // exit(json_result('other', $res['msg']));
|
|
|
- // }
|
|
|
- // }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if (!empty($idArr)) {
|
|
|
- foreach ($idArr as $id) {
|
|
|
- $this->do_setting($id, $data);
|
|
|
- }
|
|
|
+ $sendData = '000A';
|
|
|
+ $interval = base_convert($interval, 10, 16);
|
|
|
+ $sendData .= substr('0000'.$interval, -4);
|
|
|
+
|
|
|
+ $res = $this->send_cmd('16',$address,$senddata);
|
|
|
+ if (empty($res)) {
|
|
|
+ exit(json_result('0016',$this->response['0016']));
|
|
|
+ }else{
|
|
|
+ $res = unpack('H*', $res['msg'])[1];
|
|
|
+ if (substr($res, 18,2) != '01') exit(json_result('0010',$this->response['0010']));
|
|
|
}
|
|
|
+
|
|
|
exit(json_result('0000', $this->response['0000'], array()));
|
|
|
}
|
|
|
|