当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Arduino WiFiNINA - WiFi.status()用法及代码示例


说明

返回连接状态。

用法

WiFi.status()

参数

  • None

返回

  • WL_CONNECTED:连接到WiFi网络时分配;
  • WL_AP_CONNECTED:当设备以接入点模式连接时分配;
  • WL_AP_LISTENING:在接入点模式下监听连接时分配;
  • WL_NO_SHIELD:当没有WiFi屏蔽存在时分配;
  • WL_NO_MODULE:与集成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 <WiFiNINA.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
  }

  // 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.cc大神的英文原创作品 WiFiNINA - WiFi.status()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。