极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 16853|回复: 5

[求助]关于EtherCard的webClient代码分析

[复制链接]
发表于 2012-4-19 16:31:48 | 显示全部楼层 |阅读模式

以下代码摘自EtherCard的webClient实例,主要功能是打开指定网址,
Serial.print((const char*) Ethernet::buffer + off);这一行显示服务器返回的数据。当输出一个没有任何格式的页面的时候,也返回一些服务器的信息,我的想法是过滤掉服务器的信息,看这里谁做过类似的方案。
能取得数据的话,就可以在web上面设置Arduino程序里面的参数了。
  1. //>>> The latest version of this code can be found at [url]https://github.com/jcw/[/url] !!

  2. // Demo using DHCP and DNS to perform a web client request.
  3. // 2011-06-08 <[email][email protected][/email]> [url]http://opensource.org/licenses/mit-license.php[/url]
  4. // $Id: webClient.pde 7763 2011-12-11 01:28:16Z jcw $

  5. #include <EtherCard.h>

  6. // ethernet interface mac address, must be unique on the LAN
  7. static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

  8. byte Ethernet::buffer[700];
  9. static uint32_t timer;

  10. char website[] PROGMEM = "www.google.com";

  11. // called when the client request is complete
  12. static void my_callback (byte status, word off, word len) {
  13.   Serial.println(">>>");
  14.   Ethernet::buffer[off+300] = 0;
  15.   [color=Red]Serial.print((const char*) Ethernet::buffer + off);[/color]
  16.   Serial.println("...");
  17. }

  18. void setup () {
  19.   Serial.begin(57600);
  20.   Serial.println("\n[webClient]");

  21.   if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
  22.     Serial.println( "Failed to access Ethernet controller");
  23.   if (!ether.dhcpSetup())
  24.     Serial.println("DHCP failed");

  25.   ether.printIp("IP:  ", ether.myip);
  26.   ether.printIp("GW:  ", ether.gwip);  
  27.   ether.printIp("DNS: ", ether.dnsip);  

  28.   if (!ether.dnsLookup(website))
  29.     Serial.println("DNS failed");
  30.    
  31.   ether.printIp("SRV: ", ether.hisip);
  32. }

  33. void loop () {
  34.   ether.packetLoop(ether.packetReceive());
  35.   
  36.   if (millis() > timer) {
  37.     timer = millis() + 5000;
  38.     Serial.println();
  39.     Serial.print("<<< REQ ");
  40.     ether.browseUrl(PSTR("/foo/"), "bar", website, my_callback);
  41.   }
  42. }
复制代码
回复

使用道具 举报

 楼主| 发表于 2012-4-19 16:33:10 | 显示全部楼层
附一下EtherCard的库文件,用于0023版本的。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-4-19 16:35:08 | 显示全部楼层
本帖最后由 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引脚。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-4-19 20:56:44 | 显示全部楼层
页面无任何返回值的。但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=/
回复 支持 反对

使用道具 举报

发表于 2012-5-6 22:14:31 | 显示全部楼层
loneress 发表于 2012-4-19 20:56
页面无任何返回值的。但Arduino接收到返回如信息,如果能把以下信息过虑掉就完美了。

为什么我只是端口输出 [webClient]然后就没有反应了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-5-10 12:52:14 | 显示全部楼层
可能是DHCP获取不到IP地址哦。
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-2 21:05 , Processed in 0.043016 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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