fork download
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. // Update these with values suitable for your network.
  5. byte mac[] = { 0x98, 0x4F, 0xEE, 0x00, 0x70, 0x32 };
  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 & value sensor
  13. const int pinSensorSuhu = A0;
  14. int sensorSuhu = 0;
  15.  
  16. void setup()
  17. {
  18. // Reset connection
  19. system("ifdown eth0");
  20. system("ifup eth0");
  21. delay(2000);
  22.  
  23. // connecting network
  24. Serial.begin(9600);
  25. Serial.println("connecting...");
  26. if (Ethernet.begin(mac) != 1) {
  27. Ethernet.begin(mac, ip, dns, gateway);
  28. }
  29. delay(1000);
  30. Serial.print("Running on: ");
  31. Serial.println(Ethernet.localIP());
  32. }
  33.  
  34. void loop()
  35. {
  36. // read the analog in value:
  37. // map it to the range of the analog out:
  38. sensorSuhu = map(analogRead(pinSensorSuhu), 0, 1023, 0, 100);
  39.  
  40. // ganti dengan URL API Push Feed punyamu sendiri
  41. String url_api = "/bc0dfdba-f5be-11e5-8001-xxxxxxxxxxxx/feed?push=led={v_led},sensor={v_sensor}";
  42. url_api.replace("{v_led}", "");
  43. url_api.replace("{v_sensor}", String(sensorSuhu));
  44. Serial.println("Sensor Suhu: "+String(sensorSuhu));
  45.  
  46. boolean requestStatus = httpRequest(url_api);
  47. if(requestStatus == true)
  48. Serial.println("Sending data success!");
  49. else
  50. Serial.println("Sending data failed!");
  51. Serial.println();
  52.  
  53. // close any connection before send a new request.
  54. // This will free the socket on the Ethernet shield
  55. ethClient.stop();
  56. delay(1000);
  57. }
  58.  
  59. boolean httpRequest(String link) {
  60. // if you get a connection, report back via serial:
  61. Serial.println("Push data to server");
  62. if (ethClient.connect(server, 80)) {
  63. // Make a HTTP request:
  64. ethClient.println("GET " + link + " HTTP/1.0");
  65. ethClient.println("Host: agnosthings.com");
  66. ethClient.println();
  67. return true;
  68. } else {
  69. // You couldn't make the connection
  70. Serial.println("Connection Failed");
  71. ethClient.stop();
  72. return false;
  73. }
  74. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:17: fatal error: SPI.h: No such file or directory
compilation terminated.
stdout
Standard output is empty