|
@@ -94,10 +94,11 @@ $ws_worker->onWorkerStart = function($ws_worker)
|
|
|
foreach ($temp as $k => $v) {
|
|
|
var_dump($v['lamp_id']);
|
|
|
$client = $v['client'];
|
|
|
- $lamp = $websocketDB->query("select manu,address,id from lampinfo where id = ".$v['lamp_id']);
|
|
|
+ $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'])) {
|
|
@@ -111,18 +112,18 @@ $ws_worker->onWorkerStart = function($ws_worker)
|
|
|
$mqtt->publish($topick.$address, unpack('H*', $cmd));
|
|
|
|
|
|
$index = strtolower($address);
|
|
|
- $devUpdateList[$index] = array('client'=>$client,'lamp_id'=>$v['lamp_id'],'time'=>time(),'type'=>0,'step'=>0);
|
|
|
+ $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]];
|
|
|
+ $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]];
|
|
|
+ $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]];
|
|
|
+ $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]);
|
|
@@ -140,20 +141,20 @@ $ws_worker->onWorkerStart = function($ws_worker)
|
|
|
foreach ($temp as $k => $v) {
|
|
|
if ($v['type'] == 0) { // 升级指令还没返回
|
|
|
if (time() - $v['time'] > 10) { // 指令超时
|
|
|
- $data = ['code'=>'9999','status'=>2,'msg'=>'The command is timed out, please try again later','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2]];
|
|
|
+ $data = ['code'=>'9999','status'=>2,'msg'=>'The command is timed out, please try again later','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2,'number'=>$v['number']]];
|
|
|
unset($devUpdateList[$k]);
|
|
|
}
|
|
|
}elseif ($v['type'] == 1) { // 升级中
|
|
|
if (time() - $v['time'] > 60 * 5) { // 指令超时
|
|
|
- $data = ['code'=>'9999','status'=>2,'msg'=>'Please try again later. Please upgrade the device','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2]];
|
|
|
+ $data = ['code'=>'9999','status'=>2,'msg'=>'Please try again later. Please upgrade the device','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'status'=>2,'number'=>$v['number']]];
|
|
|
unset($devUpdateList[$k]);
|
|
|
}else{
|
|
|
if ($devUpdateList[$k]['step'] < 95) $devUpdateList[$k]['step'] += 1;
|
|
|
|
|
|
- $data = ['code'=>'0000','status'=>2,'msg'=>'Successful operation','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'step'=>$v['step'],'status'=>2]];
|
|
|
+ $data = ['code'=>'0000','status'=>2,'msg'=>'Successful operation','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'step'=>$v['step'],'status'=>2,'number'=>$v['number']]];
|
|
|
}
|
|
|
}elseif ($v['type'] == 2) { // 升级成功
|
|
|
- $data = ['code'=>'0000','status'=>2,'msg'=>'Successful operation','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'step'=>100,'status'=>2]];
|
|
|
+ $data = ['code'=>'0000','status'=>2,'msg'=>'Successful operation','data'=>['type'=>'updateDev','id'=>$v['lamp_id'],'step'=>100,'status'=>2,'number'=>$v['number']]];
|
|
|
unset($devUpdateList[$k]);
|
|
|
}
|
|
|
$v['client']->send(json_encode($data));
|