Arduino W5100排错
试了几天的W5100模块,做本地server正常,但是以web client模式运行时,总是连接失败,更换几台电脑以及arduino IDE版本,都是这个问题,后来才发现是MAC地址冲突,更改之后正常。
1 /* 2 Web client 3 4 This sketch connects to a website (http://www.google.com) 5 using an Arduino Wiznet Ethernet shield. 6 7 Circuit: 8 * Ethernet shield attached to pins 10, 11, 12, 13 9 10 created 18 Dec 2009 11 by David A. Mellis 12 13 */ 14 15 #include <SPI.h> 16 #include <Ethernet.h> 17 18 // Enter a MAC address and IP address for your controller below. 19 // The IP address will be dependent on your local network: 20 byte mac[] = { 21 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }; 22 byte ip[] = { 23 192,168,1,177 }; 24 byte server[] = { 25 203,208,36,20}; // Google 26 27 // Initialize the Ethernet client library 28 // with the IP address and port of the server 29 // that you want to connect to (port 80 is default for HTTP): 30 Client client(server, 80); 31 32 void setup() { 33 // start the Ethernet connection: 34 Ethernet.begin(mac, ip); 35 // start the serial library: 36 Serial.begin(9600); 37 // give the Ethernet shield a second to initialize: 38 delay(1000); 39 Serial.println("connecting..."); 40 41 // if you get a connection, report back via serial: 42 if (client.connect()) { 43 Serial.println("connected"); 44 // Make a HTTP request: 45 client.println("GET /search?q=arduino HTTP/1.0"); 46 client.println(); 47 } 48 else { 49 // kf you didn't get a connection to the server: 50 Serial.println("connection failed"); 51 } 52 } 53 54 void loop() 55 { 56 if (client.available()) { 57 char c = client.read(); 58 Serial.print(c); 59 } 60 }
上面的google ip地址通过nslookup获得。
返回的结果是
connecting... connected HTTP/1.0 302 Found Location: http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q=http://www.google.com.hk/search%3Fq%3Darduino&ust=1364544912341937&usg=AFQjCNFj1fSI9ED_CL0COWIPK91qxDpCiQ Cache-Control: private Content-Type: text/html; charset=UTF-8 Set-Cookie: PREF=ID=2e6ecd05dee87fb8:FF=0:NW=1:TM=1364544882:LM=1364544882:S=OnU-EIEfNhz0bbsG; expires=Sun, 29-Mar-2015 08:14:42 GMT; path=/; domain=.google.com Date: Fri, 29 Mar 2013 08:14:42 GMT Server: gws Content-Length: 396 X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> The document has moved <A HREF="http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q=http://www.google.com.hk/search%3Fq%3Darduino&ust=1364544912341937&usg=AFQjCNFj1fSI9ED_CL0COWIPK91qxDpCiQ">here</A>. </BODY></HTML>
浙公网安备 33010602011771号