add debug
This commit is contained in:
parent
7cabbb8757
commit
c405ba7d6d
@ -104,6 +104,7 @@ handle_cast({send_command, Ref, ReceiverPid, DeviceId, Command}, State = #state{
|
|||||||
|
|
||||||
NCommand = jiffy:encode(Command#{<<"sessionid">> => SessionId}, [force_utf8]),
|
NCommand = jiffy:encode(Command#{<<"sessionid">> => SessionId}, [force_utf8]),
|
||||||
iot_mqtt_connection:publish_msg(ConnPid, Topic, NCommand, 2),
|
iot_mqtt_connection:publish_msg(ConnPid, Topic, NCommand, 2),
|
||||||
|
lager:debug("[iot_mqtt_aircon_gateway] publish message, topic: ~p, message: ~ts", [Topic, NCommand]),
|
||||||
|
|
||||||
NInflight = maps:put({DeviceId, SessionId}, {Ref, ReceiverPid}, Inflight),
|
NInflight = maps:put({DeviceId, SessionId}, {Ref, ReceiverPid}, Inflight),
|
||||||
{noreply, State#state{inflight = NInflight}}.
|
{noreply, State#state{inflight = NInflight}}.
|
||||||
@ -115,6 +116,7 @@ handle_cast({send_command, Ref, ReceiverPid, DeviceId, Command}, State = #state{
|
|||||||
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
{stop, Reason :: term(), NewState :: #state{}}).
|
||||||
handle_info({mqtt_message, Topic, Payload, _Qos}, State = #state{inflight = Inflight}) ->
|
handle_info({mqtt_message, Topic, Payload, _Qos}, State = #state{inflight = Inflight}) ->
|
||||||
|
lager:debug("[iot_mqtt_aircon_gateway] get reply of topic: ~p, payload: ~p", [Topic, Payload]),
|
||||||
case binary:split(Topic, <<"/">>) of
|
case binary:split(Topic, <<"/">>) of
|
||||||
[<<>>, <<"aircon">>, DeviceId, <<"command_reply">>] ->
|
[<<>>, <<"aircon">>, DeviceId, <<"command_reply">>] ->
|
||||||
Reply = catch jiffy:decode(Payload, [return_maps]),
|
Reply = catch jiffy:decode(Payload, [return_maps]),
|
||||||
@ -122,12 +124,14 @@ handle_info({mqtt_message, Topic, Payload, _Qos}, State = #state{inflight = Infl
|
|||||||
#{<<"sessionid">> := SessionId} ->
|
#{<<"sessionid">> := SessionId} ->
|
||||||
case maps:take({DeviceId, SessionId}, Inflight) of
|
case maps:take({DeviceId, SessionId}, Inflight) of
|
||||||
error ->
|
error ->
|
||||||
|
lager:debug("[iot_mqtt_aircon_gateway] not find in inflight"),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
{{Ref, ReceiverPid}, NInflight} ->
|
{{Ref, ReceiverPid}, NInflight} ->
|
||||||
case is_pid(ReceiverPid) andalso is_process_alive(ReceiverPid) of
|
case is_pid(ReceiverPid) andalso is_process_alive(ReceiverPid) of
|
||||||
true ->
|
true ->
|
||||||
ReceiverPid ! {send_command_reply, Ref, Reply};
|
ReceiverPid ! {send_command_reply, Ref, Reply};
|
||||||
false ->
|
false ->
|
||||||
|
lager:debug("[iot_mqtt_aircon_gateway] reveiver is dead"),
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
{noreply, State#state{inflight = NInflight}}
|
{noreply, State#state{inflight = NInflight}}
|
||||||
@ -136,7 +140,7 @@ handle_info({mqtt_message, Topic, Payload, _Qos}, State = #state{inflight = Infl
|
|||||||
{noreply, State}
|
{noreply, State}
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
lager:notice("[~p] get a invalid topic: ~p, message: ~p", [?MODULE, Topic, Payload]),
|
lager:notice("[iot_mqtt_aircon_gateway] get a invalid topic: ~p, message: ~p", [Topic, Payload]),
|
||||||
{noreply, State}
|
{noreply, State}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user