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} |
|
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
{stop, Reason :: term(), NewState :: #state{}}).
|
||||||
handle_cast(need_auth, State = #state{uuid = UUID}) ->
|
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]),
|
Reply = jiffy:encode(#{<<"a">> => false, <<"aes">> => <<"">>}, [force_utf8]),
|
||||||
|
|
||||||
{ok, Ref} = iot_mqtt_publisher:publish(downstream_topic(UUID), <<8:8, Reply/binary>>, 1),
|
{ok, Ref} = iot_mqtt_publisher:publish(downstream_topic(UUID), <<8:8, Reply/binary>>, 1),
|
||||||
receive
|
receive
|
||||||
{ok, Ref, PacketId} ->
|
{ok, Ref, PacketId} ->
|
||||||
|
|||||||
@ -28,14 +28,7 @@ start_link() ->
|
|||||||
init([]) ->
|
init([]) ->
|
||||||
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
|
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
|
||||||
ChildSpecs = [
|
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',
|
id => 'iot_mqtt_subscriber',
|
||||||
@ -62,6 +55,15 @@ init([]) ->
|
|||||||
shutdown => 2000,
|
shutdown => 2000,
|
||||||
type => worker,
|
type => worker,
|
||||||
modules => ['iot_mqtt_publisher']
|
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}}.
|
{ok, {SupFlags, pools() ++ ChildSpecs}}.
|
||||||
|
|||||||
@ -212,22 +212,26 @@ handle_info({publish, #{payload := Payload, qos := Qos, topic := FromTopic}},
|
|||||||
|
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|
||||||
#{<<"auth">> := false, <<"reply">> := #{<<"topic">> := Topic, <<"assoc">> := Assoc}} ->
|
#{<<"auth">> := false, <<"reply">> := #{<<"topic">> := Topic, <<"assoc">> := Assoc}} ->
|
||||||
Msg = jiffy:encode(#{
|
Msg = jiffy:encode(#{
|
||||||
<<"code">> => 1,
|
<<"code">> => 1,
|
||||||
<<"message">> => "",
|
<<"message">> => "",
|
||||||
<<"assoc">> => Assoc
|
<<"assoc">> => Assoc
|
||||||
}, [force_utf8]),
|
}, [force_utf8]),
|
||||||
|
|
||||||
{ok, Ref} = iot_mqtt_publisher:publish(Topic, Msg, 1),
|
{ok, Ref} = iot_mqtt_publisher:publish(Topic, Msg, 1),
|
||||||
receive
|
receive
|
||||||
{ok, Ref, PacketId} ->
|
{ok, Ref, PacketId} ->
|
||||||
lager:debug("[host_mocker] send reply success, packet_id: ~p", [PacketId]);
|
lager:debug("[host_mocker] send reply success, packet_id: ~p", [PacketId]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:debug("[host_mocker] send reply failed, reason: ~p", [Reason])
|
lager:debug("[host_mocker] send reply failed, reason: ~p", [Reason])
|
||||||
end,
|
end,
|
||||||
|
|
||||||
{noreply, State#state{aes = <<>>}}
|
{noreply, State#state{aes = <<>>}};
|
||||||
|
#{<<"auth">> := false} ->
|
||||||
|
self() ! create_session,
|
||||||
|
|
||||||
|
{noreply, State#state{aes = <<>>}}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
%% 处理其他指令
|
%% 处理其他指令
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user