Go Down

Topic: EthernetShield + Webserver on a NAS in my LAN (Read 3 times) previous topic - next topic

juekr

Hey there!

I ran into a weird problem:

I played around with arduino, the etherned shield a a lcd module. All seems all to be wired correctly - at least everythings works fine in some cases. I followed the EthernetClient example that came with the Ethernet class to have the arduino connect to a webserver. Everything seems to work fine as long as the webserver that I'm trying to reach is outside of my home network. But connecting to the webserver that is running on my Buffalo Linkstation NAS always fails. The code I use:

Code: [Select]
#include <LiquidCrystal.h>
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xDF, 0xAE, 0xED }; 
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);
byte server[] = { 192, 168, 1, 125 }; // Webserver on my NAS running on port 81
EthernetClient client;

void setup() {
  lcd.begin(20, 4);
  Ethernet.begin(mac);
  lcd.print("connecting ...");
  delay(1000);
  lcd.setCursor(0,1);
  if (client.connect(server, 81)) {
    lcd.print("connected");
    client.println("GET /tools/lcd.php HTTP/1.1");
    client.println();
  } else {
    lcd.print("connection failed");
  }
}

void loop() {
  if (client.available()) {
    char c = client.read();
    lcd.setCursor(0,2);
    lcd.print("SUCCESS");
    for(;;)
      ;
  }

  if (!client.connected()) {
    lcd.setCursor(0,2);
    lcd.print("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}


What happens is: Both if-statements in the main loop() are false at first - after some time, the second one becomes true. So the client seems to connect successfully but never becomes "available" - whatever that is supposed to mean ... As soon as I change the server to 74.125.132.94 (which is www.google.de) everything works as expected.

Has anyone an idea on this? I'm kinda stuck ...

Thanks and regards
J├╝rgen

pylon

Have you tried accessing your NAS manually (without a browser)?

This is done by the telnet command. Open a command line and enter:

Code: [Select]
telnet 192.168.1.125 81

When connected enter the following string:

Code: [Select]
GET /tools/lcd.php HTTP/1.0



Take care to hit the return key twice after that first line. If you get any response, you should change the protocol version to 1.0 too in your code. If you don't get a response, the problem lies in your NAS being a bit picky about how a request is sent. You tell your server that you're using HTTP 1.1 but effectively your sending the simplest form of a version 1.0 request.

juekr

Hey, thanks for the reply!

Seems like there's something wrong with the webserver's configuration?!?

If I telnet onto the NAS width HTTP/1.0 I receive the following response:
Code: [Select]
telnet 192.168.1.125 81
Trying 192.168.1.125...
Connected to 192.168.1.125.
Escape character is '^]'.
GET /tools/lcd.php HTTP/1.0

HTTP/1.0 200 OK
X-Powered-By: PHP/5.2.10-pl0-gentoo
Content-type: text/html
Content-Length: 39
Connection: close
Date: Mon, 16 Jul 2012 13:21:19 GMT
Server: lighttpd/1.4.23


While telnetting with HTTP/1.1 gives the following result:
Code: [Select]
telnet 192.168.1.125 81
Trying 192.168.1.125...
Connected to 192.168.1.125.
Escape character is '^]'.
GET /tools/lcd.php HTTP/1.1

HTTP/1.1 400 Bad Request
Content-Type: text/html
Content-Length: 349
Connection: close
Date: Mon, 16 Jul 2012 13:22:12 GMT
Server: lighttpd/1.4.23


But switching from HTTP/1.1 to HTTP/1.0 in my Arduino script has no effect - still the client never becomes "available".

Do I have to tell my NAS to serve the webpage in HTTP/1.0-mode? How would I do that?

Thanks for your help so far - it seems like we're getting closer to the problem!

pylon

Quote
Do I have to tell my NAS to serve the webpage in HTTP/1.0-mode? How would I do that?


You do that by saying so on the request line. Your server is correct (although a bit picky) in not accepting the single line request when asked for the HTTP/1.1 protocol. Just leave the HTTP/1.0 in your code and that part should be fine.

client.available() does not mean that the client is available but that the client has received some characters from the server (it returns the number of characters available for you to read).

Do you get a connected on the LCD?

juekr

Yes - on the LCD I get (I changed the request to HTTP/1.0):

Code: [Select]
connecting ...
connected


and after a while:
Code: [Select]
connecting ...
connected
disconnecting.

Go Up