Hi,
My Ethernet shield is based on Enc28j60. I downloaded the special lib and made the replacements so that to use the code example coming with IDE. I got to a problem explained here. No ip addressing issue exists.
Final project goal:
A Java client socket running on pc, contacts the server socket of Arduino to update the servo position.
Code modification:
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0, 7 };
Server server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
}
void loop()
{
Client client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print("received: ");
Serial.print(c);
Serial.println();
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("Arduino Ethernet is alive...");
client.println();
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}
Now what happens is that when I address http://192.168.0.7, I have a long long wait, then nothing comes out. On Serial window I receive "GET /..." as expected, but then I continue to receive unknown characters which are printed as squares.
Pinging the Arduino+Ethernet circuit and all other experiments prove that connection is ok (0% loss).
Now if I change the code like:
if (c == '\n' && currentLineIsBlank || c=='G')
that is:
...
if (c == '\n' && currentLineIsBlank || c=='G') {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("Arduino Ethernet is alive...");
client.println();
break;
}
...
which makes the if part to happen right after it receives 'Get/...' from the browser call and not to wait for the '\n' from the browser, again after a wait - but not as long as before - I get the magical "Arduino Ethernet is alive..." there on the browser and continue to receive those strange squares on serial window.
Please tell me what is the problem and how to deal with those squares?