Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Python client: static publish method
Python client: static publish method [message #1495430] Tue, 02 December 2014 07:47 Go to next message
a b is currently offline a bFriend
Messages: 2
Registered: December 2014
Junior Member
Dear all,

I'm experimenting with the python paho lib in order to publish some information via mqtt.
The mqtt client I want to embed into an existing python script.

I'm a python starter and have generally the client is running. My only issue is that I cannot embed the connect/reconnect mechanism within a method.
When I just put the initialization of the client in a .py file everything is working perfectly.
When I'm embedding the initialization in the connect method and I try to run it before publication, then it fails:

in loop_forever
    self.reconnect()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 743, in reconnect
    self._sock.setblocking(0)
AttributeError: 'NoneType' object has no attribute 'setblocking'


The same applies when I want to keep the connection alive.

I'm doing this because I need to create a publish method that I can use as "fire and forget". I need to have a mechanism that when someone tries to publish something the publish method checks if the connection is established, otherwise do it and publish it. The connection can stay open. Unfortunately my internet connection is quite unstable which forces me to check that.

Can someone give me some advices or even some code snippets how to do that best?
Re: Python client: static publish method [message #1498233 is a reply to message #1495430] Thu, 04 December 2014 09:09 Go to previous messageGo to next message
a b is currently offline a bFriend
Messages: 2
Registered: December 2014
Junior Member
I think I found my issue.
In my script I'm having an additional other socket. This script needs the following parameter set:
socket.setdefaulttimeout(0)

When removing this I can get it working.

By the way:
Is there a proper way to check if the paho client is connected?
Re: Python client: static publish method [message #1553719 is a reply to message #1498233] Thu, 08 January 2015 21:46 Go to previous message
Roger Light is currently offline Roger LightFriend
Messages: 21
Registered: September 2013
Junior Member
As a slightly different thought, have you considered using paho.mqtt.publish.single()?
Previous Topic:List of MqttClient subscriptions
Next Topic:Paho Client Tool and Subscriber tool running on local host
Goto Forum:
  


Current Time: Wed Dec 12 02:31:42 GMT 2018

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

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

Back to the top