增加对设备状态主动上报的逻辑支持
This commit is contained in:
parent
b70a2a35d1
commit
43864341e6
@ -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).
|
||||
|
||||
@ -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}) ->
|
||||
|
||||
@ -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]),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user