|
4 | 4 |
|
5 | 5 | The EthInterface provides a C++ API for connecting to the internet over Ethernet.
|
6 | 6 |
|
7 |
| -### EthInterface class reference |
8 |
| - |
9 |
| -[](https://os.mbed.com/docs/v5.8/mbed-os-api-doxy/class_eth_interface.html) |
| 7 | +By default, this class does not require any configuration. It is able to pick up the default Ethernet driver for the target and select correct network stack. |
10 | 8 |
|
11 | 9 | ### Usage
|
12 | 10 |
|
13 |
| -To bring up the network interface: |
| 11 | +To statically initialize the driver, create an object without passing any parameters: |
| 12 | + |
| 13 | +```cpp |
| 14 | +EthernetInterface eth; |
| 15 | +``` |
| 16 | + |
| 17 | +Then, if the default configuration is enough, bring up the interface: |
| 18 | + |
| 19 | +```cpp |
| 20 | +nsapi_error_t status = eth.connect(); |
| 21 | +``` |
| 22 | + |
| 23 | +Now, the interface is ready to be used for [network sockets](/docs/development/reference/network-socket.html). |
| 24 | + |
| 25 | +```cpp |
| 26 | +// Open a TCP socket |
| 27 | +TCPSocket socket; |
| 28 | +socket.open(ð); |
| 29 | + |
| 30 | +// Open a UDP socket |
| 31 | +UDPSocket socket; |
| 32 | +socket.open(ð); |
| 33 | +``` |
| 34 | + |
| 35 | +### Configuration |
14 | 36 |
|
15 |
| -1. Instantiate the `EthInterface` class. |
16 |
| -1. Call the `connect` function. |
17 |
| -1. Once you connect the EthInterface, you can use it as a |
18 |
| -target for opening [network sockets](/docs/v5.8/reference/network-socket.html). |
| 37 | +For EthernetInterface, there are two possible configurations: |
| 38 | + |
| 39 | +- Use DHCP for network addressing. This is the default. |
| 40 | +- Use statically configured IP addresses. |
| 41 | + |
| 42 | +Refer to the API below for how to set the IP addresses by calling the `set_network()` function. |
| 43 | + |
| 44 | +### Troubleshooting information |
| 45 | + |
| 46 | +Network interface `connect` failure causes: |
| 47 | + |
| 48 | +- `NSAPI_ERROR_NO_CONNECTION` indicates that the Ethernet link up has failed. Check that the Ethernet connection is working. |
| 49 | +- `NSAPI_ERROR_DHCP_FAILURE` indicates that acquiring the IP address has failed. Check that the IP address configuration service is working. |
| 50 | + |
| 51 | +### EthInterface class reference |
| 52 | + |
| 53 | +[](https://os.mbed.com/docs/v5.8/mbed-os-api-doxy/class_eth_interface.html) |
19 | 54 |
|
20 | 55 | ### EthInterface examples
|
21 | 56 |
|
|
0 commit comments