Advertisement
Guest User

Arduino Webclient

a guest
Aug 30th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <EtherCard.h>
  2.  
  3. // ethernet interface mac address, must be unique on the LAN
  4. static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
  5.  
  6. byte Ethernet::buffer[700];
  7. static uint32_t timer;
  8.  
  9. const char website[] PROGMEM = "www.japseyz.com";
  10.  
  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.   Serial.print((const char*) Ethernet::buffer + off);
  16.   Serial.println("...");
  17. }
  18.  
  19. void setup () {
  20.   Serial.begin(57600);
  21.   Serial.println(F("\n[webClient]"));
  22.  
  23.   if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
  24.     Serial.println(F("Failed to access Ethernet controller"));
  25.   if (!ether.dhcpSetup())
  26.     Serial.println(F("DHCP failed"));
  27.  
  28.   ether.printIp("IP:  ", ether.myip);
  29.   ether.printIp("GW:  ", ether.gwip);  
  30.   ether.printIp("DNS: ", ether.dnsip);  
  31.  
  32.   if (!ether.dnsLookup(website))
  33.     Serial.println("DNS failed");
  34.    
  35.   ether.printIp("SRV: ", ether.hisip);
  36. }
  37.  
  38. void loop () {
  39.   ether.packetLoop(ether.packetReceive());
  40.  
  41.   if (millis() > timer) {
  42.     timer = millis() + 5000;
  43.     Serial.println();
  44.     Serial.print("<<< REQ ");
  45.     ether.browseUrl(PSTR(""), "/arduino.php", website, my_callback);
  46.   }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement