Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] does calling mosquitto_subscribe twice add a new subscription or replace the existing one?

Just to follow up on this, over the weekend I spent some time on this and it seems that the mqtt lib for Prolog I was using included an old version of the mosquitto library in its distribution. Once I removed that and recompiled with a current version the subscriptions worked as expected. I ended up forking the repository for the interface (it appears the original is inactive) and I'm now working to allow binary blob message payloads via the library, plain string payloads already work.

My fork is at: https://github.com/sprior/swi-mqtt-pack

I think that there are some pretty cool possibilities using Prolog in combination with IOT devices, but I may just be weird.

Steve

On 5/30/2017 5:07 AM, Roger Light wrote:
Hi Steve,

If you call

mosquitto_subscribe(client, NULL, "topic1", 1);
mosquitto_subscribe(client, NULL, "topic2", 0);

then you should end up subscribed to both topic1 (with qos 1) and
topic2 (with qos0).

If you subsequently call

mosquitto_subscribe(client, NULL, "topic2", 1");

then your subscription for topic2 will be updated to be qos 1 instead.
It will not add an extra subscription for topic2.

I hope that clears things up.

Regards,

Roger



On 30 May 2017 at 03:39, Steve Prior <sprior@xxxxxxxxxxxx> wrote:
I'm getting started using the mqtt pack for SWI-Prolog to subscribe to
topics on a mosquitto message broker.  The library under the covers uses the
c mosquitto API.

I've been able to subscribe to a topic and process incoming messages in
Prolog - this is working.  What I'm trying to understand is whether I can
subscribe to two completely different topics using the same mqtt connection.
I was under the impression that this was possible, but what I think I saw
was than when I called subscribe a second time I started seeing the messages
under the new topic, but no longer saw the messages I had previously
subscribed to.  Then when I called subscribe again with the original topic I
saw only those and not the ones for the second topic.

I've gone through the prolog -> mosquitto interface code and the interface
code is doing very little beyond retrieving the connection and passing the
call to the mosquitto c API, so I don't think that interface is adding any
new restrictions.

Looking at the c API documentation for mosquitto_subscribe it does not
specify the behavior if it is called twice.  Can anyone clarify if the new
subscription topic is supposed to replace (or add) to any previous
subscribed topics?

Thanks
Steve Prior



Back to the top