IPAddress()

名称

IPAddress()

説明

IPアドレスを定義する。ローカルIPアドレス・リモートIPアドレス双方の宣言に利用できる。

書式

IPAddress.IPAddress();

IPAddress.IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);

IPAddress.IPAddress(uint32_t address);

IPAddress.IPAddress(const uint8_t *address);

引数

first_octet, second_octet, third_octet, fourth_octetアドレスを表すコンマ区切りのリスト(4バイトで、例えば、192, 168, 1, 1)。
addressIPアドレス。

戻り値

なし(この関数はコンストラクタ)。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <SPI.h>
#include <Ethernet.h>

// network configuration. dns server, gateway and subnet are optional.

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

// the dns server ip
IPAddress dnServer(192, 168, 0, 1);
// the router's gateway address:
IPAddress gateway(192, 168, 0, 1);
// the subnet:
IPAddress subnet(255, 255, 255, 0);

//the IP address is dependent on your network
IPAddress ip(192, 168, 0, 2);

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

  // initialize the ethernet device
  Ethernet.begin(mac, ip, dnServer, gateway, subnet);
  //print out the IP address
  Serial.print("IP = ");
  Serial.println(Ethernet.localIP());
}

void loop() {
}

訳者註

この関数(クラス)は、Ethernetライブラリの一部ではなく、coreに含まれる。

オリジナルのページ

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

最終更新日

January 7, 2024

inserted by FC2 system