基础工作:W5100扩展板插在ARDUINO上。用网线把W5100和自己家的路由器连接。插上网线能看到侧面网口指示灯变亮。路由器开启DHCP服务(一般都是开启的)。

1.打开官方例程里面的Ethernet->WebClient

2.修改里面的谷歌服务器为百度的。

3.修改IP地址为本地的局域网号码段,比如你的电脑是192.168.1.100。那么设置你的w5100,也在192.168.1.x。后面的x不能与局域网内的其它设备重复。

4.下载代码,看效果。

 /*
Web client This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield. Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen */ #include <SPI.h>
#include <Ethernet.h> // Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "www.baidu.com"; // name address for Google (using DNS) // Set the static IP address to use if the DHCP fails to assign
IPAddress ip(,,,); // Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client; void setup() {
// Open serial communications and wait for port to open:
Serial.begin();
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
} // start the Ethernet connection:
if (Ethernet.begin(mac) == ) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay();
Serial.println("connecting..."); // if you get a connection, report back via serial:
if (client.connect(server, )) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.1");
client.println("Host: www.baidu.com");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
} void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
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);
}
}

能显示服务器返回的数据,证明通讯成功。

最新文章

  1. NodeJS 错误处理最佳实践
  2. java集合-HashTable
  3. 如何使Python完美升级到新版本
  4. window.open()&amp;&amp;window.showmodaldialog()
  5. HTML 的 &lt;div&gt; 和 &lt;span&gt; 标签
  6. Magento架构师的笔记-----Magento显示当前目录的父分类和子分类的分类名
  7. html 5新特性 --用SVG绘制的微信logo
  8. JS拖拽原理
  9. Android下调用收发短信邮件等
  10. OC第四课
  11. .NET开源项目 TOP 25
  12. hibernate中SQLQuery的addEntity()方法
  13. jvm系列(七):jvm调优-工具篇
  14. UPS对电源故障的处理能力
  15. 【转】Entity Framework 5.0系列之自动生成Code First代码
  16. 更改checkbox样式css
  17. C#自定义控件、用户控件、动态加载菜单按钮
  18. JAVA正确地自定义比较对象---如何重写equals方法和hashCode方法
  19. 007-优化web请求三-异步调用【WebAsyncTask】
  20. 通过 Java 线程堆栈进行性能瓶颈分析

热门文章

  1. C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用 &amp;amp;&amp;amp; 并查集方法)
  2. JavaScript Array pop(),shift()函数
  3. MySQL + Amoeba 负载均衡、主从备份方案
  4. 第九节: 利用RemoteScheduler实现Sheduler的远程控制 第八节: Quartz.Net五大构件之SimpleThreadPool及其四种配置方案 第六节: 六类Calander处理六种不同的时间场景 第五节: Quartz.Net五大构件之Trigger的四大触发类 第三节: Quartz.Net五大构件之Scheduler(创建、封装、基本方法等)和Job(创建、关联
  5. 第二章:核心C#
  6. IE hack 条件语句
  7. Android View中getViewTreeObserver().addOnGlobalLayoutListener() (转)
  8. 【hiho一下】第一周 最长回文子串
  9. python入门课程 第3章 Python变量和数据类型
  10. Lumen开发:添加手机验证,中文验证与Validator验证的“半个”生命周期