bportaluri / WiFiEsp

Arduino WiFi library for ESP8266 modules
GNU General Public License v3.0
550 stars 210 forks source link

Cannot connect to AP #231

Open rwb196884 opened 2 months ago

rwb196884 commented 2 months ago
#include <SoftwareSerial.h>
#include <WiFiEsp.h>

#define RX 6 // blue
#define TX 7 // black
SoftwareSerial Esp8266(RX, TX);
const char AP[] = "calleva";
const char PASS[] = "top-secret-password";

void setup() {
  Serial.begin(9600);
  Serial.println("setup..."); // ESP8266 seems to need some time.
  delay(3000);
  connect_wifi();
  connect_ap();
}

void connect_wifi() {
  while (true) {
    Serial.println("-- connect_wifi --");
    Esp8266.begin(9600);
    WiFi.init(&Esp8266);
    if (WiFi.status() == WL_NO_SHIELD) {
      blink(1); // Error 1: couldn't connect to WiFi hardware.
      delay(1000);
    } else {
      return;
    }
    Esp8266.end();
  }
}

void connect_ap() {
  int status = -1;
  while (status != WL_CONNECTED) {
    status = WiFi.begin(AP, PASS);
    Serial.print("-- connect_ap: status is ");
    Serial.println(status);
    blink(2); // Error 2: couldn't connect to WiFi AP.
    Serial.println();
  }
}

output

[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Initilization successful - 2.0.0
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Failed connecting to calleva
-- connect_ap: status is2

[WiFiEsp] Failed connecting to calleva
-- connect_ap: status is2

[WiFiEsp] Failed connecting to calleva
-- connect_ap: status is2
...