Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] connect_async problem and advice publish/dedconnect needed

Hi Karl.

You seem to use the Paho libray, maybe it is handled differently there. Or is paho based on mosquitto??
As for the MID parameter in mosquitto_publish: The api doc ( says:

mid	pointer to an int.  *If not NULL*, the function will set this to the message id of this particular message.  This can be then used with the publish callback to determine when the message has been sent.  Note that although the MQTT protocol doesn't use message ids for messages with QoS=0, libmosquitto assigns them message ids so they can be tracked with this parameter.

So if you provide a pointer to a defined int, this will be used for the message id (at least this is how I read it).



-----Urspr√ľngliche Nachricht-----
Von: mosquitto-dev-bounces@xxxxxxxxxxx [mailto:mosquitto-dev-bounces@xxxxxxxxxxx] Im Auftrag von Karl Palsson
Gesendet: Mittwoch, 29. April 2015 12:06
An: General development discussions for the mosquitto project
Betreff: Re: [mosquitto-dev] connect_async problem and advice publish/dedconnect needed

Interesting.  The loop_start/loop_stop behaviour I was proposing is how
the python client works.

See the bottom for a simple client that publishes all three before
exiting.  I retested this with libmosquitto and indeed, loop_stop won't
stop unless you call disconnect, and disconnect just exits, before
you've finished the exchange.  Roger, is it really meant to be like

One further note, you've made a common mistake, in that you're trying to
_provide_ a MID in the publish call.  You don't provide a mid here, you get a MID written back to you. 

Karl P

#!/usr/bin/env python

import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

client = mqtt.Client()
client.on_connect = on_connect

client.connect("localhost", 1883, 60)


client.publish("test/topic", "dummy msg qos 0", 0)
client.publish("test/topic", "dummy msg qos 1", 1)
client.publish("test/topic", "dummy msg qos 2", 2)



"Bayerlein, Markus (I/AEV-23)" <markus.bayerlein@xxxxxxx> wrote:
> Hi.
--- snip ---
>         for ( qos = 0; qos <= 2; ++qos ) {
>             ++msg_id;
>             sprintf(msg, "my test message, QoS %d, id %d", qos, msg_id);
>             mlen = strlen(msg);
>             printf("sending message %d with QoS %d on topic %s\n", msg_id, qos, topic);
>             if ( mosquitto_publish(m, &msg_id, topic, mlen, msg, qos, false) != MOSQ_ERR_SUCCESS ) {
>                 perror("failed to publish message");
>             }

Back to the top