Page 1 of 2

Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Thu Jan 12, 2017 6:14 pm
by The Royal We
First, I am very new to programming, microcontollers, and networking so please be gentle.

I currently have two Adafruit Feather Huzzah's; Feather1 has a temperature sensor attached to it, Feather2 has a 7 segment display attached to it. I also have a Raspberry Pi running as an MQTT broker. The end goal is to have multiple temperature sensors transmitting data via MQTT to the display.

Currently I am able to publish from the temp sensor on Feather1 to my laptop. Additionally, I am able to subscribe from the display on Feather2 from my laptop. However, whenever I try to publish from Feather1 to Feather2 I get :

File "umqtt/simple.py", line 56, in connect
OSError: [Errno 103] ECONNABORTED

I have a suspicion that the problem has something to do with network sockets based on following that traceback.

When I run ifconfig on each of the feathers (as well as when looking on Fing) I see that they each have different IP addresses on my local network, but their gateway and DNS are the same (10.0.1.1). I cannot find information in the documentation about adjusting the DNS on the feather, but have a feeling its being determined by the router (5th gen Apple Airport Extreme).

My connection to the network is basically this code here https://docs.micropython.org/en/latest/ ... networking

Any help on getting these feathers to send data to one another would be greatly appreciated. Thanks for looking and please let me know if I can clarify with details.

Re: Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Thu Jan 12, 2017 7:29 pm
by torwag
Hi,

Not sure I understood you right, however in MQTT there is nothing like publish from one device to another. Each and every message goes to the mqtt broker (your rpi). From there other clients can subscribe to certain channels and read what others published there.
In a sense MQTT is for IOT devices what a chat server like irc (or whatsapp) is for humans. You do not connect between devices but both devices connect to the server.

Might this be your problem?

Re: Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Thu Jan 12, 2017 9:09 pm
by The Royal We
Thank you for the response and apologies for any confusion. I am using the broker on the rpi as an intermediary and I have had success in various tests. I am able to take data from the temp sensor on one feather, pass it via MQTT to the rpi broker and read it on a laptop. Similarly, I am able to take data from my laptop, pass it through the rpi broker and display it on another feather. Its when I go from temp sensor feather via rpi to display feather that things break. Here is a visualization that I made to help me conceptualize

These two scenarios work:
Temp Sensor Feather ---[publish to topic1]---> RaspberryPi MQTT broker ---[subscribe to topic1]---> Laptop
Laptop ---[publish to topic1]---> RaspberryPi MQTT broker ---[subscribe to topic1]---> Display Feather

However, when I try the following I get the ECONNABORTED error...
Temp Sensor Feather ---[publish to topic1]---> RaspberryPi MQTT broker ---[subscribe to topic1]---> Display Feather

Hope this helps clarify.

Re: Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Thu Jan 12, 2017 9:16 pm
by torwag
Hi,
yes this makes things more clear.
Which unit fails to connect? the display or the sensor unit?

ADDON:

Did you make sure you have two unique client IDs set during the initialisation of the MQTT client?

Re: Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Thu Jan 12, 2017 9:27 pm
by The Royal We
The display unit is the one that fails to connect. The sensor unit appears to be chugging along just fine.

EDIT:
Both feathers had different client id's in the initialization

Re: Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Thu Jan 12, 2017 9:33 pm
by hsmade
I see the same issue. As soon as I establish 2 connections to my broker, with different IDs, I will get this error message. When I close one connection, it works.

Re: Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Thu Jan 12, 2017 11:46 pm
by torwag
Which kind of broker do you use. This is indeed a rather strange behaviour as I can't see in which way umqtt should be involved here. The client does not have any idea how many other clients or which clients are connected to the broker.

Re: Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Fri Jan 13, 2017 7:53 am
by hsmade
I'm thinking that if it's a micropython related problem, it could be in socket.
I'm using mosquitto on raspberry pi. I will do a test with 2 simultaneously connected python clients on intel, to see if I can reproduce it on another platform as well.

-- Wim

Re: Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Fri Jan 13, 2017 8:07 am
by hsmade
Ok, so this is indeed a problem with the socket implementation:

>>> import socket
>>> sock = socket.socket()
>>> addr = socket.getaddrinfo('192.168.178.35', 80)[0][-1]
>>> sock.connect(addr)
>>> sock.write('GET / HTTP/1.1\nHost: localhost\n\n')
32
>>> print(sock.read(10))
b'HTTP/1.1 2'


>>> sock2 = socket.socket()
>>> addr = socket.getaddrinfo('192.168.178.35', 80)[0][-1]
>>> sock2.connect(addr)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 103] ECONNABORTED

Re: Problem with Multiple ESP8266 and MQTT. Blocked Sockets?

Posted: Sat Jan 14, 2017 6:53 am
by pythoncoder
I don't understand why your display unit is opening two sockets. I'd expect to see a single instance of the MQTTClient class, with all publications and subscriptions being routed through that. A single instance opens just one socket.

On the other hand it does look as if you've found a bug: if confirmed it should be reported on GitHub.