diff --git a/apps/emqx_gateway_lwm2m/src/emqx_lwm2m_channel.erl b/apps/emqx_gateway_lwm2m/src/emqx_lwm2m_channel.erl index 77652744a..bbd2d4377 100644 --- a/apps/emqx_gateway_lwm2m/src/emqx_lwm2m_channel.erl +++ b/apps/emqx_gateway_lwm2m/src/emqx_lwm2m_channel.erl @@ -111,8 +111,8 @@ info(clientid, #channel{clientinfo = #{clientid := ClientId}}) -> info(ctx, #channel{ctx = Ctx}) -> Ctx. -stats(_) -> - []. +stats(#channel{session = Session}) -> + emqx_lwm2m_session:stats(Session). init( ConnInfo = #{ @@ -246,7 +246,7 @@ handle_call( Subs = emqx_lwm2m_session:info(subscriptions, Session), NSubs = maps:put(MountedTopic, NSubOpts, Subs), NSession = emqx_lwm2m_session:set_subscriptions(NSubs, Session), - {reply, {ok, {MountedTopic, NSubOpts}}, Channel#channel{session = NSession}}; + {reply, {ok, {MountedTopic, NSubOpts}}, [{event, updated}], Channel#channel{session = NSession}}; handle_call( {unsubscribe, Topic}, _From, @@ -269,7 +269,7 @@ handle_call( Subs = emqx_lwm2m_session:info(subscriptions, Session), NSubs = maps:remove(MountedTopic, Subs), NSession = emqx_lwm2m_session:set_subscriptions(NSubs, Session), - {reply, ok, Channel#channel{session = NSession}}; + {reply, ok, [{event, updated}], Channel#channel{session = NSession}}; handle_call(subscriptions, _From, Channel = #channel{session = Session}) -> Subs = maps:to_list(emqx_lwm2m_session:info(subscriptions, Session)), {reply, {ok, Subs}, Channel}; diff --git a/apps/emqx_gateway_lwm2m/src/emqx_lwm2m_session.erl b/apps/emqx_gateway_lwm2m/src/emqx_lwm2m_session.erl index e267692a6..8c37d48e2 100644 --- a/apps/emqx_gateway_lwm2m/src/emqx_lwm2m_session.erl +++ b/apps/emqx_gateway_lwm2m/src/emqx_lwm2m_session.erl @@ -248,11 +248,11 @@ stats(subscriptions_max, _) -> stats(inflight_cnt, _) -> 0; stats(inflight_max, _) -> - 0; + infinity; stats(mqueue_len, _) -> 0; stats(mqueue_max, _) -> - 0; + infinity; stats(mqueue_dropped, _) -> 0; stats(next_pkt_id, _) -> diff --git a/apps/emqx_gateway_lwm2m/test/emqx_lwm2m_SUITE.erl b/apps/emqx_gateway_lwm2m/test/emqx_lwm2m_SUITE.erl index 1779bf842..df1a5d2b3 100644 --- a/apps/emqx_gateway_lwm2m/test/emqx_lwm2m_SUITE.erl +++ b/apps/emqx_gateway_lwm2m/test/emqx_lwm2m_SUITE.erl @@ -2486,6 +2486,12 @@ case100_subscription_api(Config) -> }, {201, _} = request(post, Path, SubReq), {200, _} = request(get, Path), + + %% check subscription_cnt + {200, #{subscriptions_cnt := 2}} = request( + get, "/gateways/lwm2m/clients/" ++ binary_to_list(ClientId) + ), + {204, _} = request(delete, Path ++ "/tx"), {200, [InitSub]} = request(get, Path).