fix
This commit is contained in:
parent
98501ad6c5
commit
0425030730
@ -141,6 +141,8 @@ init([UUID]) ->
|
||||
%% 启动心跳定时器
|
||||
erlang:start_timer(?TICKER_INTERVAL, self(), ping_ticker),
|
||||
Aes = list_to_binary(iot_util:rand_bytes(32)),
|
||||
%% 告知主机端需要重新授权
|
||||
gen_server:cast(self(), need_auth),
|
||||
|
||||
{ok, #state{host_id = HostId, uuid = UUID, aes = Aes, is_activated = (Status /= ?HOST_STATUS_INACTIVE), status = Status, has_session = false}};
|
||||
undefined ->
|
||||
@ -227,6 +229,18 @@ handle_call(Info, _From, State) ->
|
||||
{noreply, NewState :: #state{}} |
|
||||
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
||||
{stop, Reason :: term(), NewState :: #state{}}).
|
||||
handle_cast(need_auth, State = #state{uuid = UUID}) ->
|
||||
lager:debug("[iot_host] host_id uuid: ~p, create_session", [UUID]),
|
||||
Reply = jiffy:encode(#{<<"a">> => false, <<"aes">> => <<"">>}, [force_utf8]),
|
||||
|
||||
{ok, Ref} = iot_mqtt_publisher:publish(downstream_topic(UUID), <<8:8, Reply/binary>>, 1),
|
||||
receive
|
||||
{ok, Ref, PacketId} ->
|
||||
lager:debug("[iot_host] host_id uuid: ~p, packet_id: ~p, publish need_auth reply success", [UUID, PacketId])
|
||||
after 5000 ->
|
||||
lager:debug("[iot_host] host_id uuid: ~p, publish need_auth reply get error is: timeout", [UUID])
|
||||
end,
|
||||
{noreply, State};
|
||||
handle_cast({handle, Payload}, State) ->
|
||||
%% 处理消息
|
||||
NState = handle_message(Payload, State),
|
||||
@ -396,6 +410,7 @@ handle_message(Msg = #{<<"code">> := _Code, <<"assoc">> := Assoc}, State = #stat
|
||||
end;
|
||||
|
||||
handle_message(Message, State = #state{uuid = UUID, has_session = HasSession}) ->
|
||||
not HasSession andalso gen_server:cast(self(), need_auth),
|
||||
lager:warning("[iot_host] host_id uuid: ~p, get a unknown message: ~p, session: ~p", [UUID, Message, HasSession]),
|
||||
State.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user