Pages: [1]   Go Down
Author Topic: Ethernet webserver example, problem  (Read 330 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 301
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
#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:

Code:

...

        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?
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 175
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think use wrong library the library Ethernet.h is for Wiznet 5100...for ENC28J60 is another library you can find it google nuelectronics....i think
Logged

Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

Offline Offline
Full Member
***
Karma: 2
Posts: 175
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The ethernet card ENC28J60 need restart every 15 minutes,i made an external circuit with I.C timer 555 for this problem....the wiznet w5100 never need restart is better.... with easy code...
Logged

Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

UK
Offline Offline
God Member
*****
Karma: 13
Posts: 903
Twitter: @simonmonk2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This may or may not help.

http://srmonk.blogspot.com/2010/03/simplified-ethernet-library-for-28j60.html

I haven't got around to updating it to Arduino 1.0 yet.
Logged

--
My New Arduino Book: http://www.arduinobook.com

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 301
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it's not an issue of lib type

I explicitly wrote enc28j60 to point to that I'm using the right lib.

Also, if it was the case, in no way I could get any kind of output on the browser (it didn't work at all), but I get the right response but not the ideal way.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 301
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This may or may not help.

http://srmonk.blogspot.com/2010/03/simplified-ethernet-library-for-28j60.html

I haven't got around to updating it to Arduino 1.0 yet.

Thank you very much, this was exactly what I needed, no more checking like "c=='\n'", very nice methods provided smiley

Logged

Pages: [1]   Go Up
Jump to: