增加对设备状态主动上报的逻辑支持

This commit is contained in:
anlicheng 2025-05-07 10:38:39 +08:00
parent b70a2a35d1
commit 43864341e6
3 changed files with 22 additions and 1 deletions

View File

@ -35,7 +35,9 @@
-define(METHOD_FEEDBACK_RESULT, 16#06).
-define(METHOD_EVENT, 16#07).
%% ai识别的事件上报
-define(METHOD_AI_EVENT, 17#08).
-define(METHOD_AI_EVENT, 16#08).
%%
-define(METHOD_DEVICE_REPORT, 16#09).
%%
-define(PACKET_REQUEST, 16#01).

View File

@ -403,6 +403,20 @@ handle_event(cast, {handle, {data, Data}}, ?STATE_ACTIVATED, State = #state{aes
end,
{keep_state, State};
handle_event(cast, {handle, {device_report, Report}}, ?STATE_ACTIVATED, State = #state{uuid = UUID, aes = AES, has_session = true}) ->
PlainReport = iot_cipher_aes:decrypt(AES, Report),
case catch jiffy:decode(PlainReport, [return_maps]) of
DeviceEdgeStatusList when is_list(DeviceEdgeStatusList) ->
lager:debug("[iot_host] host: ~p, update device edge_status num: ~p", [UUID, length(DeviceEdgeStatusList)]),
%%
lists:foreach(fun(#{<<"device_uuid">> := DeviceUUID, <<"edge_status">> := EdgeStatus}) ->
device_bo:change_edge_status(DeviceUUID, EdgeStatus)
end, DeviceEdgeStatusList);
Other ->
lager:notice("[iot_host] the device_report is invalid json: ~p", [Other])
end,
{keep_state, State};
%% ping的数据是通过aes加密后的
handle_event(cast, {handle, {ping, CipherMetric}}, ?STATE_ACTIVATED, State = #state{uuid = UUID, name = Name, aes = AES,
heartbeat_counter = HeartbeatCounter, has_session = true}) ->

View File

@ -126,6 +126,11 @@ websocket_handle({binary, <<?PACKET_REQUEST, _PacketId:32, ?METHOD_AI_EVENT:8, C
iot_host:handle(HostPid, {ai_event, CipherEvent}),
{ok, State};
%%
websocket_handle({binary, <<?PACKET_REQUEST, _PacketId:32, ?METHOD_DEVICE_REPORT:8, CipherReport/binary>>}, State = #state{host_pid = HostPid}) when is_pid(HostPid) ->
iot_host:handle(HostPid, {device_report, CipherReport}),
{ok, State};
%%
websocket_handle({binary, <<?PACKET_PUBLISH_RESPONSE, 0:32, Body/binary>>}, State = #state{uuid = UUID}) ->
lager:debug("[ws_channel] uuid: ~p, get send response message: ~p", [UUID, Body]),