Reading a file from computer via Arduino Ehernet - Does not working - help-

Hi people
I am checking my arduino Ethernet to send data form sensors to my computer in localhost. In the future I ´ll send it to a mysql database via "GET" ..etc. , but, now, for demo mode I ´d make an example to read a file of my computer for check that all is ok.

I have created a file arduino.txt and I have it in localhost working fine . like this

also, I have made a copy-paste for example to connect via Ethernet to my computer, and I get conexion, but, I cannot read the file .

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x69, 0xDB };  //mac arduino
IPAddress ip(1192, 168, 1, 34);                       //my IP  
IPAddress server(127, 0, 0, 1);                    //my localhost -

EthernetClient client;
void setup() {
   Serial.begin(9600); 
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Fail DHCP");
    Ethernet.begin(mac, ip);
  }
  delay(1000); 
  Serial.println("conecting...");
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /localhost/arduino.txt HTTP/1.0");
    //client.println("GET localhost/arduino.txt HTTP/1.1");
    client.println("Host: localhost");
    client.println("Close");
    client.println();
  } 
  else {
    Serial.println("fail");
  }
}
//loop --------------------------------
void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconecting.");
    client.stop();
    while(true);
  }
}

The result in the console

conecting...
connected
HTTP/1.1 200 OK
Server: Virtual Web 0.9
Set-Cookie: SessionID=; path=/
Content-Type: text/html
Content-Length: 151   

<html><head><meta HTTP-EQUIV="Pragma" CONTENT="no-cache"><script language='javascript'>parent.location="/login.htm"</script></head><body></body></html>
disconecting.

I have tried it client.println("GET localhost/arduino.txt HTTP/1.1"); with /localhost, with HTTP/1.0, but I don´t get read the file.
any idea ?
thks for all.

You can't access localhost except from the server apps. Are you sure 192.168.1.1 is your server ip? That looks like a router login redirect page to me.

hi
thks for reply....
ok I know, I want access to my server app. I have installed easyphp in windows7. and the file, in this case, arduino.txt is in the directory of the easypphp. Like you say that IP :192, 168, 1, 1 was the router . Now I am using the IP for localhost that easy php give to me 127.0.0.1

but, now, I don´t get anything in the console just a * Serial.println("Fail DHCP");*

You must use the local ip of the server. It should be 192.168.1.x

localhost is the computer (server) that the client is running on.

When the Arduino attempts to connect to the server (itself) that the client is running on (itself), it isn't going to find that file, is it?

You must use the local ip of the server. It should be 192.168.1.x

thks for your help friends XD, both
what is X ? 8)

if I use " 192.168.1.1" I have got access to the router page, I see.
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x69, 0xDB }; //mac arduino
IPAddress ip(192, 168, 1, 34);
IPAddress server(192, 168, 1, 1 );

if i use this config : - FAIL
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x69, 0xDB }; //mac arduino
IPAddress ip(192, 168, 1, 34);
IPAddress server(127, 0, 0, 1 );

if i use this config : - FAIL
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x69, 0xDB }; //mac arduino
IPAddress ip(127, 0, 0, 1);
IPAddress server(192, 168, 1, 34 );

.... also if I add 10 to last number -FAIL.
IPAddress ip(192, 168, 1, 44);

On your windows server computer, type in ipconfig at the command prompt and press enter. You should see info about the computer. The below is what I get on my computer. The default gateway is the netgear router, and the IPv4 address is the lan ip address of the computer.

Wireless LAN adapter Wireless Network Connection 2:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::eda8:a9dd:bd47:fc09%13
   IPv4 Address. . . . . . . . . . . : 192.168.1.2
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

thanks for your time :slight_smile: and a pleasure for your replies. thks
I have got conexion with a external server, I read external files, and execute a query in a mysql via get, etc... but I don´t get it in localhost :frowning:

I have the mac of my arduino : 0x90, 0xA2, 0xDA, 0x0D, 0x69, 0xDB
I have got the arduino IP via Ethernet - Arduino Reference : IPAddress ip(192,168,1,33);
I have the IPv4 of my computer ( like you say with ipconfig ) : IPAddress server(192,168,1,34);

also I have a file http://127.0.0.1/arduino.txt ready for reading ( running WAMP)

if I use : IPAddress server(127,0,0,1); I get conexion, but I don´t read anything : I don´t found the file.
if I use : IPAddress server(192,168,1,1); I get conexion and i read the info of router :slight_smile:
if I use : IPAddress server(192,168,1,34); I don´t make conexion

if I use : IPAddress server(192,168,1,34); I don´t make conexion

If that is the ip of your server, and the web page is showing on the server's web browser using that ip, then you probably have a firewall problem. Insure you are allowing port 80 through the server firewall.

if I use : IPAddress server(127,0,0,1); I get conexion, but I don´t read anything : I don´t found the file.

Do you know why? 127.0.0.1 is, like localhost, a special IP address that refers to the server that the client is running on.

The Arduino as client is not running a server, so, of course the page isn't on the server.

f I use : IPAddress server(192,168,1,1); I get conexion and i read the info of router

So, that is clearly the IP address that the router assigns to itself. What IP address is the router assigning to the Arduino? THAT is the only address you can use on the Arduino.

What IP address is the router assigning to the PC that is the server? That is the ONLY address you can use for the server.

From a browser running on the PC that your web server is on, are you able to open http://192.168.1.34/arduino.txt ?
Do you have any other devices connected to the same network that can run a browser? If so, try the same URL on one of them.

tijuinem, please read your private message.

1.- sorry for delay !! :slight_smile: but ..thks all for your replies. I didn´t get to work in localhost mode, but I think that is problem that my router and my ISP.

1.- I don´t have any private msg "buscador" what do you need of my person ? :slight_smile: