So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By user._.
#83840 I want to communicate between three node MCUs by using IPs. I was able to communicate between two nodemcus (one was in AP mode and the other in STA) using the same IP address without the web page.

Now, I'm having 3 nodemcus where the first one is in AP mode, second one in AP+STA mode and third in STA mode. I am able to establish a connection between the second and third nodemcu but not between the first and second.

I have attached a code for second nodemcu which is functioning in AP+STA mode. There may be errors in the code. Someone please help.
Thanks in advance.

Code: Select all#include <ESP8266WiFi.h>
byte ledPin = 2;
char ssid[] = "Wemos_AP";           // SSID of your AP
char pass[] = "Wemos_comm";         // password of your AP
IPAddress server(192,168,4,15);     // IP address of the AP
WiFiClient client;
void setup() {
  Serial.begin(9600);
   WiFi.mode(WIFI_AP_STA);
  WiFi.begin(ssid, pass);           // connects to the WiFi AP
  Serial.println();
  Serial.println("Connection to the AP");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.println("Connected");
  Serial.println("station_bare_01.ino");
  Serial.print("LocalIP:"); Serial.println(WiFi.localIP());
  Serial.println("MAC:" + WiFi.macAddress());
  Serial.print("Gateway:"); Serial.println(WiFi.gatewayIP());
  Serial.print("AP MAC:"); Serial.println(WiFi.BSSIDstr());
  pinMode(ledPin, OUTPUT);
 
}
void loop() {
 
  client.connect(server, 80);
  digitalWrite(ledPin, LOW);
  Serial.println("********************************");
  Serial.print("Byte sent to the AP: ");
  Serial.println(client.print("From sta_ap\r"));
  String answer = client.readStringUntil('\r');
  Serial.println("From the AP: " + answer);
  client.flush();
  digitalWrite(ledPin, HIGH);
  client.stop();
 // delay(2000);


WiFiClient client1 = server.available();
 if (!client1) {return;}
 digitalWrite(ledPin, LOW);
 String request = client1.readStringUntil('\r');
 Serial.println("********************************");
 Serial.println("From the station: " + request);
 client1.flush();
 Serial.print("Byte sent to the station: ");
 Serial.println(client1.println(request + "ca" + "\r"));
 digitalWrite(ledPin, HIGH);

}