fork download
  1. /*
  2.   Web client
  3.  
  4.  This sketch connects to a solar system inverter and takes the power output of the moment in Watt (4 chars). Then print it to serial TTL console of arduino
  5.  using an Arduino Wiznet Ethernet shield.
  6.  
  7.  Circuit:
  8.  * Ethernet shield attached to pins 10, 11, 12, 13
  9.  
  10.  created 18 Dec 2009
  11.  modified 9 Apr 2012
  12.  by David A. Mellis
  13.  
  14.  */
  15.  
  16. #include <SPI.h>
  17. #include <Ethernet.h>
  18.  
  19. // Enter a MAC address for your controller below.
  20. // Newer Ethernet shields have a MAC address printed on a sticker on the shield
  21. byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x6A, 0x23 };
  22. IPAddress server(192,168,0,55); // Solarlog 200
  23.  
  24. // Initialize the Ethernet client library
  25. // with the IP address and port of the server
  26. // that you want to connect to (port 80 is default for HTTP):
  27. EthernetClient client;
  28.  
  29. char cifra1;
  30. char cifra2;
  31. char cifra3;
  32. char cifra4;
  33. boolean finito;
  34. int delimitatore;
  35.  
  36. void setup() {
  37.  
  38.  
  39.  
  40. Serial.begin(9600);
  41.  
  42. // start the Ethernet connection:
  43. if (Ethernet.begin(mac) == 0) {
  44. Serial.println("Failed to configure Ethernet using DHCP");
  45. // no point in carrying on, so do nothing forevermore:
  46. for(;;)
  47. ;
  48. } else { Serial.println("eth0 is up and configured via dhcp."); }
  49.  
  50. delay(1000);
  51.  
  52. if (client.connect(server, 80)) {
  53. // Make a HTTP request:
  54. client.println("GET /min_day.js HTTP/1.0");
  55. client.println();
  56. }
  57.  
  58.  
  59.  
  60. }
  61.  
  62. void loop() {
  63.  
  64.  
  65.  
  66. finito = 0;
  67.  
  68. if (client.available()) {
  69. delimitatore = 0;
  70. while(finito == 0){
  71. char c = client.read();
  72. Serial.print(c);
  73. if (delimitatore==1) { cifra1=c; delimitatore++; }
  74. if (c=='|') { delimitatore++; }
  75. if ((delimitatore==2)&& (c!=';')) { cifra2=c; delimitatore++; } else { if (c==';') {finito=1;}; };
  76. if ((delimitatore==3)&& (c!=';')) { cifra3=c; delimitatore++; } else { if (c==';') {finito=1;}; };
  77. if ((delimitatore==4)&& (c!=';')) { cifra4=c; delimitatore++; } else { if (c==';') {finito=1;}; };
  78. if (delimitatore==5) {finito=1; client.stop();};
  79. }
  80. }
  81.  
  82.  
  83.  
  84. Serial.println(cifra1);
  85. Serial.println(cifra2);
  86. Serial.println(cifra3);
  87. Serial.println(cifra4);
  88. Serial.println("end");
  89.  
  90. delay (5000);
  91.  
  92. }
  93.  
  94.  
  95. text that webclient reads:
  96.  
  97. m[mi++]="03.01.13 16:50:00|6;0;6;6230;212;209;13"
  98.  
  99. expected serial output:
  100. 6
  101.  
  102.  
  103.  
  104. end
  105.  
  106.  
  107. serial output:
  108.  
  109. 6
  110. 6
  111. 6
  112. 6
  113. end
  114.  
  115. why??
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:16:17: fatal error: SPI.h: No such file or directory
compilation terminated.
stdout
Standard output is empty