View difference between Paste ID: kXdchwYd and x5SuWRqE
SHOW: | | - or go back to the newest paste.
1
// Demo using DHCP and DNS to perform a web client request.
2
// 2011-06-08 <[email protected]> http://opensource.org/licenses/mit-license.php
3
4
#include <EtherCard.h>
5
6
// ethernet interface mac address, must be unique on the LAN
7
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
8
9
byte Ethernet::buffer[700];
10
static uint32_t timer;
11
12
const char website[] PROGMEM = "www.yoerik.com";
13
14
// called when the client request is complete
15
static void my_callback (byte status, word off, word len) {
16
  Serial.println(">>>");
17
  Ethernet::buffer[off+600] = 0;
18
  
19
  
20
  //String potato = tomato.substring(260);
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.persistTcpConnection(true);
52
    ether.browseUrl(PSTR("/cooking/"), "barcode.php?bar=0013800102010&power=700", website, my_callback);
53
  }
54
}