Error executing multiple connections to mqtt

30 views
Skip to first unread message

Andrea Giordano

unread,
Sep 14, 2017, 6:45:59 AM9/14/17
to MQTT
Hi, I'm using mosquitto on a RPI3 to collect data coming from some python codes.
I have a python script which execute 8 py codes:

python RC-accSimulation.py &
python RC
-gyrSimulation.py &
python RT
-accSimulation.py &
python RT
-gyrSimulation.py &
python LC
-accSimulation.py &
python LC
-gyrSimulation.py &
python LT
-accSimulation.py &
python LT
-gyrSimulation.py &


Each one of these codes at the end send a string to the same mqtt broker but using different topics:

mqttClient = mqtt.Client()
mqttClient
.connect(host=raspberry_MQTT_ip, port=1883)
mqttClient
.publish("topic/sensorLCacc", jsonData)


Unfortunately when I execute the script (with all the py codes) after some seconds of correct execution I obtain:

Traceback (most recent call last):

  File "/Users/giordano/Dropbox/Andrea/tesi/sensorsScripts/simulatedsensors/RT-accSimulation.py", line 58, in <module>

    mqttClient = mqtt.Client()

  File "/Library/Python/2.7/site-packages/paho/mqtt/client.py", line 497, in __init__

    self._sockpairR, self._sockpairW = _socketpair_compat()

  File "/Library/Python/2.7/site-packages/paho/mqtt/client.py", line 245, in _socketpair_compat

    sock1.connect(("127.0.0.1", port))

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth

    return getattr(self._sock,name)(*args)

socket.error: [Errno 49] Can't assign requested address



I want to highlight that this error appears just when I execute in the script more than 5 py codes. I tried every combinations of py codes to verify if a specific one was guilty but this is not the case. 
Strings are sent about each 20ms. Too much traffic? it sounds strange...

Moreover, I tried executing 5 py code in the script and then putting in one of them multiple publish functions (see above) to cover the other non-executed py code and everything works.

mqttClient = mqtt.Client()
mqttClient
.connect(host=raspberry_MQTT_ip, port=1883)
mqttClient
.publish("topic/sensorLCacc", jsonData)
mqttClient
.publish("topic/sensorLTacc", jsonData)
mqttClient
.publish("topic/sensorLCgyr", jsonData)
mqttClient
.publish("topic/sensorLTgyr", jsonData)









Reply all
Reply to author
Forward
0 new messages