Go Down

Topic: Ethernet Shield + UNO connection problem (Read 2627 times) previous topic - next topic

SurferTim

Can your friend ping your public ip?

There are ways around the port 80 block.

The most legal is to get a commercial account with a static ip from your provider. Sometimes this is not cheap. Mine went from $39 US for a residential account to $99 for a minimum commercial account. I now pay well over $300/month.

The second way is to use a port other than port 80. May I suggest port 8088. Set that port in your server() code in the arduino, then check it on localnet. Does this respond?
http://192.168.1.4:8088

Then your friend should be able to use
http://yourpublicip:8088


Mastino

SurferTim really you are my HERO! Thanks you it is working fine! I`m so happy now!

SurferTim

#17
Jan 22, 2012, 09:35 pm Last Edit: Jan 23, 2012, 01:57 am by SurferTim Reason: 1

SurferTim really you are my HERO! Thanks you it is working fine! I`m so happy now!

Thanks!

m_-a-_c

Ok, now that his problem has been fixed, I'm going to high-jack this thread.

I've been working on connecting my arduino UNO with the (official) ethernet sheild for about 8 hrs now with limitted success.  (btw: using v 1.0 IDE)

Right now it does connect, but only if I manually delete the IP address from my routers' DHCP table and then it only connects once or twice before jamming-up again.

I used some code from a previous post to connect to an XAMPP local server and read a text file, and when it does connect everything works fine.  But what could be causing this issue?

SurferTim

Hijack away!  At least this way I know what you have seen. :)

Please post your code and describe your network setup, like gateway and subnet mask. dhcp server? Other network devices? The ip/subnet/gateway assigned to the computer you are attempting the connection from.

Can you ping it after it "jams up"?


m_-a-_c

#20
Jan 23, 2012, 03:23 pm Last Edit: Jan 23, 2012, 03:25 pm by m_-a-_c Reason: 1
Yes, I can still Ping it after.  Right now it does not show up in the router dhcp table, but I can till ping.

I`m very new at this network stuff, but I spent most of last night trolling this forum, so I am starting to catch-up.  I know the problem probably exists outside of the Arduino World, but I am at a lost.
Thanks,

NEW info:
My test code doesn`t work at all anymore (nothing changed just restarted my computer).  The web client example (using dhcp) works fine, but if I try to assign an ip manually it doesn`t work (even if it`s the same as the router would assign - after deleting the previous entry).

REQUESTED info:
lap-top (netbook actually) is connected through wifi (but gateway and subnet is same as wired)
ethernet board is wired to router
dhcp server is enabled
I can also load the text file from my browser using the ip address (i.e. 192.168.1.101/arduino.html)

CODE:
Code: [Select]

//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

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

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x80, 0x65 };
byte ip[] = { 192, 168, 1, 104 }; //assigned arduino LAN IP address
byte server[] = { 192, 168, 1, 101 }; // laptop running apache LAN IP address
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0};


EthernetClient client; //apache web server running on port 80

void setup()
{
 Ethernet.begin(mac);//, ip, gateway, subnet);
 Serial.begin(9600);
 Serial.println("starting simple arduino client test");
 Serial.println();

 delay(1000);

 Serial.println("connecting...");

 if (client.connect(server, 80)) {
   Serial.println("connected");
   client.println("GET /arduino.txt HTTP/1.0"); //text file in apache htdocs folder
   client.println();
 } else {
   Serial.println("connection failed");
 }
}

void loop()
{
 if (client.available()) {
   char c = client.read();
   Serial.print(c);
 }

 if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");
   Serial.println("==================================");
   Serial.println("");
   client.stop();
   for(;;);
 }
}

SurferTim

I would check the router dhcp server. Some don't care about ip addresses within the range of the dhcp server that were not issued by the dhcp server using the localnet. Some do care.

Insure the ip address you are assigning to the shield is not in the range the dhcp server. They can be a bit fussy about that.

m_-a-_c

I did, range is 100-150, I tried a bunch below 100... nothing worked.

SurferTim

#23
Jan 23, 2012, 03:46 pm Last Edit: Jan 23, 2012, 04:05 pm by SurferTim Reason: 1
If I were you, I would avoid 192.168.1.100 to 192.168.1.150. Even if that is not the problem today, it will be someday.

When you say "doesn't work", you have to be more specific. What does the serial monitor say when you press the reset button?

Edit: That is V1.0 code. Show me the code you use for Ethernet.begin() when you assign a static ip. The reason I ask is there is no variable for the dns ip. Here are the function declarations for begin() in IDE v1.0. Anything more than an ip must specify a dns server. If you omit that, it will take your third parameter as the dns server (maybe ok) and the fourth parameter as the gateway (probably not ok).

Quote
int begin(uint8_t *mac_address);
  void begin(uint8_t *mac_address, IPAddress local_ip);
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);

m_-a-_c

Interesting,
I didn't catch that when I modified the code to V1.0 - thanks for pointing it out.
However, I was mainly using (mac, ip) so it should still work. I will try later today. 
Code: [Select]

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x80, 0x65 };  //mac from sticker on board
byte ip[] = { 192, 168, 1, 9 }; //assigned arduino LAN IP address
byte server[] = { 192, 168, 1, 101 }; // laptop running apache LAN IP address

EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.println("starting simple arduino client test");
  Serial.println();

  delay(1000);

  Serial.println("connecting...");

  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /arduino.txt HTTP/1.0"); //text file in apache htdocs folder
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    Serial.println("==================================");
    Serial.println("");
    client.stop();
    for(;;);
  }

Also, my test code does not work when using just begin(mac):



The Serial monitor gets to "connecting" then waits a bit then goes to "connection failed" and "disconnecting"
I am not able to test things right now, but if you have another idea, I will test a bunch of things when I get home (damn work is always in the way!)

Cheers, and thanks again.

SurferTim

#25
Jan 23, 2012, 05:02 pm Last Edit: Jan 23, 2012, 05:13 pm by SurferTim Reason: 1
On an HTTP/1.0 request, the server will close the connection. This is something like the code I use:
Code: [Select]
void loop()
{
 while(client.connected()) {
   while(client.available()) {
     char c = client.read();
     Serial.print(c);
   }
 }
 client.stop();
  Serial.println();
  Serial.println("Disconnected");
 for(;;);
}

I found if you do not read the connection until the server closes it, there may be characters in the rx buffer. The connection will not close if the rx buffer is not empty.

Edit: corrected typo in code and added the "Disconnected" message.

m_-a-_c

Thank you for all your help it is very appreciated.
Unfortunately, it`s not quite working yet.

I can set a manual ip address
the manual ip address works in the web client example
my test code does assign the manual ip address, and the arduino does ping after that, but it still doesn`t connect to the computer. 

client.connect(server, 80) = 0, I understand the code you are suggesting, and if it would still 'sometimes' connect, that might have done the trick, but it 'never' connects now, I really don't understand how these things can magically start and stop working.

I`m just hoping you have another trick up your sleeve.

Thanks again,
MA

m_-a-_c

Woot,
I got some good news, it's working again.  but only with the automatic ip method (dhcp).
if I define the ip address, (either just (mac, ip) or the whole thing) then it doesn't work, wich is weird because manual works fine in the other sketch.  This leads me to believe that the router must be blocking it.  because it still pigns fine, but it can't connect to my local server.

Any idea?
Cheers, and thanks.

m_-a-_c

Ok, some more progress.
I changed to code a bit to loop through multiple attempts because it doesn't always connect on the first try.  I also poked more holes into the firewalls (router and PC) and that seemed to have helped (I could only connect with the network un-protected before).

Setting the ip manually still doesn't work.  So, what I ended up doing is setting the ip the WizNet was urrently connected to as a reserved client on the router (DHCP reservation).  That way I can poke "small" holes in the firewall by knowing the ip address of the device. Do you see a problem with this at all?

So it's not perfect, but unless you have some comments or notice that I am breaking some rules here, I think I'm good to keep tinkering.  For now anyway.

This was my first time posting, and I am very impressed with th level of help I got here, thanks alot SurferTim (and everybody else who answers these things)

Cheers,
MA

m_-a-_c

oh, the code (fyi and future reference)
Code: [Select]

//Based on code by zoomkat
//modified by Surfer Tim and m_-a-_c
//simple ethernet client test code
//for use with IDE v1.0 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

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

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x80, 0x65 };
byte server[] = { 192, 168, 1, 104 }; // PC running apache LAN IP address

EthernetClient client; //apache web server running on port 80

void setup()
{
  Ethernet.begin(mac);  //for some reason only DHCP works, manual ip addresses don't connect
  Serial.begin(9600); 
  Serial.println("starting simple arduino client test");
  Serial.println();

  delay(1000);

  int i =0;
  while(!client.connected() && i<10){   //loops up to 10 times to try to connect
    Serial.println("connecting...");
    Serial.print("Result: ");
    Serial.println(client.connect(server, 80));
    i++;
    delay(500);
  }
  if(client.connected()){
    Serial.println("connected");
    client.println("GET /arduino.txt HTTP/1.0"); //text file in apache htdocs folder
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  while(client.connected()) {
    while(client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }
  client.stop();
  Serial.println();
  Serial.println("Disconnected");
  for(;;);
}


Go Up