|
以下代码摘自EtherCard的webClient实例,主要功能是打开指定网址,
Serial.print((const char*) Ethernet::buffer + off);这一行显示服务器返回的数据。当输出一个没有任何格式的页面的时候,也返回一些服务器的信息,我的想法是过滤掉服务器的信息,看这里谁做过类似的方案。
能取得数据的话,就可以在web上面设置Arduino程序里面的参数了。- //>>> The latest version of this code can be found at [url]https://github.com/jcw/[/url] !!
- // Demo using DHCP and DNS to perform a web client request.
- // 2011-06-08 <[email][email protected][/email]> [url]http://opensource.org/licenses/mit-license.php[/url]
- // $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[700];
- 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[off+300] = 0;
- [color=Red]Serial.print((const char*) Ethernet::buffer + off);[/color]
- Serial.println("...");
- }
- void setup () {
- Serial.begin(57600);
- Serial.println("\n[webClient]");
- 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);
- }
- }
复制代码 |
|