Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » MQTT client stops sending PINGREQ packets after receiving a message on its subscription(Paho MQTT- sockets, timeout, PINGREQ, PINGRESP)
MQTT client stops sending PINGREQ packets after receiving a message on its subscription [message #1750846] Thu, 29 December 2016 23:17 Go to next message
Nicholas John is currently offline Nicholas JohnFriend
Messages: 2
Registered: December 2016
Junior Member
So, I am writing a program that works as a proxy for an MQTT client, to allow it to run over a serial-based internet-connected device. This is why you will see the client connecting to localhost.

I have a relatively simple client script:

import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
print("Connected with result code {0}".format(str(rc)))
#print("result code: "+str(rc)+"\nclient1_id: "+str(client))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("/blah/testing", qos=0)

def on_message(client, userdata, message):
print("Received message '" + str(message.payload) + "' on topic '"
+ message.topic + "' with QoS " + str(message.qos))

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
#client.connect("m2m.eclipse.org", 1883) # 198.41.30.241
print("Connecting to localhost...")
client.connect("127.0.0.1", port=5231, keepalive=15)
client.loop_forever() # Start networking daemon


If I let this run without publishing any messages to that topic (via a separate script), it behaves, and sends out a PINGREQ every 15 seconds, since I set "keepalive" to that value.

As soon as I publish a message to the topic "/blah/testing" (with a separate script), my client will print (after 10-15 seconds) "Received message 'blah' on topic '/blah/testing' with QoS 0" BUT, once this occurs, my client stops sending out any PINGREQ frames, as if the "loop_forever()" networking daemon decided to stop. It will then eventually disconnect due to what I assume is the socket timing out, as my "socket.recv(size)" call in my proxy script that normally receives socket messages from the MQTT client script starts receiving '' or EOF.

ANY IDEAS?

I tried using loop_start() in place of loop_forever(), and in the message callback I tried stopping and starting the daemon again, but I can't seem to figure out the issue. It's my understanding that the loop_<whatever>() functions start a network daemon that is responsible for keeping the TCP connection open, and thusly should still be keeping the connection alive after a message receipt. But, let me know if I am misunderstanding the workings, of course.

Thanks to whoever took the time to read this,
Cheers,
NJ
Re: MQTT client stops sending PINGREQ packets after receiving a message on its subscription [message #1751143 is a reply to message #1750846] Wed, 04 January 2017 22:08 Go to previous message
Nicholas John is currently offline Nicholas JohnFriend
Messages: 2
Registered: December 2016
Junior Member
I modified my proxy script to send a "PINGRESP" to the client, simulating a ping interaction, after any "PUBACK" sent by the client after a message receipt. For some reason, this seems to keep the network daemon up and running. I still don't have any insight into why the protocol behaves this way, but if this helps anyone. My script has been running for over an hour and I posted 12 or so messages to the test topic on the broker I am using, all of which delivered successfully.
Previous Topic:MQTTClient_create(...) C lib problem
Next Topic:I am getting this error while connecting to MqttClient
Goto Forum:
  


Current Time: Thu Nov 15 16:23:12 GMT 2018

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

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

Back to the top