當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino WiFi101 - WiFi.macAddress()用法及代碼示例

說明

獲取WiFi 防護罩的 MAC 地址

用法

WiFi.macAddress(mac);

參數

mac:一個 6 字節的數組來保存 MAC 地址

返回

字節數組:6個字節代表你的盾牌的MAC地址

示例

#include <SPI.h>
#include <WiFi101.h>

char ssid[] = "yourNetwork";     // the name of your network
int status = WL_IDLE_STATUS;     // the Wifi radio's status

byte mac[6];                     // the MAC address of your Wifi shield


void setup()
{
 Serial.begin(9600);

 status = WiFi.begin(ssid);

 if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while(true);
  }
  // if you are connected, print your MAC address:
  else {
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[5],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.println(mac[0],HEX);
  }
}

void loop () {}

相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 WiFi101 - WiFi.macAddress()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。