W5100使用静态IP的方式
#include "SPI.h"
#include "Ethernet.h"
byte myMac[] = {0x88, 0x80, 0x22, 0x19, 0x00, 0x01}; //初始化MAC(Media Access Control)地址
byte myIp[] = {10, 5, 103, 28}; // 或者使用类,注意括弧不同:IPAddress myIp(10, 5, 103, 28);
byte myDns[] = {202, 204, 24, 35}; //dns
byte myGateway[] = {10, 5, 103, 1}; //网关
byte mySubnet[] = {255, 255, 255, 0}; //子网掩码
void setup()
{
Serial.begin(9600);
Ethernet.begin(myMac, myIp, myDns, myGateway, mySubnet);
//第一种打印方式
Serial.print("My IP address-1: ");
Serial.println(Ethernet.localIP());
//第二种打印方式
Serial.print("My IP address-2: ");
for (byte i = 0; i < 4; i++)
{
Serial.print(Ethernet.localIP()[i], DEC);
if (i != 3)
{
Serial.print(".");
}
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while (true);
}
}
