MQTT subscribe to a topic and get another topic for free

I have been using mosquitto_sub and MQTT to subscribe to TTN application/device uplinks and it works very well. I now want to get more sophisticated and have a separate subscription to collect application/device events. Using the documentation I have subscribed to the MQTT topic +/devices/+/events… and I get events AND all the uplinks. I have used mosquitto_sub in debug mode to try to understand this and here is a snippet of me subscribing to +/devices/+/events:

$ mosquitto_sub -h eu.thethings.network -d -t +/devices/+/events -u ‘…’ -P ‘…’
Client mosqsub|4108-cts4 sending CONNECT
Client mosqsub|4108-cts4 received CONNACK
Client mosqsub|4108-cts4 sending SUBSCRIBE (Mid: 1, Topic: +/devices/+/up, QoS: 0)
Client mosqsub|4108-cts4 sending SUBSCRIBE (Mid: 2, Topic: +/devices/+/events, QoS: 0)
Client mosqsub|4108-cts4 received SUBACK

It appears that when I subscribe to +/devices/+/events I get a free additional subscription to +/devices/+/up. I have tried a variety of topics and I always get the additional subscription to +/devices/+/up. If I subscribe with no topic at all then I get +/devices/+/up.

I have a lot of experience of getting things wrong and then muddling through using forums, google, etc. but I have failed to find a way to subscribe to only +/devices/+/events.

Can anyone point out what I’m doing wrong? Thanks in advance.

1 Like

Anything in your ~/.config/mosquitto_sub file? And though your debug output shows QoS: 0 for the uplinks too: any chance you ever used some other QoS for that?

Just in case it helps, using the same command, I only get the events:

$ mosquitto_sub -h eu.thethings.network -d -t +/devices/+/events -u my-app-id -P ttn-account-v2.w1q...Gk
Client mosqsub|97315-arjan.fri sending CONNECT
Client mosqsub|97315-arjan.fri received CONNACK
Client mosqsub|97315-arjan.fri sending SUBSCRIBE (Mid: 1, Topic: +/devices/+/events, QoS: 0)
Client mosqsub|97315-arjan.fri received SUBACK
Subscribed (mid: 1): 0

…and that’s on a Mac for:

$ mosquitto_sub --help
...
mosquitto_sub version 1.4.14 running on libmosquitto 1.4.14.

@arjanvanb you are a real star!

Here it is…

$  more .config/mosquitto_sub
# mosquitto_sub config
# config file for sds MQTT subscriber
#
--host eu.thethings.network
--topic +/devices/+/up
--username ...
--pw ttn-account-v2....
#
# end

Config file now edited to comment out the topic and it’s working correctly.

Thanks again!