fork download
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. // Update these with values suitable for your network.
  5. byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
  6. byte ip[] = { 192, 168, 1, 100 };
  7. byte dns[] = { 192, 168, 1, 1 };
  8. byte gateway[] = { 192, 168, 1, 1 };
  9. char server[] = "agnosthings.com";
  10. EthernetClient ethClient;
  11.  
  12. // set variabel pin untuk led
  13. const int ledPin = 13;
  14.  
  15. void setup()
  16. {
  17. // reset network
  18. system("ifdown eth0");
  19. system("ifup eth0");
  20. delay(2000);
  21.  
  22. // connecting network
  23. Serial.begin(9600);
  24. Serial.println("connecting...");
  25. if (Ethernet.begin(mac) != 1) {
  26. Ethernet.begin(mac,ip);
  27. }
  28. delay(1000);
  29. Serial.print("Running on: ");
  30. Serial.println(Ethernet.localIP());
  31.  
  32. // initialing LED PIN as Output
  33. pinMode(ledPin, OUTPUT);
  34. digitalWrite(ledPin, LOW);
  35. }
  36.  
  37. void loop()
  38. {
  39. // send request
  40. // change link with your own link
  41. boolean requestStatus = httpRequest("/bc0dfdba-f5be-11e5-8001-XXXXXXXXXXXX/field/last/feed/00/led");
  42. if(requestStatus == true){
  43.  
  44. // if there's incoming data from the net connection.
  45. // send it out the serial port. This is for debugging
  46. // purposes only:
  47. while(ethClient.available())
  48. {
  49. // read data from server
  50. String line = ethClient.readString();
  51. Serial.println(line);
  52.  
  53. // Turn On LED while data is On
  54. if (line.indexOf("value\":\"on") != -1) {
  55. Serial.println("Turn On LED");
  56. digitalWrite(ledPin, HIGH);
  57. }
  58.  
  59. // Turn Off LED while data is not On
  60. else {
  61. Serial.println("Turn Off LED");
  62. digitalWrite(ledPin, LOW);
  63. }
  64. }
  65.  
  66. } // end if requestStatus
  67.  
  68. // close any connection before send a new request.
  69. // This will free the socket on the Ethernet shield
  70. ethClient.stop();
  71. delay(1000);
  72. }
  73.  
  74. boolean httpRequest(String link) {
  75. // if you get a connection, report back via serial:
  76. Serial.println("Reading data from server");
  77. if (ethClient.connect(server, 80)) {
  78. // Make a HTTP request:
  79. ethClient.println("GET " + link + " HTTP/1.0");
  80. ethClient.println("Host: agnosthings.com");
  81. ethClient.println();
  82. return true;
  83. } else {
  84. // You couldn't make the connection
  85. Serial.println("Connection Failed");
  86. ethClient.stop();
  87. return false;
  88. }
  89. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:10: fatal error: 'SPI.h' file not found
#include <SPI.h>
         ^
1 error generated.
stdout
Standard output is empty