felixbmmm
felixbmmm

Reputation: 412

WiFi Status 1 on ESP8266

I'm trying to connect my Arduino Uno R3 + ESP8266 to a WiFi connection, and it returned a status of 1 when I printed out WiFi.status(), does anyone now what does it really mean and what's the solution? Here's my ESP8266 code:

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

// WiFi CREDENTIALS
const char *ssid = "xxxx";
const char *password = "xxxx";

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println();
  Serial.println("Connect to: ");
  Serial.println(ssid);
}
    
void loop(){ 
  delay(5000);
  WiFi.mode(WIFI_STA);
  Serial.println();
  Serial.println("Connect to: ");
  Serial.println(ssid);
  Serial.println(WiFi.status());
  Serial.println(WL_CONNECTED);
  if (WiFi.status() != WL_CONNECTED) {
    WiFi.begin(ssid, password);
    delay(15000);
  }
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("From ESP Connected!");
  }
  else {
    Serial.println("From ESP Not Connected!");
  }
}

=== UPDATE === I've tried using my smartphone's hotspot and it worked on the first try.

Upvotes: 0

Views: 6035

Answers (2)

felixbmmm
felixbmmm

Reputation: 412

I'm not sure myself, but when I start over using the cleaner code:

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

// WiFi CREDENTIALS
const char *ssid = "xxxx";
const char *password = "xxxx";

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");
  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}


void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("From ESP Connected!");
  }
  delay(5000);
}

My gut is telling me that maybe WiFi.mode(WIFI_STA) is causing the error?

By the way, it worked already, thanks Juraj and cbalakus for the help!

Upvotes: 0

cbalakus
cbalakus

Reputation: 630

I found this in Arduino Forum. I hope it is useful for you. And status 1 means no ssid according to enum below.

typedef enum {
    WL_NO_SHIELD        = 255,   // for compatibility with WiFi Shield library
    WL_IDLE_STATUS      = 0,
    WL_NO_SSID_AVAIL    = 1,
    WL_SCAN_COMPLETED   = 2,
    WL_CONNECTED        = 3,
    WL_CONNECT_FAILED   = 4,
    WL_CONNECTION_LOST  = 5,
    WL_DISCONNECTED     = 6
} wl_status_t;

Upvotes: 1

Related Questions