fix mocker
This commit is contained in:
parent
42b3b8b2fa
commit
08fb916f77
@ -162,21 +162,7 @@ handle_info({publish, #{payload := Payload, qos := Qos, topic := FromTopic}},
|
||||
lager:debug("[host_mocker] get reply: ~p", [Json]),
|
||||
case Json of
|
||||
#{<<"code">> := 1, <<"message">> := <<"ok">>} ->
|
||||
%% 建立到iot的会话
|
||||
Req = jiffy:encode(#{
|
||||
<<"method">> => <<"create_session">>,
|
||||
<<"params">> => #{
|
||||
<<"pub_key">> => PubKey
|
||||
}
|
||||
}, [force_utf8]),
|
||||
|
||||
{ok, Ref} = iot_mqtt_publisher:publish(Topic, Req, 1),
|
||||
receive
|
||||
{ok, Ref, PacketId} ->
|
||||
lager:debug("[host_mocker] send create_session success, packet_id: ~p", [PacketId]);
|
||||
{error, Reason} ->
|
||||
lager:debug("[host_mocker] send create_session failed, reason: ~p", [Reason])
|
||||
end;
|
||||
self() ! create_session;
|
||||
Info ->
|
||||
Info
|
||||
end,
|
||||
@ -218,6 +204,8 @@ handle_info({publish, #{payload := Payload, qos := Qos, topic := FromTopic}},
|
||||
lager:debug("[host_mocker] send reply failed, reason: ~p", [Reason])
|
||||
end,
|
||||
|
||||
self() ! create_session,
|
||||
|
||||
{noreply, State};
|
||||
|
||||
#{<<"auth">> := false, <<"reply">> := #{<<"topic">> := Topic, <<"assoc">> := Assoc}} ->
|
||||
@ -252,9 +240,26 @@ handle_info({puback, Packet = #{packet_id := _PacketId}}, State = #state{}) ->
|
||||
lager:debug("[iot_mqtt_subscriber] receive puback packet: ~p", [Packet]),
|
||||
{noreply, State};
|
||||
|
||||
%% 建立到iot的会话
|
||||
handle_info(create_session, State = #state{topic = Topic, pub_key = PubKey}) ->
|
||||
Req = jiffy:encode(#{
|
||||
<<"method">> => <<"create_session">>,
|
||||
<<"params">> => #{
|
||||
<<"pub_key">> => PubKey
|
||||
}
|
||||
}, [force_utf8]),
|
||||
|
||||
{ok, Ref} = iot_mqtt_publisher:publish(Topic, Req, 1),
|
||||
receive
|
||||
{ok, Ref, PacketId} ->
|
||||
lager:debug("[host_mocker] send create_session success, packet_id: ~p", [PacketId]);
|
||||
{error, Reason} ->
|
||||
lager:debug("[host_mocker] send create_session failed, reason: ~p", [Reason])
|
||||
end,
|
||||
{noreply, State};
|
||||
|
||||
%% 周期数据上传逻辑
|
||||
handle_info({timeout, _, data_ticker}, State = #state{aes = Aes, topic = Topic}) ->
|
||||
|
||||
InfoList = [
|
||||
#{
|
||||
<<"service_name">> => <<"shuibiao">>,
|
||||
@ -417,7 +422,7 @@ code_change(_OldVsn, State = #state{}, _Extra) ->
|
||||
%%% Internal functions
|
||||
%%%===================================================================
|
||||
|
||||
handle_command(8, Info, State) ->
|
||||
lager:debug("[host_mocker] command is: ~p", [Info]),
|
||||
handle_command(Type, Info, State) ->
|
||||
lager:debug("[host_mocker] command type: ~p, is: ~p", [Type, Info]),
|
||||
State.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user