Accesspoint - Station Communication Between Two ESP8266 MCUs




Hello Makers!

In my previous instructable I made a WiFi communication between two ESP8266 MCUs through a home WiFi router. As I saw from the comments there are Makers who would like to use ESP8266 MCUs far from the range of a router. So here is a bare minimum instructable about an accesspoint - station communication which don't needs WiFi network.

Step 1: What Do You Need.

Things you need:

  • 2 pcs ESP8266 based MCUs e.g. Wemos D1 mini
  • 2 pcs micro USB cables
  • and a PC with Arduino IDE

Step 2:

Everything you have to do:

  • Download the attached sketches
  • Open them in two independent Arduino IDEs
  • Upload them into two ESP8266 MCUs.

The AP has a fix IP address eliminating the IP conflict with your other projects.

The station uses this predefined IP to connect to the AP. The station triggers the AP with a message and the AP answers it.

Opening the serial monitors of each running Arduino IDEs you can see the flow of the messages and answers.

The built in LED flashes during the communication. It is only visualization you can eliminate flashing if you don't like it.

Step 3: How to Open Independent IDEs

How to start two independent Arduino IDEs?

  • At first click on the accesspoint_bare_01.ino. It will open the first Arduino IDE.
  • Connect the first MCU.
  • Set the new port appears in the Tools->Port menu to the first MCU.
  • Upload the sketch. It will be your accesspoint.
  • After that go back to the downloaded sketches and double click on station_bare_01.ino. It will open the second Arduino IDE.
  • Connect the second MCU.
  • Set the new port appears in the Tools->Port menu to the second MCU. (If your IDEs are independent then port will not change in the first IDE window.)
  • Uplod the sketch. It will be your station.

5 People Made This Project!


  • Epilog X Contest

    Epilog X Contest
  • Weaving Challenge

    Weaving Challenge
  • Organization Contest

    Organization Contest

47 Discussions


7 weeks ago

Hi, NIce project. Thank you. Is there a way AP starts the communication?

2 replies

Reply 7 weeks ago

Hi Petr,
There may be reversed action I think, but I do not know it.


Reply 5 weeks ago

The reverse action and is very slow in sending messages.

there's a solution?


11 months ago

For some reason, when I run this code for a few minutes, the ESPs stop communicating with each other. Its like they get stuck. What could be causing this problem and how can it be fixed?

3 replies

Reply 11 months ago

Hi Jacob,

I downloaded my codes from above and uploaded them to two Wemos D1 mini. After more than 40 minute test run the station and the AP are talking without any problem.

Did you modify anything in the code?


Reply 11 months ago

Hi Gyalu,

Thank you so much for the excellent code example. I wouldn't have gotten my project to work without it.

I am using the Adafruit HUZZAH ESP8266 Breakout Board. I did modify the code but left all of the wifi connection code the same (I had the AP and station "control" each the other's LED by saying "turn on... turn off"). Most importantly, I changed the delay at the end of loop() to be 200 ms, so my code should run about 10x faster than yours (which is why your could last over 40 mins while mine only lasted a few).

I was doing some debugging and it seemed like the problem was with the station, because when I would hit the reset button on the AP, nothing would happen, but when I hit the reset button on the station, it would start working again.

I also noticed that the client.connect() method returns a boolean if it was successful or not. I printed the result of client.connect() out to Serial and noticed that after about 400 times (I got a different number each time I ran the experiment), the client.connect() method starts failing.

client.connect() starts to fail because the WiFiClient object can only connect to a server so many times before it stops working. I moved the construction of client to the beginning of loop(), so that it would construct a new WiFiClient object each time it tried to connect to the server, and this seemed to fix the bug! :) This is a reasonable solution since the WiFiClient object takes less that 1ms to construct (I timed it).

I wonder if an alternative solution to the problem would be to move "client.connect(server, 80);" to the the end of setup() and delete "client.stop();". I haven't tested that to see if its reliable since I'm happy with the current solution.

tl;dr, I was able to get the ESPs to communicate indefinitely by moving the code "WiFiClient client;" to the beginning of loop() in the station code.

On an unrelated note, in the access point code, I think you're supposed to add "client.stop();" at the end of loop(), but I don't really understand what this does, so I could be wrong.


7 months ago

can any one help me in the problem of the station nodemcu stuck and not send data after a while ?

3 replies

Reply 7 months ago

Hi eslam46,

I think Jabob solved this problem. See the comments below.


Reply 7 months ago

thanks you Gyalu for ur reply


7 months ago

thank you for that great code

but .... after a small time the station stop to trigger the access point

nothing is being sent from the station side

1 reply

5 months ago

Well thank you. That helped me.
But I do not know how to send numbers from the station to the server.
How to do it?
The commands: " ()" and "client.write ()" do not work.

I have two Adafruit father Huzzah ESP8266 with WiFi

3 replies

Reply 4 months ago

Hi Vlado66,
convert the numbers to strings, send strings through WiFi and after receiving the message convert them back to number on demand.
See String(), string.toFloat() and string.toInt() functions.


Reply 3 months ago

Hello :)
I asked myself the same question. I would like to send a BYTE. Is it always possible to send only strings?
I have already seen several examples and in fact they have always been strings.
Is there no way to send a BYTE and receive it on the other side ??
Thank you in advance for the help


Reply 3 months ago

Hi Matze8266,
as far as I know you can send only strings.
But it is not problem. Convert your BYTE to string and after receiving it convert it back to byte or whatever you want.