fixed
This commit is contained in:
parent
c92d3c7e64
commit
3b356f0617
|
@ -26,6 +26,10 @@ class DataCollectController extends BaseApiController
|
|||
if(!$parmas || !isset($parmas['username']) || $parmas['username']==''){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
|
||||
// mqtt服务端 消息发布事件
|
||||
if ($parmas['event'] == 'message.publish') {
|
||||
$payload= json_decode($parmas['payload'], true);
|
||||
$user = User::where('account', $parmas['username'])->find();
|
||||
|
||||
$device = explode('_', $parmas['topic']); // 命名规则:camera_deviceid deviceid为设备主键id
|
||||
|
@ -34,10 +38,6 @@ class DataCollectController extends BaseApiController
|
|||
$productDevice = ProductDevice::where('device_id', $deviceId)->find();
|
||||
$landProduct = LandProduct::where('product_id', $productDevice['product_id'])->find();
|
||||
$landId = $landProduct['land_id']; // 土地id
|
||||
|
||||
// mqtt服务端 消息发布事件
|
||||
if ($parmas['event'] == 'message.publish') {
|
||||
$payload= json_decode($parmas['payload'], true);
|
||||
$data = [
|
||||
'user_id' => $user['id'],
|
||||
'land_id' => $landId,
|
||||
|
@ -176,7 +176,15 @@ class DataCollectController extends BaseApiController
|
|||
|
||||
// mqtt服务端 连接断开事件 客户端断开表示该土块的所有设备都已断开 共用同一个mqtt客户端
|
||||
if ($parmas['event'] == 'client.disconnected') {
|
||||
// lihai_lot_walnutpi_dev_6 clientid 命名规则
|
||||
|
||||
$device = strstr($parmas['clientid'], 'dev_');
|
||||
$device = explode('_', $device);
|
||||
$deviceId = $device[1]; // 设备id
|
||||
|
||||
$productDevice = ProductDevice::where('device_id', $deviceId)->find();
|
||||
$landProduct = LandProduct::where('product_id', $productDevice['product_id'])->find();
|
||||
$landId = $landProduct['land_id']; // 土地id
|
||||
// 查询该土地关联的设备
|
||||
$addData = [
|
||||
'land_id' => $landId,
|
||||
|
@ -192,6 +200,10 @@ class DataCollectController extends BaseApiController
|
|||
}
|
||||
// 连接链接事件 设备已上线
|
||||
if ($parmas['event'] == 'client.connected') {
|
||||
// lihai_lot_walnutpi_dev_6 clientid 命名规则
|
||||
$device = strstr($parmas['clientid'], 'dev_');
|
||||
$device = explode('_', $device);
|
||||
$deviceId = $device[1]; // 设备id
|
||||
Device::where('id', $deviceId)->update(['is_online' => 1]);
|
||||
return $this->success('接收成功');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue