fix device

This commit is contained in:
anlicheng 2023-08-15 23:20:02 +08:00
parent 30c0d6c198
commit 5cc6665a3d

View File

@ -415,16 +415,22 @@ handle_event(info, {'EXIT', Pid, Reason}, StateName, State = #state{uuid = UUID,
false -> false ->
{keep_state, State}; {keep_state, State};
{value, {DeviceUUID, _}} -> {value, {DeviceUUID, _}} ->
%%
erlang:start_timer(5000, self(), {restart_device, DeviceUUID}),
{keep_state, State#state{device_map = maps:remove(DeviceUUID, DeviceMap)}}
end;
handle_event(info, {timeout, _, {restart_device, DeviceUUID}}, _, State = #state{uuid = UUID, device_map = DeviceMap}) ->
%% device进程不一定能成功 %% device进程不一定能成功
case iot_device:start_link(self(), DeviceUUID) of case catch iot_device:start_link(self(), DeviceUUID) of
{ok, DevicePid} -> {ok, DevicePid} ->
lager:debug("[iot_host] uuid: ~p, restart device: ~p, success", [UUID, DeviceUUID]),
%% DeviceUUID %% DeviceUUID
NDeviceMap = maps:put(DeviceUUID, DevicePid, DeviceMap), NDeviceMap = maps:put(DeviceUUID, DevicePid, DeviceMap),
{keep_state, State#state{device_map = NDeviceMap}}; {keep_state, State#state{device_map = NDeviceMap}};
Error -> Error ->
lager:warning("[iot_host] uuid: ~p, restart device: ~p, get error: ~p", [UUID, DeviceUUID, Error]), lager:warning("[iot_host] uuid: ~p, restart device: ~p, get error: ~p", [UUID, DeviceUUID, Error]),
{keep_state, State} {keep_state, State}
end
end; end;
handle_event(EventType, EventContent, StateName, State) -> handle_event(EventType, EventContent, StateName, State) ->