ESP8266 not receiving data in STA mode, but works in softAP mode.

Good day,

I'm busy developing firmware for the ESP8266 module that needs to communicate with my modile app.

I use, softAP mode with IP 192.168.4.1 to pair the device to my mobile phone and my wifi network...that works fine. Then I connect to my home wifi network and get an IP address to communicate with the device but to no avail.

I can't even ping it from my laptop.

I use the module on other projects using AT commands and I have not had the same issue. Its just now that I'm using Arduino, it doesn't work.

The ESP8266 in question is running as a server that responds to requests from my mobile app.

Any Sugestions?

My Code:

#define NODEX_AP_NAME "NODEX_AP"

WiFiServer server(80);
WiFiClient client;

void WIFI_Init()
{

  WiFi.mode(WIFI_AP_STA);
  
  Serial.println("Setting up softAP.");
  result = WiFi.softAP(NODEX_AP_NAME);

  data.fields.credentialsSet = false;

  while(result == false)
  {
    Serial.print(".");
  }

  Serial.print("SoftAP set. Address: ");
  Serial.println(WiFi.softAPIP());

  EEPROM.get(address, data.rawData);

  Serial.print("\r\nSSID: ");
  Serial.print(data.fields.devSSID);

  Serial.print(" PASSWORD: ");
  Serial.print(data.fields.devPASSWORD);

  Serial.print(" NAME: ");
  Serial.print(data.fields.devNAME);
  Serial.print("\r\n");

  if(data.fields.credentialsSet)
  {
    Serial.println("Credentials where set before");

    WiFi.begin(data.fields.devSSID, data.fields.devPASSWORD);

    WiFi.begin(data.fields.devSSID, data.fields.devPASSWORD);

    Serial.println("");

    while (WiFi.status() != WL_CONNECTED) 
    {
      delay(500);
      Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");

    Serial.print(data.fields.devIP);
    Serial.print("\r\n");
  }
  else
  {
    Serial.println("No credentials yet");  
  }

  server.begin();
}

void WIFI_Tasks()
{ 
  client = server.available();

  if(client)
  {
    Serial.println("New Client");

    while(client.connected())
    {
      if(client.available())
      {
        message = client.readStringUntil('\r');
        Serial.println(message);

        WIFI_ProcessMessage();

        client.flush();
        client.stop();
      }
    }
  }
}

Did you check that your WiFi router doesn't do device isolation?

I tried some code using softAP and did not see an immediate way to connect to the network thru an AP connection.

Thanks guys for the response.

What is device isolation? And how can I possibly fix the issue?

Are there other Libraries that you would recommend that I can try?

Thanks again!

What is device isolation? And how can I possibly fix the issue?

Device isolation means that the router don't let device A see device B on the same WiFi network and vice versa. Most routers allow to disable that feature but I've seen some that have this "feature" constantly turned on.

It might help to show us the code that does not work (above code shows the version where the ESP is the access point).

Good Day

Thanks for the reply.

In the code above, under WIFI_Init(), I check if credentials where set, then if they where, I connect to the WIFI network that was configured. After the WiFi.begin(), I connect to the WiFi network successfully, and get the IP address, but I can't talk to it or even ping it for that matter.

Just some other information that might be useful, the ESP8266 that I am using is on the SONOFF Basic Switch.

Thank You Again.

Regards

I use a rather different way of setting up my connections, but let's see what we can do. if you change Serial.print(data.fields.devIP); to Serial.print(WiFi.localIP());

So i tend lto leave the WiFi.mode() out, just start up as WiFi.softAP(apname,appass); then connect to a Station (my router) using WiFi.begin(stname, stapass); and after successfully connecting using something like your

while (WiFi.status() != WL_CONNECTED)
    {
      delay(500);
      Serial.print(".");
    }

do WiFi.reconnect(); to reconnect to any device that was connected to the AP (connecting to an STA drops the AP-connection) You can determine is your Router is the issue btw by connecting to the AP and entering the STA IP-address (instead of the 192.168.4.1) because if the connection is there that IP-address will also bring you to your home page.

In the code above, under WIFI_Init(), I check if credentials where set, then if they where, I connect to the WIFI network that was configured. After the WiFi.begin(), I connect to the WiFi network successfully, and get the IP address, but I can't talk to it or even ping it for that matter.

That code doesn't compile so it's definitely no usable to help us track your problems.

Good Morning.

My apologies, I wasn't printing the IP address completely. So I was using 192.168.100.18, instead of 192.168.100.185. So it works now.

Thank you for all the help.

Regards

Jean-Pierre