From 04254def4bdfe869b4b89f3535b75a73860a2dbd Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Wed, 7 May 2025 22:12:51 +0800 Subject: [PATCH] fix host --- apps/iot/src/iot_host.erl | 65 +++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index 9c31a80..c13242d 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -418,36 +418,41 @@ code_change(_OldVsn, StateName, State = #state{}, _Extra) -> %%%=================================================================== %% 处理相关数据 -handle_data(#data{device_uuid = DeviceUUID, service_name = ServiceName, at = Timestamp, fields = FieldsList, tags = Tags}, #state{uuid = UUID}) - when is_binary(DeviceUUID), DeviceUUID /= <<>> -> - - case iot_device:get_pid(DeviceUUID) of - undefined -> - lager:warning("[iot_host] host uuid: ~p, device uuid: ~p not found, fields: ~p, tags: ~p", [UUID, DeviceUUID, FieldsList, Tags]), - ok; - DevicePid when is_pid(DevicePid) -> - case iot_device:is_activated(DevicePid) of - true -> - %% 查找终端设备对应的点位信息 - iot_router:route_uuid(DeviceUUID, FieldsList, Timestamp), - - %% 数据写入influxdb - NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName, <<"device_uuid">> => DeviceUUID}, - influx_client:write_data(DeviceUUID, NTags, FieldsList, Timestamp), - - iot_device:change_status(DevicePid, ?DEVICE_ONLINE); - false -> - lager:warning("[iot_host] host uuid: ~p, device_uuid: ~p not activated, fields: ~p, tags: ~p", [UUID, DeviceUUID, FieldsList, Tags]) - end - end; - -handle_data(#data{service_name = ServiceName, at = Timestamp, fields = FieldsList, tags = Tags}, #state{uuid = UUID}) -> - %% 查找终端设备对应的点位信息 - iot_router:route_uuid(UUID, FieldsList, Timestamp), - - %% 数据写入influxdb - NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName}, - influx_client:write_data(UUID, NTags, FieldsList, Timestamp). +%handle_data(#data{device_uuid = DeviceUUID, service_name = ServiceName, at = Timestamp, fields = FieldsList, tags = Tags}, #state{uuid = UUID, device_map = DeviceMap}) +% when is_binary(DeviceUUID), DeviceUUID /= <<>> -> +% +% case maps:find(DeviceUUID, DeviceMap) of +% +% end, +% +% +% case iot_device:get_pid(DeviceUUID) of +% undefined -> +% lager:warning("[iot_host] host uuid: ~p, device uuid: ~p not found, fields: ~p, tags: ~p", [UUID, DeviceUUID, FieldsList, Tags]), +% ok; +% DevicePid when is_pid(DevicePid) -> +% case iot_device:is_activated(DevicePid) of +% true -> +% %% 查找终端设备对应的点位信息 +% iot_router:route_uuid(DeviceUUID, FieldsList, Timestamp), +% +% %% 数据写入influxdb +% NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName, <<"device_uuid">> => DeviceUUID}, +% influx_client:write_data(DeviceUUID, NTags, FieldsList, Timestamp), +% +% iot_device:change_status(DevicePid, ?DEVICE_ONLINE); +% false -> +% lager:warning("[iot_host] host uuid: ~p, device_uuid: ~p not activated, fields: ~p, tags: ~p", [UUID, DeviceUUID, FieldsList, Tags]) +% end +% end; +% +%handle_data(#data{service_name = ServiceName, at = Timestamp, fields = FieldsList, tags = Tags}, #state{uuid = UUID}) -> +% %% 查找终端设备对应的点位信息 +% iot_router:route_uuid(UUID, FieldsList, Timestamp), +% +% %% 数据写入influxdb +% NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName}, +% influx_client:write_data(UUID, NTags, FieldsList, Timestamp). -spec report_event(UUID :: binary(), NewStatus :: integer()) -> no_return(). report_event(UUID, NewStatus) when is_binary(UUID), is_integer(NewStatus) ->