Go Down

Topic: ESP8266 is not connecting to my router WiFi but... (Read 295 times) previous topic - next topic

madnegrete

Jun 14, 2019, 08:19 am Last Edit: Jun 15, 2019, 06:15 pm by madnegrete
Hi everyone
In order to make a Google assistant box, I just got a new esp8266 nodemcu v2 from Ali. The first thing was scanning all the available networks. Then copy and paste mine and with its password in a script to turn on and off a LED. The serial monitor will give me information about the status of the module and its address. The  problem here is that the module is not connecting to my home wifi network, so I tried connecting to my phone wifi hotspot  and it connected and works properly. I don't know what is going on with my wifi.
Thanks.

...
WMM is on.

...
From a youtube video, it works even on my lapto´s hotspot.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

const char* ssid = ".............";
const char* password = ".................";

WiFiServer server(80);

 int PinLED = 16;
 int estado = LOW;

 
void setup() {
  Serial.begin(115200);

  pinMode(PinLED,OUTPUT);
  digitalWrite(PinLED,LOW);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid,password);
  Serial.printf("\n\nConectado a la red: %s\n", WiFi.SSID().c_str());
     while (WiFi.status()!=WL_CONNECTED){
      delay(500);
      Serial.printf(".");
      }
Serial.println(".");
Serial.println("WiFi conectada");

server.begin();
Serial.println("Servidor incializado");

Serial.printf("\n\nUtiliza esta URL para conectar: http://%s/\n", WiFi.localIP().toString().c_str());
}


void loop() {

WiFiClient client = server.available();
if(!client){
  return;
  }

  Serial.println("nuevo cliente");
  while(!client.available()){
    delay(1);
    }

    String peticion = client.readStringUntil('\r');
    Serial.println(peticion);
    client.flush();

    if (peticion.indexOf('/LED=ON') !=-1)
    {estado = LOW;}
    if (peticion.indexOf('/LED=OFF') !=-1)
    {estado = HIGH;}

    digitalWrite(PinLED, estado);

    client.println("HTTP/1.1 200 OK");
    client.println("");
    client.println("");
    client.println("");
    client.println("");
    client.println("<hl align=center>CONTROL LED ");

    if(estado == HIGH)
     {client.print("<input type='image' src='https://i.imgur.com/00i0BdB.jpg' style='display:block; margin:auto' width='30%' onClick=location.href='/LED=ON'>");}
    else
     {client.print("<input type='image' src='https://i.imgur.com/uQxhFE5.jpg' style='display:block; margin:auto' width='30%' onClick=location.href='/LED=OFF'>");}
 
     client.println("</html>");
     delay(1);
     Serial.println("Peticion finalizada"); // Se finaliza la petición al cliente. Se inicializa la espera de una nueva petición.
     Serial.println("");

Riva

What frequency is your home WiFi working on? I would not expect the ESP8266 to see anything but the 2.4GHz band but maybe your Wifi needs different credentials for different bands.

Do you have MAC address filtering turned on on your router.
Are you using a static IP or DHCP to connect.
Don't PM me for help as I will ignore it.

floresta

#2
Jun 14, 2019, 03:39 pm Last Edit: Jun 14, 2019, 03:41 pm by floresta
Hi everyone
. . . The  problem here is that the module is not connecting to my home wifi network, so I tried connecting to my phone wifi hotspot  and it connected and works properly. I don't know what is going on with my wifi.
Thanks.
We don't know what is going on with your program since you didn't provide a copy.  It's pretty hard to keep an ESP8266 from connecting to a router once you have provided it with the SSID and password.

Don

madnegrete

What frequency is your home WiFi working on? I would not expect the ESP8266 to see anything but the 2.4GHz band but maybe your Wifi needs different credentials for different bands.

Do you have MAC address filtering turned on on your router.
Are you using a static IP or DHCP to connect.
My wifi is working at 2.4Ghz on chanel 9, not MAC address filtering  and using a DHCP.

Riva

My wifi is working at 2.4Ghz on chanel 9, not MAC address filtering  and using a DHCP.
What encryption system is it using and is it using IPv4 and not IPv6, as floresta says it's difficult to have the ESP chips not be able to connect to a WiFi AP.
You have not provided the code your trying (or a cut down version of it) so people can look for potential problems.
Don't PM me for help as I will ignore it.

madnegrete

What encryption system is it using and is it using IPv4 and not IPv6, as floresta says it's difficult to have the ESP chips not be able to connect to a WiFi AP.
You have not provided the code your trying (or a cut down version of it) so people can look for potential problems.

i just edited the post with the full code.

madnegrete

We don't know what is going on with your program since you didn't provide a copy.  It's pretty hard to keep an ESP8266 from connecting to a router once you have provided it with the SSID and password.

Don
Now you can look at my full code.

Riva

You really need to put your code in code tags </>
What do you get on the serial console output what you run the code?
Don't PM me for help as I will ignore it.

Go Up