Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. // This demo does web requests via DNS lookup, using a fixed gateway.
  2. // 2010-11-27 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
  3.  
  4. #include <EtherCard.h>
  5.  
  6. // ethernet interface mac address
  7. static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
  8. // ethernet interface ip address
  9. static byte myip[] = { 10,250,0,218 };
  10. // gateway ip address
  11. static byte gwip[] = { 10,250,0,254 };
  12. //dns
  13. static byte dns[] = { 10,250,0,2 };
  14. // remote website name
  15. const char website[] PROGMEM = "hexium-automation.lan.timstallard.me.uk";
  16.  
  17. byte Ethernet::buffer[300]; // a very small tcp/ip buffer is enough here
  18.  
  19. boolean button5 = 0;
  20. boolean button6 = 0;
  21. boolean button7 = 0;
  22. static long timer;
  23.  
  24. // called when the client request is complete
  25. static void my_result_cb (byte status, word off, word len) {
  26. Serial.print("<<< reply ");
  27. Serial.println((const char*) Ethernet::buffer + off);
  28. }
  29.  
  30. void setup () {
  31. Serial.begin(57600);
  32. Serial.println("\n[getViaDNS]");
  33.  
  34. if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
  35. Serial.println( "Failed to access Ethernet controller");
  36.  
  37. ether.staticSetup(myip, gwip, dns);
  38.  
  39. if (!ether.dnsLookup(website))
  40. Serial.println("DNS failed");
  41. ether.printIp("Server: ", ether.hisip);
  42.  
  43. pinMode(5, INPUT_PULLUP);
  44. pinMode(6, INPUT_PULLUP);
  45. pinMode(7, INPUT_PULLUP);
  46. }
  47.  
  48. void loop () {
  49. ether.packetLoop(ether.packetReceive());
  50. if(millis() > timer + 1000){
  51. if(digitalRead(5) == LOW){
  52. if(button5 == 0){
  53. button5 = 1;
  54. Serial.println("Awake");
  55. timer = millis();
  56. ether.browseUrl(PSTR("/completeaction.php"), "?module=Scheduler&action=Awake", website, my_result_cb);
  57. }
  58. }
  59. else
  60. {
  61. button5 = 0;
  62. }
  63. if(digitalRead(6) == LOW){
  64. if(button6 == 0){
  65. button6 = 1;
  66. Serial.println("Arrived");
  67. timer = millis();
  68. ether.browseUrl(PSTR("/completeaction.php"), "?module=Scheduler&action=Arrived", website, my_result_cb);
  69. }
  70. }
  71. else
  72. {
  73. button6 = 0 ;
  74. }
  75.  
  76. if(digitalRead(7) == LOW){
  77. if(button7 == 0){
  78. button7 = 1;
  79. Serial.println("Leaving");
  80. timer = millis();
  81. ether.browseUrl(PSTR("/completeaction.php"), "?module=Scheduler&action=Leaving", website, my_result_cb);
  82. }
  83. }
  84. else
  85. {
  86. button7 = 0;
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement