This commit is contained in:
anlicheng 2025-05-07 22:12:51 +08:00
parent 740e35833b
commit 04254def4b

View File

@ -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}) %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 /= <<>> -> % when is_binary(DeviceUUID), DeviceUUID /= <<>> ->
%
case iot_device:get_pid(DeviceUUID) of % case maps:find(DeviceUUID, DeviceMap) of
undefined -> %
lager:warning("[iot_host] host uuid: ~p, device uuid: ~p not found, fields: ~p, tags: ~p", [UUID, DeviceUUID, FieldsList, Tags]), % end,
ok; %
DevicePid when is_pid(DevicePid) -> %
case iot_device:is_activated(DevicePid) of % case iot_device:get_pid(DeviceUUID) of
true -> % undefined ->
%% % lager:warning("[iot_host] host uuid: ~p, device uuid: ~p not found, fields: ~p, tags: ~p", [UUID, DeviceUUID, FieldsList, Tags]),
iot_router:route_uuid(DeviceUUID, FieldsList, Timestamp), % ok;
% DevicePid when is_pid(DevicePid) ->
%% influxdb % case iot_device:is_activated(DevicePid) of
NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName, <<"device_uuid">> => DeviceUUID}, % true ->
influx_client:write_data(DeviceUUID, NTags, FieldsList, Timestamp), % %%
% iot_router:route_uuid(DeviceUUID, FieldsList, Timestamp),
iot_device:change_status(DevicePid, ?DEVICE_ONLINE); %
false -> % %% influxdb
lager:warning("[iot_host] host uuid: ~p, device_uuid: ~p not activated, fields: ~p, tags: ~p", [UUID, DeviceUUID, FieldsList, Tags]) % NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName, <<"device_uuid">> => DeviceUUID},
end % influx_client:write_data(DeviceUUID, NTags, FieldsList, Timestamp),
end; %
% iot_device:change_status(DevicePid, ?DEVICE_ONLINE);
handle_data(#data{service_name = ServiceName, at = Timestamp, fields = FieldsList, tags = Tags}, #state{uuid = UUID}) -> % false ->
%% % lager:warning("[iot_host] host uuid: ~p, device_uuid: ~p not activated, fields: ~p, tags: ~p", [UUID, DeviceUUID, FieldsList, Tags])
iot_router:route_uuid(UUID, FieldsList, Timestamp), % end
% end;
%% influxdb %
NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName}, %handle_data(#data{service_name = ServiceName, at = Timestamp, fields = FieldsList, tags = Tags}, #state{uuid = UUID}) ->
influx_client:write_data(UUID, NTags, FieldsList, Timestamp). % %%
% 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(). -spec report_event(UUID :: binary(), NewStatus :: integer()) -> no_return().
report_event(UUID, NewStatus) when is_binary(UUID), is_integer(NewStatus) -> report_event(UUID, NewStatus) when is_binary(UUID), is_integer(NewStatus) ->