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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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!


  • Made with Math Contest

    Made with Math Contest
  • Multi-Discipline Contest

    Multi-Discipline Contest
  • Robotics Contest

    Robotics Contest

50 Discussions


Question 5 days ago

Your sketch works well with me. I have a question.
How can I send more text lines?
For example.
Hello world.
Hello friend.
I tried it but am too much a beginner (73).
Thanks in advance.
Bert Heideveld.

2 answers

Answer 2 days ago

Hi Bert,
There are many ways to send more text.
Merge the short strings to a longer one separated with a special character. Send the long string to the other ESP, and cut the long string to parts at the separator.
The other way can be to change the value of the string in every cycle before the client.print("... command.



Reply 2 days ago

Oke i work on it. Do you have a exampel ?



8 months ago

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

2 replies

Reply 8 months ago

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


Reply 8 months ago

The reverse action and is very slow in sending messages.

there's a solution?


1 year 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 1 year 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 1 year 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.


1 year ago

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

3 replies

Reply 1 year ago

Hi eslam46,

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


Reply 1 year ago

thanks you Gyalu for ur reply


1 year 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

1 year 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