Ethernet shield - webClient example

I dont see how this is possible

Check the RFCs. The default subnet mask is defined in the IPv4 standard. First bit 0? class A. first 2 bits 10? class B. first 3 bits 110? class C. Same for classes D and E, but those aren't node addresses.

-j

Yes, but you cannot assume the default subnet is the correct subnet. For instance, I have a fixed range of static IP addresses available, its a class A network, but I cannot use 255.0.0.0. A workplace network might have multiple departments all running on a 192.168.. network, but each department could be limited to 16 or 32 addresses.

Again, you almost always can assume the subnet or gateway, but it shouldn't be coded, it should be up to the programmer to make that assumption

Again, you almost always can assume the subnet or gateway, but it shouldn't be coded

The default netmask is defined by the IPv4 standard. It can and should be coded. Every single network capable operating system I have ever encountered allows one to use the default subnet mask. Why would you remove this from the arduino?

You're on a network that does not use a default netmask; big deal. I've been on a network where the netmask changes depending on which subnet you're on. If the user is on such a network they will likely be assigned an address anyway (which will come with subnet and router data!), instead of being allowed to run amok and chose an IP configuration by rectal extraction.

The simple fact is that most arduino users will be on a network where the default netmask is correct and the default router is .1. The arduino is meant to be easy to use. connect the dots...

-j

I'm not in any way suggesting that any functionality be removed.

Again, yes, you can determine the "default" subnet, but that doesn't make it the correct subnet for the programmer/user. Programming should be a codified set of rules, not assumptions. Carrying the assumption out a little: Most arduino tinkerers are probably starting out on a home router, most home routers come shipped as 192.168.(1 or 2).1 so should this address be assumed to be the default gateway.

I'm not inferring either that programmers should just randomly choose an IP configuration by "rectal extraction" (I like that one), in fact I'm saying just the opposite, that if the programmer doesn't know the correct settings, then the library should not help him by making assumptions.

Programming should be a codified set of rules, not assumptions.

There are codified assumptions all over the place in the software world. We call 'em "defaults".

In another thread it looks like the DHCP client is making progress, so hopefully this will all be a moot point soon.

-j

check CIDR!

classless IP is with us. stop thinking in pure class A B C things. this isn't 10-15 yrs ago, mate.

I can't believe that this is still an open issue.

you have broken code and proven examples of how it screwed over a user. you think that's a Good Thing(tm)?

go talk to a routing company and suggest they put dot1 in their last octet as a router. go see what kind of laughter you get from them.

(I used to work for cisco, juniper and many other networking companies. and I, too, would laugh in your face if you suggested that dot-1 was anything more than some dumb convention that SOME HOME USERS have.)

this shouldn't even be DEBATED. its butt-obvious to anyone who plays in the IP world.

I need to step away, again, it seems. this is too frustrating having to argue about basic IP topology issues to THIS length.

go read a book on ip networking. see how 'frequent' it is that they recommend you just automatically assume a router's ip address. show me some citations - if you can find any.

DHCP does not make this moot.

you STILL need to provide sane time-proven ways to configure your ip host.

slamming in a dot or a series of 255's is wrong wrong wrong.

wrong.

just simply wrong.

stop trying to defend a basically ignorant assumption about how ip works.

"it works at MY house and my mommies house, too"

good logic. folks. nice way to write APIs.

fwiw, I purchased a static block of IP from my net provider and I'm a 255.255.255.240 subnet.

can I 'get by' by faking it to pure class C? sort of. kinda sorta.

is it right to assume class C?

no. no it is not.

lets also talk about ISPs. my ISP has given me a .70 as my default router ('pro' level DSL from pacbell).

I happen to have a local gateway in my block of 5 or so addresses I can use but if I used their gw, it would be xx.xx.xx.70

so again, your code would not work on my home network using the ASSIGNED router that I get from pacbell.

I don't have a class C address and my router isn't .1

I guess the ard code is just not 'supposed' to work for folks like me, hmmm?

wow - the arduino codebase. we need a new slogan:

"well, it works FOR US..."

sheesh!

OK, no more caffeine for you today...

stop trying to defend a basically ignorant assumption about how ip works.

Ignorant? Hmm, let's see: BS computer science; have nearly finished MSE computer engineering; 20 years supporting engineering workstations and networks including a few years as backup network admin for an engineering network at NASA's Marshall Space Flight Center; design and implementation of various instructional networking labs; network engineer training on (at the time) big name commercial routers; designed protocols for theoretical network hardware and implement same on simulated hardware; I've even transferred data between my moving vehicle and the International Space Station (that was neat).

Opinionated? you bet. Ignorant on networking? I beg to differ.

-j (my last post on this thread)

Put simply:

Assuming .1 gateway: Works for the majority
Requiring a gateway: Works for everyone

Assuming a subnet: Works for the majority
Requiring a subnet: Works for everyone

Put simply:

Assuming .1 gateway: Works for the majority
Requiring a gateway: Works for everyone

Assuming a subnet: Works for the majority
Requiring a subnet: Works for everyone

This suggests that somehow the current option to have a default subnet and gateway means that there is no way it will work for those who have a different situation. There are multiple forms of the constructor, some which allow for defaults, and some that allow full configuration.

Now, if the argument is primarily about what is a 'right' thing to teach those who are just getting into networking, I think that's a valid discussion.

My personal feeling is that "Assuming a subnet: Works for the majority" is a good definition of a default value.

Hi everyone, I'm hoping someone can help me figure out how to get WebClient to run. I'm a relative network noob but I've read through all the threads I can find on this.

My setup:

  1. OS X 10.5.8, computer is internet sharing my airport connection.
  2. WebServer sketch seems to work fine using ip of 192.168.2.3.
  3. Ping to 192.168.2.3 seems to work fine.
  4. Yet WebClient connection fails after about 1 minute of "connecting..." I'm using the standard WebClient sketch with the following declarations:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 2, 3 };
byte subnet[] = { 255, 255, 0, 0 };
byte gateway[] = { 192, 168, 2, 1 };
byte server[] = { 64, 233, 187, 99 }; // Google

FYI, ifconfig en0 produced:

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
inet6 fe80::21f:5bff:fef3:7a1f%en0 prefixlen 64 scopeid 0x4
inet 169.254.25.48 netmask 0xffff0000 broadcast 169.254.255.255
ether 00:1f:5b:f3:7a:1f
media: autoselect (100baseTX ) status: active...

Any suggestions? Many thanks!

try a different google address, for example: 216,239,59,147

The reason mem suggested a different IP address is that google has done some rearranging of their server network, and 64.233.187.99 doesn't work for direct end user access anymore.

Running a host www.google.com returns some alternatives:

www.google.com is an alias for www.l.google.com.
www.l.google.com has address 66.102.7.99
www.l.google.com has address 66.102.7.103
www.l.google.com has address 66.102.7.104
www.l.google.com has address 66.102.7.105
www.l.google.com has address 66.102.7.106
www.l.google.com has address 66.102.7.147

66.102.7.103 worked for someone who asked about this the other day.

Ran

Thank you for the suggestions, but those addresses gave me the same result. Should I be trying other (less frequently rearranged) sites? Should I try playing with wireshark? Thanks!

Next step is probably to try connecting a laptop or other device with easier access to diagnostic info in place of the Arduino, and see whether there's a configuration problem in the Mac that's preventing it from forwarding traffic.

Or, it would be for me: if you're already up to speed on wireshark (I'm not), you may find it faster and easier to snoop around with that.

It might also be useful to watch the data transfer stats on the network cards for hints on whether packets are being forwarded.

(Yes, this means that my guess is that it's likely your gateway isn't gateway-ing).

Ran

I came across Georg Kaindl's recent Arduino Ethernet libraries and gave a shot at using his EthernetDHCP library to get my WebClient sketch to work.

I get this output:

Discovering servers....................
Requesting lease.
Obtained lease!
My IP address is 192.168.2.3
Gateway IP address is 192.168.2.1
DNS IP address is 192.168.2.1
hostName is Arduino

connecting...
Trying client.connect() #1.....    connection failed
Trying client.connect() #2.....    connected
Trying client.connect() #3.....    connection failed
Trying client.connect() #4.....    connection failed
Trying client.connect() #5.....    connection failed
Trying client.connect() #6.....    connection failed
Trying client.connect() #7.....    connection failed
Trying client.connect() #8.....    connection failed
Trying client.connect() #9.....    connection failed
Trying client.connect() #10.....    connection failed

...when I run this code:

//  Copyright (C) 2010 Georg Kaindl
//  http://gkaindl.com
//
//  This file is part of Arduino EthernetDHCP.
//
//  EthernetDHCP is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as
//  published by the Free Software Foundation, either version 3 of
//  the License, or (at your option) any later version.
//
//  EthernetDHCP is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with EthernetDHCP. If not, see
//  <http://www.gnu.org/licenses/>.
//

//  Illustrates how to use EthernetDHCP in polling (non-blocking)
//  mode.

#include <Ethernet.h>
#include <EthernetDHCP.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte server[] = { 66, 102, 7, 147 }; // Google

const char* ip_to_str(const uint8_t*);

Client client(server, 80);



void setup()
{
  Serial.begin(9600);
  
  // Initiate a DHCP session. The argument is the MAC (hardware) address that
  // you want your Ethernet shield to use. The second argument enables polling
  // mode, which means that this call will not block like in the
  // SynchronousDHCP example, but will return immediately.
  // Within your loop(), you can then poll the DHCP library for its status,
  // finding out its state, so that you can tell when a lease has been
  // obtained. You can even find out when the library is in the process of
  // renewing your lease.
  EthernetDHCP.begin(mac, 1);
}

void loop()
{
  static DhcpState prevState = DhcpStateNone;
  static unsigned long prevTime = 0;
  
  // poll() queries the DHCP library for its current state (all possible values
  // are shown in the switch statement below). This way, you can find out if a
  // lease has been obtained or is in the process of being renewed, without
  // blocking your sketch. Therefore, you could display an error message or
  // something if a lease cannot be obtained within reasonable time.
  // Also, poll() will actually run the DHCP module, just like maintain(), so
  // you should call either of these two methods at least once within your
  // loop() section, or you risk losing your DHCP lease when it expires!
  DhcpState state = EthernetDHCP.poll();

  if (prevState != state) {
    Serial.println();

    switch (state) {
      case DhcpStateDiscovering:
        Serial.print("Discovering servers.");
        break;
      case DhcpStateRequesting:
        Serial.print("Requesting lease.");
        break;
      case DhcpStateRenewing:
        Serial.print("Renewing lease.");
        break;
      case DhcpStateLeased: {
        Serial.println("Obtained lease!");

        // Since we're here, it means that we now have a DHCP lease, so we
        // print out some information.
        const byte* ipAddr = EthernetDHCP.ipAddress();
        const byte* gatewayAddr = EthernetDHCP.gatewayIpAddress();
        const byte* dnsAddr = EthernetDHCP.dnsIpAddress();

        Serial.print("My IP address is ");
        Serial.println(ip_to_str(ipAddr));

        Serial.print("Gateway IP address is ");
        Serial.println(ip_to_str(gatewayAddr));

        Serial.print("DNS IP address is ");
        Serial.println(ip_to_str(dnsAddr));

        //Serial.println();
        
        delay(2000);
        
        Serial.print("hostName is ");
        Serial.println(EthernetDHCP.hostName());
        Serial.println();
        
        Serial.println("connecting...");
  
        for (int i = 0; i < 10; i++){
          Serial.print("Trying client.connect() #");  //added line
          Serial.print(i+1);
          Serial.print(".....  ");
          delay(3000);
          if (client.connect()) {
            Serial.println("  connected");
            client.println("GET /search?q=arduino HTTP/1.0");
            client.println();
          } else {
            Serial.println("  connection failed");
          }
        }
        
        break;
      }
    }
  } else if (state != DhcpStateLeased && millis() - prevTime > 300) {
     prevTime = millis();
     Serial.print('.'); 
  }

  prevState = state;
}

// Just a utility function to nicely format an IP address.
const char* ip_to_str(const uint8_t* ipAddr)
{
  static char buf[16];
  sprintf(buf, "%d.%d.%d.%d\0", ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3]);
  return buf;
}

Any guesses from the tubes as to why no output from the GET command? Any guesses as to why the second client.connect() outputs "connected" but not the others?

Many many thanks!

I had a few issues getting the WebClient to work too via the Ethernet example. Haven't tried the DHCP sketch yet but will give that a go later.

Initially I connected via my BT HomeHub 1 (BT Home Hub - Information and Advice), however when I connect....nothing.

One thing I did notice was that with all other devices laptops, phones etc. is that the router captures their IP and stores it automatically.

With the ethernet board connected I had to reuse/manually reconfigure an IP that already existed in the routers memory (the 'old' device was not connected) as the ethernet shield did not 'show' up when originally connecting. I could though ping the board no problem.

I then tried my trusty old BT 240 Voyager Router http://www.voyager.bt.com/wired_routers/voyager_240/product_info.htm, hooked up the ethernet board and connected straight away no problem.

So it looks like its down to the routers, their software(?) and how it manages the connections....bit of a pain though in having to swap routers just to get it working.....but at least it is!

G

Well if anyone is keeping score --

Assuming .1 gateway: Works for the majority
Requiring a gateway: Works for everyone

Assuming a subnet: Works for the majority
Requiring a subnet: Works for everyone

I spent some time with wireshark to figure out the request was going out for a dot one gateway. I'm new to the Ard and Ether shield and I learned more about the code than I wanted to. The default idea of a dot one bit me so I'm siding up with the unpopular linux-works point of view. I was thinking about rewriting the example code to prevent other newbies from falling into the same problem and then I found this thread while searching about DHCP. So how can I help with the dot one gateway example code? I also found the google address is stale but that was easy to figure out.