[求助]关于EtherCard的webClient代码分析
以下代码摘自EtherCard的webClient实例,主要功能是打开指定网址,
Serial.print((const char*) Ethernet::buffer + off);这一行显示服务器返回的数据。当输出一个没有任何格式的页面的时候,也返回一些服务器的信息,我的想法是过滤掉服务器的信息,看这里谁做过类似的方案。
能取得数据的话,就可以在web上面设置Arduino程序里面的参数了。//>>> The latest version of this code can be found at https://github.com/jcw/ !!
// Demo using DHCP and DNS to perform a web client request.
// 2011-06-08 <[email protected]> http://opensource.org/licenses/mit-license.php
// $Id: webClient.pde 7763 2011-12-11 01:28:16Z jcw $
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer;
static uint32_t timer;
char website[] PROGMEM = "www.google.com";
// called when the client request is complete
static void my_callback (byte status, word off, word len) {
Serial.println(">>>");
Ethernet::buffer = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println("...");
}
void setup () {
Serial.begin(57600);
Serial.println("\n");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP:", ether.myip);
ether.printIp("GW:", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 5000;
Serial.println();
Serial.print("<<< REQ ");
ether.browseUrl(PSTR("/foo/"), "bar", website, my_callback);
}
} 附一下EtherCard的库文件,用于0023版本的。 本帖最后由 loneress 于 2012-4-19 21:46 编辑
管脚定义在enc28j60.cpp里面。
const byte SPI_SS = 10;
const byte SPI_MOSI = 11;
const byte SPI_MISO = 12;
const byte SPI_SCK= 13;
记得要接RST引脚。 页面无任何返回值的。但Arduino接收到返回如信息,如果能把以下信息过虑掉就完美了。
HTTP/1.1 200 OK
Cache-Control: private
Connection: close
Date: Thu, 19 Apr 2012 12:55:01 GMT
Content-Length: 0
Content-Type: text/html
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Set-Cookie: ASPSESSIONIDAQARQQRA=DNFIBJODFMKIANIJJKPDFECO; path=/
loneress 发表于 2012-4-19 20:56 static/image/common/back.gif
页面无任何返回值的。但Arduino接收到返回如信息,如果能把以下信息过虑掉就完美了。
为什么我只是端口输出 然后就没有反应了 可能是DHCP获取不到IP地址哦。
页:
[1]