|
@@ -31,7 +31,7 @@ $ws_worker->onWorkerStart = function($ws_worker)
|
|
|
$mqtt->onConnect = function($mqtt) {
|
|
|
|
|
|
$room = array(
|
|
|
- // '/IDCOL/CmdInput/#' => 2,
|
|
|
+ '/IDCOL/CmdInput/#' => 2,
|
|
|
'/IDCOL/CmdOutput/#' => 2,
|
|
|
);
|
|
|
|
|
@@ -64,7 +64,58 @@ $ws_worker->onWorkerStart = function($ws_worker)
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
+ // 下发设备升级指令
|
|
|
+ Timer::add(1, function()use($mqtt){
|
|
|
+ // global $mqtt;
|
|
|
+ global $devUpdateList;
|
|
|
+ global $devList;
|
|
|
+ global $websocketDB;
|
|
|
+
|
|
|
+ $url = 'http://120.77.179.55';
|
|
|
+ $topick = '/IDCOL/CmdInput/';
|
|
|
+ $temp = $devList;
|
|
|
+ if (!empty($temp)) {
|
|
|
+ foreach ($temp as $k => $v) {
|
|
|
+ var_dump($v['lamp_id']);
|
|
|
+ $client = $v['client'];
|
|
|
+ $lamp = $websocketDB->query("select manu,address,id,number from lampinfo where id = ".$v['lamp_id']);
|
|
|
+ if (!empty($lamp) && !empty($lamp[0]['id'])) {
|
|
|
+ $manu = $lamp[0]['manu'];
|
|
|
+ $address = $lamp[0]['address'];
|
|
|
+ $number = $lamp[0]['number'];
|
|
|
+ if (!empty($manu)) {
|
|
|
+ $firmware_info = $websocketDB->query("select version,id,path from firmware_info where manuId = ".$manu);
|
|
|
+ if (!empty($firmware_info) && !empty($firmware_info[0]['id'])) {
|
|
|
+ $file_path = $url.$firmware_info[0]['path'];
|
|
|
+ $cmd = '190100010000000000';
|
|
|
+ for ($i=0; $i < 200; $i++) {
|
|
|
+ $file_path .= pack('H*','00');
|
|
|
+ }
|
|
|
+ $file_path = substr($file_path,0,200);
|
|
|
+ // $cmd .= $file_path;
|
|
|
+ $cmd = pack('H*', $cmd);
|
|
|
+ $crc = crc16($cmd.$file_path);
|
|
|
+ $mqtt->publish($topick.$address, $cmd.$file_path.pack('H*',$crc));
|
|
|
+
|
|
|
+ $index = strtolower($address);
|
|
|
+ $devUpdateList[$index] = array('client'=>$client,'lamp_id'=>$v['lamp_id'],'time'=>time(),'type'=>0,'step'=>0,'number'=>$number);
|
|
|
+ $websocketDB->update('lampinfo')->cols(array('is_update'=>1))->where('id='.$v['lamp_id']);
|
|
|
+ unset($devList[$k]);
|
|
|
+ continue;
|
|
|
+ }else{
|
|
|
+ $data = ['code'=>'9999','status'=>2,'msg'=>'No firmware file found, please contact your administrator','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2,'number'=>$number]];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $data = ['code'=>'9999','status'=>2,'msg'=>'Device not bound to manufacturer','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2,'number'=>$number]];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $data = ['code'=>'9999','status'=>2,'msg'=>'Device does not exist','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2,'number'=>'']];
|
|
|
+ }
|
|
|
+ $client->send(json_encode($data));
|
|
|
+ unset($devList[$k]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
};
|
|
|
$mqtt->connect();
|
|
|
|
|
@@ -82,58 +133,7 @@ $ws_worker->onWorkerStart = function($ws_worker)
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 下发设备升级指令
|
|
|
- Timer::add(1, function()use($ws_worker){
|
|
|
- global $mqtt;
|
|
|
- global $devUpdateList;
|
|
|
- global $devList;
|
|
|
- global $websocketDB;
|
|
|
-
|
|
|
- $url = 'http://120.77.179.55';
|
|
|
- $topick = '/IDCOL/CmdInput/';
|
|
|
- $temp = $devList;
|
|
|
- if (!empty($temp)) {
|
|
|
- foreach ($temp as $k => $v) {
|
|
|
- var_dump($v['lamp_id']);
|
|
|
- $client = $v['client'];
|
|
|
- $lamp = $websocketDB->query("select manu,address,id,number from lampinfo where id = ".$v['lamp_id']);
|
|
|
- if (!empty($lamp) && !empty($lamp[0]['id'])) {
|
|
|
- $manu = $lamp[0]['manu'];
|
|
|
- $address = $lamp[0]['address'];
|
|
|
- $number = $lamp[0]['number'];
|
|
|
- if (!empty($manu)) {
|
|
|
- $firmware_info = $websocketDB->query("select version,id,path from firmware_info where manuId = ".$manu);
|
|
|
- if (!empty($firmware_info) && !empty($firmware_info[0]['id'])) {
|
|
|
- $file_path = $url.$firmware_info[0]['path'];
|
|
|
- $cmd = '190100010000000000';
|
|
|
- for ($i=0; $i < 200; $i++) {
|
|
|
- $file_path .= pack('H*','00');
|
|
|
- }
|
|
|
- $file_path = substr($file_path,0,200);
|
|
|
- // $cmd .= $file_path;
|
|
|
- $cmd = pack('H*', $cmd);
|
|
|
- $crc = crc16($cmd.$file_path);
|
|
|
- $mqtt->publish($topick.$address, $cmd.$file_path.pack('H*',$crc));
|
|
|
-
|
|
|
- $index = strtolower($address);
|
|
|
- $devUpdateList[$index] = array('client'=>$client,'lamp_id'=>$v['lamp_id'],'time'=>time(),'type'=>0,'step'=>0,'number'=>$number);
|
|
|
- $websocketDB->update('lampinfo')->cols(array('is_update'=>1))->where('id='.$v['lamp_id']);
|
|
|
- unset($devList[$k]);
|
|
|
- continue;
|
|
|
- }else{
|
|
|
- $data = ['code'=>'9999','status'=>2,'msg'=>'No firmware file found, please contact your administrator','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2,'number'=>$number]];
|
|
|
- }
|
|
|
- }else{
|
|
|
- $data = ['code'=>'9999','status'=>2,'msg'=>'Device not bound to manufacturer','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2,'number'=>$number]];
|
|
|
- }
|
|
|
- }else{
|
|
|
- $data = ['code'=>'9999','status'=>2,'msg'=>'Device does not exist','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2,'number'=>'']];
|
|
|
- }
|
|
|
- $client->send(json_encode($data));
|
|
|
- unset($devList[$k]);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+
|
|
|
|
|
|
// 设备升级进度
|
|
|
Timer::add(2, function()use($ws_worker){
|