0

connecting two esp8266
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

connecting two esp8266

by kbasher on Mon Feb 26, 2018 10:23 am

Hi
I'm trying to connect two ESP8266 using just one key. if I connect one, the second one fails to connect to the broker. Trying to write code to control led of one board using push switch from another.
What am I doing wrong? I'm using free account.

kbasher
 
Posts: 1
Joined: Wed Feb 07, 2018 2:19 pm

Re: connecting two esp8266

by abhi_nath on Sat May 05, 2018 10:21 am

I am having the same problem. Only one ESP8266 connects, other one keeps on trying to connect. Is there any solution?

abhi_nath
 
Posts: 3
Joined: Sat Feb 17, 2018 12:54 pm

Re: connecting two esp8266

by abhi_nath on Mon May 07, 2018 3:12 pm

It would be of a great help if any experienced users can provide some clue.
Are they not connecting because Adafruit IO has any restriction on simultaneous connection with Free account ?

abhi_nath
 
Posts: 3
Joined: Sat Feb 17, 2018 12:54 pm

Re: connecting two esp8266

by abachman on Wed May 09, 2018 11:04 am

Hi all,


If you're using the same client ID in both sketches, the second would cause the first to disconnect. Our MQTT broker only allows one client connection per client ID, any subsequent connection with the same client ID will force the first to disconnect.

If you're using the Adafruit IO Arduino library, which is using the Adafruit MQTT library underneath, your client ID is randomized on each connection. If you're setting the client ID manually--for example, in order to track connection / disconnection per-device--you'll need to make sure each device or script has a different client ID.


- adam b.

abachman
 
Posts: 319
Joined: Mon Feb 01, 2010 12:48 pm

Re: connecting two esp8266

by abhi_nath on Wed May 09, 2018 1:10 pm

Thanks Adam for the reply. Really appreciate.

I could figure it out yesterday after looking at the Arduino code I was using, which is the sample code came in with the Library.

Changed the below line :
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_USERNAME, AIO_KEY);

To
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_CLIENT, AIO_USERNAME, AIO_KEY);

After defining the AIO_CLIENT name and voila, it started working.

abhi_nath
 
Posts: 3
Joined: Sat Feb 17, 2018 12:54 pm

Re: connecting two esp8266

by wraith181 on Fri May 31, 2019 3:11 am

I spend six hours trying to find an answer to this today and it was only this post and another post that have allowed me to connect two different ESP8266s and keep them connected. This is the most useful thing for anyone trying to connect multiple IoT devices to the Adafruit IO. Please make this easier to find for other people who are struggling

The Adafruit MQTT does NOT assign random client IDs to each device. Mine were constantly the same and when I tried connecting both devices to the Adafruit IO, they kept kicking each other off.

wraith181
 
Posts: 1
Joined: Sat Aug 18, 2018 11:51 pm

Re: connecting two esp8266

by moh_300 on Sat Jul 20, 2019 5:35 pm

could you please show me some example..I am beginner?How
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_CLIENT, AIO_USERNAME, AIO_KEY);

After defining the AIO_CLIENT name and voila

moh_300
 
Posts: 1
Joined: Sat Jul 20, 2019 4:32 am

Re: connecting two esp8266

by abachman on Mon Jul 22, 2019 11:27 am

To be clear, the Adafruit MQTT library doesn't randomize the client ID, our MQTT broker assigns a random client ID when devices connect with no client ID set (technically with a client ID whose length is zero bytes).


- adam b.

abachman
 
Posts: 319
Joined: Mon Feb 01, 2010 12:48 pm

Re: connecting two esp8266

by brubell on Mon Jul 22, 2019 12:16 pm

wraith181 wrote:I spend six hours trying to find an answer to this today and it was only this post and another post that have allowed me to connect two different ESP8266s and keep them connected. This is the most useful thing for anyone trying to connect multiple IoT devices to the Adafruit IO. Please make this easier to find for other people who are struggling

The Adafruit MQTT does NOT assign random client IDs to each device. Mine were constantly the same and when I tried connecting both devices to the Adafruit IO, they kept kicking each other off.


Adafruit MQTT does assign a 0-byte client identifier when you do not provide a defined client ID. In this case, the broker (Adafruit IO) will assign a random, unique client ID to each device connecting using the function:
Code: Select all | TOGGLE FULL SIZE
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
image.png
image.png (22.12 KiB) Viewed 67 times


There's a possibility that you are setting two identical AIO_CLIENT values:
Code: Select all | TOGGLE FULL SIZE
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_CLIENT, AIO_USERNAME, AIO_KEY);

brubell
 
Posts: 467
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.