Ethernet

Table of Contents

  1. Hardware
  2. Software

Hardware

First of all you have to connect your mbed to a RJ45 jack. These instructions can be found here : Ethernet RJ45.

Software

See: Ethernet Interface library.

Legacy Networking Libraries

Getting started

This is essentially a tri-liner:

First include the header file:

#include "EthernetNetIf.h"

Instantiate the interface: If you are using DHCP:

EthernetNetIf eth;

Or if you want to set your own parameters:

EthernetNetIf eth(
  IpAddr(192,168,0,101), //IP Address
  IpAddr(255,255,255,0), //Network Mask
  IpAddr(192,168,0,1), //Gateway
  IpAddr(192,168,0,1)  //DNS
);

And set it up:

eth.setup();

That's it!

Includes

#include "EthernetNetIf.h"

Reference

» Import this program

Public Member Functions

  EthernetNetIf ()
  Instantiates the Interface and register it against the stack, DHCP will be used.
  EthernetNetIf ( IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns)
  Instantiates the Interface and register it against the stack, DHCP will not be used.
EthernetErr   setup (int timeout_ms=15000)
  Brings the interface up.
IpAddr   getIp () const
  Returns the IP of the interface once it's connected.




5 comments:

19 Oct 2011

For our network, the default timeout of 15 seconds was too short when using DHCP. It needs to be around 30 seconds or more.

I suspect that is the case at many large organizations that lock down the network a bit for more security.

So if you get an error trying to get an IP address, try increasing the timeout a bit with eth.setup(30000);

26 Feb 2012

I am using internet through a proxy server. Will you please told me how can i configure these parameters?? EthernetNetIf eth( IpAddr(192,168,0,101), IP Address IpAddr(255,255,255,0), Network Mask IpAddr(192,168,0,1), Gateway IpAddr(192,168,0,1) DNS );

IP address of my proxy server is 192.168.1.1(private) and HTTP/HTTPS port number is 8070.

Thanks in advance

05 Jun 2012

I've been experimenting with the code, because I would like to be able to change the way mbed conects to the network at run-time.

I've noticed that if I define Ethernet eth. inside the main loop, the code runs with no problem.

int main (){

   ...
   EthernetNetIf eth;
   ...

   return 0;
}

But if I create a function to asign a particular IP Adress based on external parameters, and then pass this object to the main function, this does not work.

EthernetNetIf getIP(){

  EthernetNetIf eth(
                    IpAddr(192,168,0,101), //IP Address
                    IpAddr(255,255,255,0), //Network Mask
                    IpAddr(192,168,0,1), //Gateway
                    IpAddr(192,168,0,1)  //DNS
                    );

  return eth;


}

int main (){

   ...
   EthernetNetIf eth = getIP();
   ...

   return 0;
}

I assume this is because there is no implementation of the Copy Constructor, I've tried to look at the code but I can't figure out the way to make this work.

What I want to do is be able to read from a Text file the IP adress to assign to mbed, without recompliling a new program. Is this posible?

26 Jun 2012

You could be interested in the new mbed official Ethernet Interface library.

25 Oct 2012

Hi Emilio, Just a quick question, we are currently using the EthernetNetIf library in our project, but we are having trouble with the DHCP (seems that it is getting stuck while waiting for an IP address). We are looking at moving to the new EthernetInterface library, but it seems that we are missing some files. I believe our current library uses the objects HOST and IPADDR (and our project is heavily based on them...), but those are not present in the new library. Is there an easy way to move from one to the other ?

Thank you for your help.