This commit is contained in:
anlicheng 2023-08-09 17:51:58 +08:00
parent dc7aa27e4e
commit 16882a038e

View File

@ -144,24 +144,19 @@ handle_request("POST", "/host/activate", _, #{<<"uuid">> := UUID, <<"auth">> :=
{ok, 200, iot_util:json_error(400, <<"host not found">>)};
{ok, Pid} when is_pid(Pid) ->
ok = iot_host:activate(Pid, false),
%%
case iot_host:has_session(Pid) of
true ->
lager:debug("[host_handler] activate host_id: ~p, start", [UUID]),
BinReply = jiffy:encode(#{<<"auth">> => false}, [force_utf8]),
case iot_host:publish_message(Pid, 8, BinReply) of
{ok, Ref} ->
receive
{response, Ref, Response} ->
lager:debug("[iot_host_handler] host_id uuid: ~p, publish topic success, get response: ~p", [Response])
after Timeout * 1000 ->
lager:debug("[iot_host_handler] host_id uuid: ~p, publish topic success, but get ack timeout", [UUID])
end;
{error, Reason} ->
lager:debug("[iot_host] host_id uuid: ~p, publish command get error: ~p", [UUID, Reason])
lager:debug("[host_handler] activate host_id: ~p, start", [UUID]),
BinReply = jiffy:encode(#{<<"auth">> => false}, [force_utf8]),
case iot_host:publish_message(Pid, 8, BinReply) of
{ok, Ref} ->
receive
{response, Ref, Response} ->
lager:debug("[iot_host_handler] host_id uuid: ~p, publish topic success, get response: ~p", [Response])
after Timeout * 1000 ->
lager:debug("[iot_host_handler] host_id uuid: ~p, publish topic success, but get ack timeout", [UUID])
end;
false ->
ok
{error, Reason} ->
lager:debug("[iot_host] host_id uuid: ~p, publish command get error: ~p", [UUID, Reason])
end,
{ok, 200, iot_util:json_data(<<"success">>)}
end;