fix host mocker
This commit is contained in:
parent
0425030730
commit
0d5d5aa852
@ -230,9 +230,7 @@ handle_call(Info, _From, 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} ->
|
||||
|
||||
@ -28,14 +28,7 @@ start_link() ->
|
||||
init([]) ->
|
||||
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
|
||||
ChildSpecs = [
|
||||
#{
|
||||
id => 'iot_host_sup',
|
||||
start => {'iot_host_sup', start_link, []},
|
||||
restart => permanent,
|
||||
shutdown => 2000,
|
||||
type => supervisor,
|
||||
modules => ['iot_host_sup']
|
||||
},
|
||||
|
||||
|
||||
#{
|
||||
id => 'iot_mqtt_subscriber',
|
||||
@ -62,6 +55,15 @@ init([]) ->
|
||||
shutdown => 2000,
|
||||
type => worker,
|
||||
modules => ['iot_mqtt_publisher']
|
||||
},
|
||||
|
||||
#{
|
||||
id => 'iot_host_sup',
|
||||
start => {'iot_host_sup', start_link, []},
|
||||
restart => permanent,
|
||||
shutdown => 2000,
|
||||
type => supervisor,
|
||||
modules => ['iot_host_sup']
|
||||
}
|
||||
],
|
||||
{ok, {SupFlags, pools() ++ ChildSpecs}}.
|
||||
|
||||
@ -212,22 +212,26 @@ handle_info({publish, #{payload := Payload, qos := Qos, topic := FromTopic}},
|
||||
|
||||
{noreply, State};
|
||||
|
||||
#{<<"auth">> := false, <<"reply">> := #{<<"topic">> := Topic, <<"assoc">> := Assoc}} ->
|
||||
Msg = jiffy:encode(#{
|
||||
<<"code">> => 1,
|
||||
<<"message">> => "",
|
||||
<<"assoc">> => Assoc
|
||||
}, [force_utf8]),
|
||||
#{<<"auth">> := false, <<"reply">> := #{<<"topic">> := Topic, <<"assoc">> := Assoc}} ->
|
||||
Msg = jiffy:encode(#{
|
||||
<<"code">> => 1,
|
||||
<<"message">> => "",
|
||||
<<"assoc">> => Assoc
|
||||
}, [force_utf8]),
|
||||
|
||||
{ok, Ref} = iot_mqtt_publisher:publish(Topic, Msg, 1),
|
||||
receive
|
||||
{ok, Ref, PacketId} ->
|
||||
lager:debug("[host_mocker] send reply success, packet_id: ~p", [PacketId]);
|
||||
{error, Reason} ->
|
||||
lager:debug("[host_mocker] send reply failed, reason: ~p", [Reason])
|
||||
end,
|
||||
{ok, Ref} = iot_mqtt_publisher:publish(Topic, Msg, 1),
|
||||
receive
|
||||
{ok, Ref, PacketId} ->
|
||||
lager:debug("[host_mocker] send reply success, packet_id: ~p", [PacketId]);
|
||||
{error, Reason} ->
|
||||
lager:debug("[host_mocker] send reply failed, reason: ~p", [Reason])
|
||||
end,
|
||||
|
||||
{noreply, State#state{aes = <<>>}}
|
||||
{noreply, State#state{aes = <<>>}};
|
||||
#{<<"auth">> := false} ->
|
||||
self() ! create_session,
|
||||
|
||||
{noreply, State#state{aes = <<>>}}
|
||||
end;
|
||||
|
||||
%% 处理其他指令
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user