[
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
|
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
that?
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.
Cheers,
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.loop_start()
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)
client.loop_stop()
------------------
"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");
> }