EDABOSS电子论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 924|回复: 0

[转帖] 关于EtherCard的webClient代码分析

[复制链接]

28

主题

4

回帖

300

E币

技术员

Rank: 2

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

02.

03.// Demo using DHCP and DNS to perform a web client request.

04.// 2011-06-08 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php

05.// $Id: webClient.pde 7763 2011-12-11 01:28:16Z jcw $

06.

07.#include <EtherCard.h>

08.

09.// ethernet interface mac address, must be unique on the LAN

10.static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

11.

12.byte Ethernet::buffer[700];

13.static uint32_t timer;

14.

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

16.

17.// called when the client request is complete

18.static void my_callback (byte status, word off, word len) {

19.  Serial.println(">>>");

20.  Ethernet::buffer[off+300] = 0;

21.  Serial.print((const char*) Ethernet::buffer + off);

22.  Serial.println("...");

23.}

24.

25.void setup () {

26.  Serial.begin(57600);

27.  Serial.println("\n[webClient]");

28.

29.  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)

30.    Serial.println( "Failed to access Ethernet controller");

31.  if (!ether.dhcpSetup())

32.    Serial.println("DHCP failed");

33.

34.  ether.printIp("IP:  ", ether.myip);

35.  ether.printIp("GW:  ", ether.gwip);  

36.  ether.printIp("DNS: ", ether.dnsip);  

37.

38.  if (!ether.dnsLookup(website))

39.    Serial.println("DNS failed");

40.

41.  ether.printIp("SRV: ", ether.hisip);

42.}

43.

44.void loop () {

45.  ether.packetLoop(ether.packetReceive());

46.

47.  if (millis() > timer) {

48.    timer = millis() + 5000;

49.    Serial.println();

50.    Serial.print("<<< REQ ");

51.    ether.browseUrl(PSTR("/foo/"), "bar", website, my_callback);

52.  }

53.}
积分规则
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|EDABOSS电子论坛

GMT+8, 2024-4-24 08:10 , Processed in 0.036727 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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