说明
返回连接状态。
用法
WiFi.status();
参数
空
返回
WL_CONNECTED:连接到WiFi网络时分配; WL_AP_CONNECTED:当设备以接入点模式连接时分配; WL_AP_LISTENING:在接入点模式下监听连接时分配; WL_NO_SHIELD:当不存在WiFi屏蔽时分配; WL_IDLE_STATUS:它是WiFi时分配的临时状态。begin()被调用并保持活动状态,直到尝试次数到期(导致WL_CONNECT_FAILED)或建立连接(导致WL_CONNECTED); WL_NO_SSID_AVAIL:当没有SSID可用时分配; WL_SCAN_COMPLETED:扫描网络完成时分配; WL_CONNECT_FAILED:在所有尝试连接失败时分配; WL_CONNECTION_LOST:连接丢失时赋值; WL_DISCONNECTED:断开网络时分配;
示例
#include <SPI.h>
#include <WiFi101.h>
char ssid[] = "yourNetwork"; // your network SSID (name)
char key[] = "D0D0DEADF00DABBADEAFBEADED"; // your network key
int keyIndex = 0; // your network key Index number
int status = WL_IDLE_STATUS; // the Wifi radio's status
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WEP network, SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, keyIndex, key);
// wait 10 seconds for connection:
delay(10000);
}
// once you are connected :
Serial.print("You're connected to the network");
}
void loop() {
// check the network status connection once every 10 seconds:
delay(10000);
Serial.println(WiFi.status());
}
相关用法
- Arduino WiFi101 - WiFi.subnetMask()用法及代码示例
- Arduino WiFi101 - WiFi.setDNS()用法及代码示例
- Arduino WiFi101 - WiFi.scanNetworks()用法及代码示例
- Arduino WiFi101 - WiFi.config()用法及代码示例
- Arduino WiFi101 - WiFi.localIP()用法及代码示例
- Arduino WiFi101 - WiFi.SSID()用法及代码示例
- Arduino WiFi101 - WiFi.macAddress()用法及代码示例
- Arduino WiFi101 - WiFi.beginAP()用法及代码示例
- Arduino WiFi101 - WiFi.RSSI()用法及代码示例
- Arduino WiFi101 - WiFi.beginProvision()用法及代码示例
- Arduino WiFi101 - WiFi.BSSID()用法及代码示例
- Arduino WiFi101 - WiFi.begin()用法及代码示例
- Arduino WiFi101 - WiFi.gatewayIP()用法及代码示例
- Arduino WiFi101 - WiFi.ping()用法及代码示例
- Arduino WiFi101 - WiFi.encryptionType()用法及代码示例
- Arduino WiFi101 - WiFiSSLClient()用法及代码示例
- Arduino WiFi101 - WiFiClient用法及代码示例
- Arduino WiFi101 - WiFiServer()用法及代码示例
- Arduino WiFi101 - ConnectSSL()用法及代码示例
- Arduino WiFi101 - connect()用法及代码示例
- Arduino WiFi101 - connected()用法及代码示例
- Arduino WiFi101OTA - WiFiOTA.begin()用法及代码示例
- Arduino WiFi101OTA - WiFiOTA.poll()用法及代码示例
- Arduino WiFiNINA - WiFi.config()用法及代码示例
- Arduino WiFiNINA - server.status()用法及代码示例
注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 WiFi101 - WiFi.status()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。