极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 18797|回复: 5

[求助] 新版Ethernet w5100 r3板,如何自動抓取ip

[复制链接]
发表于 2013-10-24 08:37:47 | 显示全部楼层 |阅读模式
以前使用舊版的w5100
若是使用浮動ip
每次都要重新擷取後
重新輸入  重新燒入才能使用

聽說新版的不用手動更新ip
所以我購買了一台  新版的w5100
http://www.electronics123.net/amazon/pictures/09026-01b.jpg

請問若我是浮動ip
使用這塊模組
是否有範例code可提供
教我如何系統直接抓取更新ip
省去我每次都要重新燒錄

謝謝!!!!
回复

使用道具 举报

发表于 2013-10-24 09:55:35 | 显示全部楼层
可以参考IDE里面W5100的DHCP例子,理论上mac地址设置的和你内网的设备mac不冲突,而且是正确的mac地址,那么就能通过DHCP服务自动获得IP地址了。

  1. /*
  2.   DHCP-based IP printer

  3. This sketch uses the DHCP extensions to the Ethernet library
  4. to get an IP address via DHCP and print the address obtained.
  5. using an Arduino Wiznet Ethernet shield.

  6. Circuit:
  7. * Ethernet shield attached to pins 10, 11, 12, 13

  8. created 12 April 2011
  9. modified 9 Apr 2012
  10. by Tom Igoe

  11. */

  12. #include <SPI.h>
  13. #include <Ethernet.h>

  14. // Enter a MAC address for your controller below.
  15. // Newer Ethernet shields have a MAC address printed on a sticker on the shield
  16. byte mac[] = {  
  17.   0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

  18. // Initialize the Ethernet client library
  19. // with the IP address and port of the server
  20. // that you want to connect to (port 80 is default for HTTP):
  21. EthernetClient client;

  22. void setup() {
  23. // Open serial communications and wait for port to open:
  24.   Serial.begin(9600);
  25.   // this check is only needed on the Leonardo:
  26.    while (!Serial) {
  27.     ; // wait for serial port to connect. Needed for Leonardo only
  28.   }

  29.   // start the Ethernet connection:
  30.   if (Ethernet.begin(mac) == 0) {
  31.     Serial.println("Failed to configure Ethernet using DHCP");
  32.     // no point in carrying on, so do nothing forevermore:
  33.     for(;;)
  34.       ;
  35.   }
  36.   // print your local IP address:
  37.   Serial.print("My IP address: ");
  38.   for (byte thisByte = 0; thisByte < 4; thisByte++) {
  39.     // print the value of each byte of the IP address:
  40.     Serial.print(Ethernet.localIP()[thisByte], DEC);
  41.     Serial.print(".");
  42.   }
  43.   Serial.println();
  44. }

  45. void loop() {

  46. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2013-10-24 09:55:40 | 显示全部楼层
板卡自带样例中有DHCP,就属于自动IP匹配.原理是在私有段中逐个找,一直到找到为止.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-24 13:08:20 | 显示全部楼层
那這樣的意思
是不是插上浮動ip網路線後
不用設定ip
每次都可以連接使用了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-24 17:26:36 | 显示全部楼层
可以了,讀取arduino IDE
可以抓取到,現在的dhcp ip

但我另一個問題是
如果arduino沒接電腦的情況下
要怎麼知道  目前抓取的ip是多少
因為我要用手機輸入ip連結到web server
回复 支持 反对

使用道具 举报

发表于 2014-1-24 01:27:55 | 显示全部楼层
不好意思!前輩!想請教一下!Failed to configure Ethernet using DHCP 是指它讀取不到IP嗎!還是MAC有問題今天剛收到!一直弄不好
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-13 20:03 , Processed in 0.055245 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表