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


Arduino Ethernet - Ethernet.localIP()用法及代码示例


说明

获取Ethernet shield的IP地址。当通过 DHCP 自动分配地址时很有用。

用法

Ethernet.localIP();

参数

返回

  • IP 地址

示例

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // print your local IP address:
  Serial.println(Ethernet.localIP());

}

void loop() {

}

相关用法


注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 Ethernet - Ethernet.localIP()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。