From eea16209ef6fabb41280c90b0e6587694c49b77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E7=A4=BC=E6=88=90?= Date: Fri, 31 Mar 2023 19:37:57 +0800 Subject: [PATCH] fix --- apps/iot/src/iot_host.erl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index bf77e64..b709e37 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -13,6 +13,7 @@ -behaviour(gen_server). %% API +-export([test/1]). -export([start_link/2, get_name/1, get_pid/1, publish/4]). %% gen_server callbacks @@ -26,6 +27,10 @@ is_connected = false :: boolean() }). +test(Id) when is_binary(Id) -> + Pid = get_pid(<<"1">>), + publish(Pid, <<"/host/", Id/binary>>, <<"hello world">>, 1). + %%%=================================================================== %%% API %%%=================================================================== @@ -124,6 +129,17 @@ handle_cast(_Request, State = #state{}) -> {noreply, NewState :: #state{}} | {noreply, NewState :: #state{}, timeout() | hibernate} | {stop, Reason :: term(), NewState :: #state{}}). +handle_info({disconnect, ReasonCode, Properties}, State = #state{host = #host{host_id = HostId}}) -> + lager:debug("[iot_host] host: ~p, Recv a DISONNECT packet - ReasonCode: ~p, Properties: ~p", [HostId, ReasonCode, Properties]), + {stop, disconnected, State}; +handle_info({publish, Message = #{packet_id := PacketId, payload := Payload}}, State = #state{emqx_pid = ConnPid, host = #host{host_id = HostId}}) -> + lager:debug("[iot_host] host: ~p, Recv a publish packet: ~p, payload: ~p", [HostId, Message, Payload]), + % emqtt:pubrec(ConnPid, PacketId), + {noreply, State}; +handle_info({puback, #{packet_id := PacketId, reason_code := ReasonCode}}, State = #state{host = #host{host_id = HostId}}) -> + lager:debug("[iot_host] host: ~p, receive puback packet_id: ~p, reason_code: ~p", [HostId, PacketId, ReasonCode]), + {noreply, State}; + handle_info(Info, State = #state{host = #host{host_id = HostId}}) -> lager:debug("host_id: ~p, get info: ~p", [HostId, Info]), {noreply, State}.