This commit is contained in:
chenbo 2024-02-22 16:32:03 +08:00
parent c92d3c7e64
commit 3b356f0617
1 changed files with 20 additions and 8 deletions

View File

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