如何解决ESP8266 中 Wifi Libary 的返回码是什么意思?
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#ifndef STASSID
#define STASSID "wlanName"
#define STAPSK "wlanPassword"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
const char* host = "api.github.com";
const int httpsPort = 443;
const char fingerprint[] PROGMEM = "5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76";
void setup() {
Serial.begin(115200);
delay(5000);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid,password);
while (true) {
delay(500);
Serial.print(WiFi.status());
}
}
void loop() {
// put your main code here,to run repeatedly:
}
如果我运行这段代码,我将得到 6 作为 Wifi.status()
的输出,并且一旦我得到 4。4 和 6 代表什么?是否已连接?我还需要知道哪些其他状态代码?
解决方法
有公开可用的文档 https://www.arduino.cc/en/Reference/WiFiStatus
Arduino 源代码是开源的。您可以浏览来源。
输入谷歌“Arduino esp8266 source github”,你可能会发现 https://github.com/esp8266/Arduino 。从那里你可以前。在上方的搜索栏中输入 WL_CONNECTED
并找到 this line of code:
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_WRONG_PASSWORD = 6,WL_DISCONNECTED = 7
} wl_status_t;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。