Connecting two ESP8266 via WiFI

Hello

I would like to connect two NodeMCUs, by using the WiFi of the ESP8266, in order to exchange sensor measurements. Both devices are not connected to any other WiFi network. My code is actually the same as the client and server example code from ESP8266WiFi library — ESP8266 Arduino Core documentation. (see attachments) However, I removed the code to connect to an existing WiFi network; instead one NodeMCU is configured to be a soft access point, which the other NodeMCU connects to. Please see below my questions:

  1. What is a soft access point? According to my knowledge an access points provides wireless devices with an access to an existing network. This way the area, in which the network is available, and the permitted number of devices is increased. But an access point cannot create a network itself. That's why a router is required, which manages the network.
    Now I am confused, because somehow the soft access point of the ESP8266 can be used as a router, in order to create a network and to exchange data. Additionally, a soft access point is described as a virtual router on wikipedia.

  2. How do I obtain or define the IP of my server? I configured the NodeMCUs as station and access point to obtain a WiFi connection. Then I setup a client and server. First, the client connects to my access point via ssid and password, then it connects to the server on the same NodeMCU via IP. But how do I get this IP?
    The command WiFi.softAPIP provides me with the IP of the access point (192.168.4.1). But this does not seem to be my server IP. This is still the one, which I received via WiFi.localIP (192.168.2.110), when I was connected to a separate WiFi network.
    Since I would at least expect my server to have an IP such as 192.168.4.*, I currently lost.

Thank you in advance for your support!

NodeMCU_Access_Point.ino (2.2 KB)

NodeMCU_Client.ino (1.31 KB)

ESP-NOW ESP-Now Overview | Espressif Systems

  1. Access Point creates the WiFi network. router does the routing between networks.
  2. the SoftAP has DHCP

Idahowalker:
ESP-NOW ESP-Now Overview | Espressif Systems

Could you please expand a little bit on this topic? Your link does not answer any of my questions.

Juraj:

  1. Access Point creates the WiFi network. router does the routing between networks.
  2. the SoftAP has DHCP

So how do I know the IP of my server?

johnson3000:
Could you please expand a little bit on this topic? Your link does not answer any of my questions.

So how do I know the IP of my server?

ESPNow connects two NodeMCUs, by using the WiFi of the ESP8266, in order to exchange sensor measurements.
The protocol is not TCP-IP, so there is no IP address.

Ok, so its an alternative approach. I would like to stick to my approach above though using the ESP8266Wifi.h, which requires an IP adress. Otherwise I am afraid to deal with multiple appraches without getting any result. But I keep the other solution in my mind.

This code snippet sets up an IP address on my ESP32-CAM. I don't know if it is the same for an ESP8266

     // set up as an Access Point
const char* ssid = "trainCam";
Serial.print("Setting AP (Access Point)…");
     // Remove the password parameter, if you want the AP (Access Point) to be open
WiFi.softAP(ssid);

IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);

...R

Robin2:
This code snippet sets up an IP address on my ESP32-CAM. I don't know if it is the same for an ESP8266

     // set up as an Access Point

const char* ssid = "trainCam";
Serial.print("Setting AP (Access Point)…");
    // Remove the password parameter, if you want the AP (Access Point) to be open
WiFi.softAP(ssid);

IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);




...R

Yes, but this IP is not the one, which is used to connect to the server. And this is exactly the reason for my question above. Why is another IP used to connect to the server and how is this IP defined?

johnson3000:
Could you please expand a little bit on this topic? Your link does not answer any of my questions.

So how do I know the IP of my server?

Try an internet search on the words "esp-now" for more information.

Idahowalker:
Try an internet search on the words "esp-now" for more information.

Sorry, I don't get your intention. I asked for a way to connect via WiFi. The first two sentences of the link above are "ESP-NOW is yet another protocol developed by Espressif, which enables multiple devices to communicate with one another without using Wi-Fi." So it does not use WiFi. It's like someone asks you, how to drive a car and you tell me "Take the train.". Furthermore, it does not answer any of my questions. If I would have succeed via google, I would not have asked here.

johnson3000:
Sorry, I don't get your intention. I asked for a way to connect via WiFi. The first two sentences of the link above are "ESP-NOW is yet another protocol developed by Espressif, which enables multiple devices to communicate with one another without using Wi-Fi." So it does not use WiFi. It's like someone asks you, how to drive a car and you tell me "Take the train.". Furthermore, it does not answer any of my questions. If I would have succeed via google, I would not have asked here.

Oh bother.

ESP-Now is an interesting ESP8266 protocol that could be used for battery powered sensors. Its built on top of 802.11 vendor-specific action frames which enables sending data without having to first establish a WiFi AP to Station connection which is time consuming and so adds significantly to draining the batteries on each sensor wakeup.

ESP-NOW uses your wireless. Like I wrote, do your research. ESP-Now/EspNowWatsonRestartingGateway.ino at master · HarringayMakerSpace/ESP-Now · GitHub

Furthermore, you can use a WiFi manager library and turn one of the ESP's into a AP; again do your research.

Ah, this was the information I was missing. No, you did not write it, but thank you though. :slight_smile:

the default IP address of esp8266 SoftAP is 192.168.4.1

"Both devices are not connected to any other WiFi network."

"The command WiFi.softAPIP provides me with the IP of the access point (192.168.4.1). But this does not seem to be my server IP. This is still the one, which I received via WiFi.localIP (192.168.2.110), when I was connected to a separate WiFi network."

I would think 192.168.4.1 is the IP address of the board AP and the 192.168.2.110 is most likely the station IP address on a router side of the ESP connection. You sure the board is not connected to a router?

johnson3000:
Yes, but this IP is not the one, which is used to connect to the server. And this is exactly the reason for my question above. Why is another IP used to connect to the server and how is this IP defined?

.
On my ESP32-CAM project the ESP32 is the server, as well as the AccessPoint. It prints the IP address and that is what I use to connect directly to it with my smartphone.

In your case I presume you can connect your other NodeMCU as a client in place of my use of the smartphone.

If you look on the ESP2866 Forum there is a book you can download written by Neil Kolban. It has a huge amount of info about the ESP8266. There is also an ESP32 book.

...R

Idahowalker:
Oh bother.

ESP-NOW uses your wireless. Like I wrote, do your research. ESP-Now/EspNowWatsonRestartingGateway.ino at master · HarringayMakerSpace/ESP-Now · GitHub

Furthermore, you can use a WiFi manager library and turn one of the ESP's into a AP; again do your research.

Maybe the OP wants to do it the hard way.

I got some ESP-NOW example code to run between two WeMOS 8266 boards, but the code is somewhat cryptic for me. Maybe it will have more appeal when more example code is developed. For bidirectional communication besides the typical http client/server there is some telnet example code available. I haven't seen any for the esp, but chat code might also be an option.

My understanding is that the OP wants to use WiFi rather than ESP-NOW. However if I have misunderstood this ESP-NOW demo may be of interest to him

...R