Ethernet.begin()

名称

Ethernet.begin()

説明

Ethernetライブラリとネットワーク設定を初期化する。

Arduino 1.0では、DHCPをサポートする。Ethernet.begin(mac)を適切なネットワーク設定の下で利用すると、EthernetシールドはIPアドレスを自動取得する。これは、スケッチのサイズをかなり大きくする。DHCPリースを適切に更新するためには、Ethernet.maintain()を定期的に呼び出すこと。

書式

int EthernetClass::begin(uint8_t *mac, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);

void EthernetClass::begin(uint8_t *mac, IPAddress ip);

void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns);

void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway);

void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);

引数

mac デバイスのMAC(Media Access Control)アドレス(6バイトの配列)。これは、シールドのEthernetハードウェアアドレスである。新しいArduino EthernetシールドにはそのデバイスのMACアドレスを書いたシールが貼ってある。古いシールドでは、自分で選択する。
timeoutbegin()のタイムアウト時間。
responseTimeoutDHCPサーバへの問い合わせのタイムアウト時間。
ipデバイスのIPアドレス(4バイトの配列)。
dns DNSサーバのIPアドレス。
gateway ネットワークゲートウェイのIPアドレス(4バイトの配列)。デフォルトはデバイスのIPアドレスの最後のオクテットを1にしたもの。
subnetネットワークのサブネットマスク(4バイトの配列)。デフォルトは、255.255.255.0

戻り値

DHCPを使う場合は、アドレスを確保できれば1、できなければ0.

DHCPを使わない場合は、なし。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include <SPI.h>
#include <Ethernet.h>

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
//the IP address for the shield:
byte ip[] = { 10, 0, 0, 177 };    

void setup()
{
  Ethernet.begin(mac, ip);
}

void loop () {}

訳者註

Ethernetライブラリを利用すると、Ethernetというオブジェクトが自動生成される(Serialと同じ)。

オリジナルのページ

https://www.arduino.cc/reference/en/libraries/ethernet/ethernet.begin/

最終更新日

January 7, 2024

inserted by FC2 system