You are viewing an older revision! See the latest version

Ethernet

Table of Contents

  1. Hardware
  2. Library

Hardware

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

Library

Getting started

This is essentially a tri-liner:

First include the header file:

#include "if/eth/ethIf.h"

Instantiate the interface: If you are using DHCP:

EthernetNetIf eth;

Or if you want to set your own parameters:

EthernetNetIf(
  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 "if/eth/ethIf.h"

Reference

EthernetNetIf()

Instantiate the Interface and register it against the stack. DHCP will be used.

EthernetNetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns)

Instantiate the Interface & register it against the stack. DHCP will not be used. IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address.

EthernetErr setup(int timeout_ms = 15000)

Bring the interface up. Returns ETH_OK on success or ETH_TIMEOUT on timeout. You can set the timeout parameter in milliseconds. If not it defaults to 15 s.

Result codes

enum EthernetErr
{
  __ETH_MIN = -0xFFFF,
  ETH_TIMEOUT, //Timeout during setup
  ETH_OK = 0
};

Implementation

This interface is built around the mbed's Ethernet class and the LwIP stack. For more information about LwIP, you can visit the project's development site or its Wiki.


All wikipages