Subscriptions from MQTT to MQTT-SN

I am using EMQX 5.3.2. I have deployed it and enabled MQTT-SN.

I can connect, publish and receive messages in MQTT. In MQTT-SN, I can publish and receive messages such as CONNACT, PUBACK… but, I have tried subscribing a client (MQTT-SN) through the dashboard (the subscription appears) and also connecting as MQTT client.

In case I reain connected as MQTT client, all messages sent to the topic are received by the client. But, after connecting as MQTT-SN client, I cannot receive any message. Even new publication during my connection.

What can I do about this? I need to use some of my clients through MQTT-SN and others through MQTT so, they must be able to send messages each other through Broker-gateway.


Just to clarify: do you use the same client ID for both connections? In this case it’s not going to work: the broker always keeps a single channel for each client ID. If you reconnect a client with the same client ID through a different gateway, the old connection will be taken over the by the new one and terminated.

If you need to connect a client via both MQTT and MQTT-SN, then you’ll have to use different client IDs.

Hi @dmif
I am using EMQX that included Broker and gateway. Through EMQX dashboard I create the subscription for client 1 to topic “test” and subscription for client 2 to “test2”.

Client 1 connects to mqtt-sn and publishes to topic “test2”.
Client 2 connects to mqtt publishes to topic “test”.

Client 2 receives everything from “test2”.
Client 1 does not receive anything.

How should I create client 1 subscription?

Any idea about what can I test for this? I see the subscription on the dashboard but it does not matter how many publishes I do, none of them reaches the mqtt-sn client.

On the dashboard under the Clients section, I see that there are X messages on the Message Queue (session info list). Is it possible that the messages are being stored for any reason?

I tried to reproduce the problem locally using mqtt-sn-sub client from this repo GitHub - njh/mqtt-sn-tools: Command line tools written in C for the MQTT-SN (MQTT for Sensor Networks) protocol, but couldn’t. Perhaps I am missing some important steps.

I was able to receive messages published to the topic that the mqtt-sn-sub client subscribes to. Could you give a more detailed instruction how to reproduce this problem? Which client are you using?

For subscribing the mqtt-sn client, I tried with EMQx dashboard. I also tried with MQTT.fx (Windows application: Softblade) through MQTT.

For publishing, I tried with a php script that connects to MQTT and perform a publish and also through another client with MQTT.fx.

My final MQTT-SN client is a Sim7080G (NB-IoT module) that uses Vodafone network. It can connect, register a topic, publish and disconnect. in every case the module receives the corresponding ACK.

I updated EMQx to 5.4.1 version. I have the free option.
All publications are done in QoS1.

Can you tell me how you tested the mqtt-sn client? did you use a python script or something I can try? Is it possible you share your gateway configuration? Maybe I have something bad configured or I need to setup other parameters.

I just tried creating the subscription through the end device (NB-IoT module) and this is the log file from the server:

2024-01-18T07:53:46.439124+01:00 [debug] msg: RECV_data, mfa: emqx_gateway_conn:parse_incoming/2(693), peername:, data: <<21,4,0,1,234,96,56,54,48,48,49,54,48,52,51,57,55,55,50,54,56>>
2024-01-18T07:53:46.440438+01:00 [debug] msg: RECV_packet, mfa: emqx_gateway_conn:handle_incoming/2(750), peername:, packet: SN_CONNECT(W0, C0, ProtocolId=1, Duration=60000, ClientId=client_id)
2024-01-18T07:53:46.445864+01:00 [debug] msg: subscribe, mfa: emqx_trace:subscribe/3(79), peername:, clientid: client_id, topic: mqttsn/topic_sub, sub_id: <<"topic_sub">>, sub_opts: #{is_new => true,nl => 0,qos => 1,rap => 0,rh => 1}, tag: SUBSCRIBE
2024-01-18T07:53:46.447001+01:00 [debug] msg: unsubscribe, mfa: emqx_trace:unsubscribe/2(84), peername:, clientid: client_id, topic: mqttsn/topic_sub, sub_opts: #{is_new => true,nl => 0,qos => 1,rap => 0,rh => 1,subid => <<"topic_sub">>}, tag: UNSUBSCRIBE
2024-01-18T07:53:46.447892+01:00 [debug] msg: conn_process_terminated, mfa: emqx_gateway_conn:terminate/2(588), peername:, clientid: client_id, reason: {shutdown,takenover}

There is an unsubscribe message my device is not sending. Is this produced by the server?