Advertisement
Guest User

Untitled

a guest
Mar 14th, 2016
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2.  
  3. #include <EtherCard.h>
  4.  
  5. // Define Static IP
  6. #define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
  7. // if static use this :
  8. #if STATIC
  9. // ethernet interface ip address
  10. static byte myip[] = { 192,168,1,2 };
  11. // gateway ip address
  12. static byte gwip[] = { 192,168,1,1 };
  13. #endif
  14.  
  15. // Variables
  16. // ethernet mac address - must be unique on your network
  17. static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
  18. const char website[] PROGMEM = "192.168.2.5";
  19. byte Ethernet::buffer[700];
  20. uint32_t timer;
  21. Stash stash;
  22. int uidvalue = 1; // gone for simplicty
  23. int busyvalue = 1; // gone for simplicity
  24.  
  25.  
  26.  
  27. /*
  28. * Setup config
  29. */
  30. void setup() {
  31.  
  32. //netwerk
  33. Serial.begin(57600);
  34. Serial.println("\n[Starting up network]");
  35.  
  36. if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
  37. Serial.println( "Failed to access Ethernet controller");
  38. #if STATIC
  39. ether.staticSetup(myip, gwip);
  40. #else
  41. if (!ether.dhcpSetup())
  42. Serial.println("DHCP failed");
  43. #endif
  44.  
  45. ether.printIp("IP: ", ether.myip);
  46. ether.printIp("GW: ", ether.gwip);
  47. ether.printIp("DNS: ", ether.dnsip);
  48. }
  49. /*
  50. * Loop config
  51. */
  52.  
  53. void loop() {
  54. ether.packetLoop(ether.packetReceive());
  55. if (millis() > timer) {
  56. timer = millis() + 10000;
  57.  
  58. // generate two fake values as payload - by using a separate stash,
  59. // we can determine the size of the generated message ahead of time
  60. byte sd = stash.create();
  61. stash.print("0,");
  62. stash.println((word) millis() / 123);
  63. stash.print("1,");
  64. stash.println((word) micros() / 456);
  65. stash.save();
  66.  
  67. // generate the header with payload - note that the stash size is used,
  68. // and that a "stash descriptor" is passed in as argument using "$H"
  69. Stash::prepare(PSTR("http://192.168.2.5/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"
  70. "Host: 192.168.1.1" "\r\n"
  71. "Content-Length: $D" "\r\n"
  72. "\r\n"
  73. "$H"),stash.size(), sd);
  74.  
  75. ether.tcpSend();
  76. Serial.print("tcp package send ");Serial.println();
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement