Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Problem with last will testament
Problem with last will testament [message #1624293] Thu, 19 February 2015 17:45 Go to next message
Jesus Ch is currently offline Jesus ChFriend
Messages: 2
Registered: February 2015
Junior Member
I'm trying to communicate a couple of programmes. I'm getting some troubles when I use the last will function. My code is this:

Suscriber:
import paho.mqtt.client as mqtt
def on_message(client, userdata, msg):
    print 'Received: ' + msg.payload

client = mqtt.Client()
client.on_message = on_message

client.connect('localhost', 1883)
client.subscribe('hello/#')

client.loop_forever()


Publisher:
import paho.mqtt.client as mqtt

client = mqtt.Client()

client.will_set('hello/will', 'Last will', 0, False)
client.connect('localhost', 1883)

client.publish('hello/world', 'Regular msg', 0, False)
client.disconnect()


The output:
Received: Last will

I should receive only the regular message because I use client.disconnect() to close the connection. If I comment the will_set line, I get the regular message. I also tried publishing both on the same topic and it doesn't work. Any guess??
Re: Problem with last will testament [message #1670583 is a reply to message #1624293] Fri, 13 March 2015 08:54 Go to previous message
Roger Light is currently offline Roger LightFriend
Messages: 20
Registered: September 2013
Junior Member
Hi there,

I'm fairly certain we've already discussed this with you on IRC, but if not the answer is that calling disconnect() doesn't guarantee that the DISCONNECT message is sent. All functions that send data are asynchronous. You need to call e.g. loop_start() or loop_forever() to ensure the network data is processed. You could also look into using the paho.mqtt.publish.single() function, which does this for you.

Cheers,

Roger
Previous Topic:Loop functions
Next Topic:Cordova + Phonegap
Goto Forum:
  


Current Time: Mon Nov 19 04:41:30 GMT 2018

Powered by FUDForum. Page generated in 0.02370 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top