ESP8266 上的 WiFi 状态 1
WiFi Status 1 on ESP8266
我正在尝试将我的 Arduino Uno R3 + ESP8266 连接到 WiFi 连接,当我打印出来时它返回状态 1 WiFi.status()
,现在有人知道它的真正含义是什么吗?解决方案?这是我的 ESP8266 代码:
#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!");
}
}
===更新===
我试过使用智能手机的热点,第一次就成功了。
我在 Arduino 论坛上找到了 this。我希望它对你有用。根据下面的枚举,状态 1 表示没有 ssid。
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;
我自己也不确定,但是当我重新开始使用更简洁的代码时:
#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);
}
我的直觉告诉我可能 WiFi.mode(WIFI_STA)
导致了错误?
顺便说一下,它已经成功了,感谢 Juraj 和 cbalakus 的帮助!
我正在尝试将我的 Arduino Uno R3 + ESP8266 连接到 WiFi 连接,当我打印出来时它返回状态 1 WiFi.status()
,现在有人知道它的真正含义是什么吗?解决方案?这是我的 ESP8266 代码:
#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!");
}
}
===更新=== 我试过使用智能手机的热点,第一次就成功了。
我在 Arduino 论坛上找到了 this。我希望它对你有用。根据下面的枚举,状态 1 表示没有 ssid。
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;
我自己也不确定,但是当我重新开始使用更简洁的代码时:
#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);
}
我的直觉告诉我可能 WiFi.mode(WIFI_STA)
导致了错误?
顺便说一下,它已经成功了,感谢 Juraj 和 cbalakus 的帮助!