让我们一起爱米兰
站内搜搜:
移动设备
请扫描二维码
或访问
m.milan100.com
您所在的位置 -> 米兰百分百 -> arduino -> arduino+W5100使用静态IP的方式

arduino+W5100使用静态IP的方式

点击数:1088 发表时间:2016-06-02 10:31:15 作者: 来源链接:
分享到:
分享到微信

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);
  }
}


0
很 好
0
一 般
0
差 劲
热门新闻
相关文章
上一篇: DFPlayer Mini模块(MP3-TF-16P)与arduino使用方法
下一篇: Arduino 与 Raspberry Pi(树莓派)的内存及性能对比
评论区
匿名

返回首页 | 收藏本页 | 回到顶部
Copyright 2010. 米兰百分百 Powered By Bridge.
京ICP备15050557号