#include<SPI.h>#include<Ethernet.h>// MACアドレスの定義
bytemac_address[]={0x90,0xA2,0xDa,0x0D,0xD2,0xEF};voidsetup(){// put your setup code here, to run once:
Serial.begin(9600);// DHCPサーバを用いてIPアドレス、サブネットマスク、ゲートウェイサーバ、DNSサーバを設定する。
if(Ethernet.begin(mac_address)>0){Serial.print("IP Address: ");Serial.println(Ethernet.localIP());Serial.print("Subnet Mask: ");Serial.println(Ethernet.subnetMask());Serial.print("Gateway IP Address: ");Serial.println(Ethernet.gatewayIP());Serial.print("DNS Server Address: ");Serial.println(Ethernet.dnsServerIP());}}voidloop(){// put your main code here, to run repeatedly:
}
#include<SPI.h>#include<Ethernet.h>// MACアドレスの定義
bytemac_address[]={0x90,0xA2,0xDa,0x0D,0xD2,0xEF};// IPアドレスの定義
byteIP_address[]={192,168,11,200};// DNSサーバアドレスの定義
bytedns_address[]={192,168,11,1};// ゲートウェイアドレスの定義
bytegateway_address[]={192,168,11,1};// サブネットマスクの定義
bytesubnet[]={255,255,255,0};voidsetup(){// put your setup code here, to run once:
Serial.begin(9600);// MACアドレス、IPアドレス、DNSサーバ、
// ゲートウェイサーバ、サブネットマスクを設定する。
Ethernet.begin(mac_address,IP_address,dns_address,gateway_address,subnet);Serial.print("IP Address: ");Serial.println(Ethernet.localIP());Serial.print("Subnet Mask: ");Serial.println(Ethernet.subnetMask());Serial.print("Gateway IP Address: ");Serial.println(Ethernet.gatewayIP());Serial.print("DNS Server Address: ");Serial.println(Ethernet.dnsServerIP());}voidloop(){// put your main code here, to run repeatedly:
}
#include<SPI.h>#include<Ethernet.h>bytemac_address[]={0x90,0xA2,0xDa,0x0D,0xD2,0xEF};EthernetClientclient;voidsetup(){Serial.begin(9600);if(Ethernet.begin(mac_address)==0){Serial.println("Failed to configure Ethernet using DHCP.");for(;;);}Serial.print("connecting...");if(client.connect("www.arduino.cc",80)){Serial.println("done.");// Make a HTTP request:
client.println("GET / HTTP/1.1");client.println("Host: www.arduino.cc");client.println("Connection: close");client.println();}else{Serial.println("failed.");}}voidloop(){if(client.available()){charc=client.read();Serial.print(c);}if(!client.connected()){Serial.println();Serial.println("disconnecting.");client.stop();for(;;);}}