Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By metalpatriot
#56374 Greeting, I´m new with the use of the esp8266 been working with for about a week now, i´m working with a project where two esp(for now, later more modules will be aded) need to share data, successfully connected one working as client to the AP but this last one never seems to detect when the client is connected, it probably is a little detail in the code but i hope someone can guide me here. I'll leave the code for the two esp modules i´m using.


This is the one working as a station altough both esp are configured as AP and STA because i´ll need them to change roles later. This esp connects with succes and it prints a confirmation in the serial monitor.

Code: Select all//ENTREGA MENSAJE(07)                                                                                                   
#include <ESP8266WiFi.h>

char bandera;
WiFiServer  Nserver(9001);
WiFiClient  Nclient;
 
void setup() {
    Serial.begin(115200);
    WiFi.disconnect();
    WiFi.mode(WIFI_AP_STA); //access point y estación
    WiFi.softAP("modulo_01"); //nombre del AP
    Nserver.begin();
    WiFi.begin("modulo_07","",9001);

}

void loop() {
 
    while(WiFi.status() != WL_CONNECTED){ //see if it connected
    Serial.println("no connected");
    delay(1000);
    }
    while(WiFi.status() == WL_CONNECTED){
    Serial.println("connected");
    Nclient.println('1');
    Serial.println("bandera send :1");
    delay(1000); 
    }
}



And this is the one working as an AP, it never seem to detect the client when it connects and keeps printing in the monitor "no client"

Code: Select all//RECIBE MENSAJE(01)
#include <ESP8266WiFi.h>

char bandera;
WiFiServer  Nserver(9001);
WiFiClient  Nclient;
 
void setup() {
    Serial.begin(115200);
    WiFi.disconnect();
    WiFi.mode(WIFI_AP_STA); //access point y estación
    WiFi.softAP("modulo_07"); //nombre del AP
    Nserver.begin();
   

}

void loop() {
   
    if(Nclient){
    WiFiClient Nclient = Nserver.available();
    Serial.println("client connected");
      if(Nclient.available()){
      bandera = Nclient.read();
      Serial.println(bandera);
      Serial.println("bandera received : 1");
      }
    }
    else{
       Serial.println("no client");
    delay(500);
    }
     
}
User avatar
By martinayotte
#56419 Your Nclient is global object but never initialized, so the "if(Nclient){" will never become true.
Also, inside your "if", you declared a local object "WiFiClient Nclient = Nserver.available();" which is not good, it should be assigned to the existing global one.