You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/api/connectivity/networksocket/networkinterface.md
+74-2Lines changed: 74 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,85 @@ A socket requires a NetworkInterface instance when opened to indicate which Netw
4
4
5
5
Network interface is also the controlling API for application to specify network configuration.
6
6
7
-
Existing network interfaces:
7
+
### Existing network interfaces:
8
8
9
9
-[Ethernet](ethernet.html): API for connecting to the internet over an Ethernet connection.
10
10
-[Wi-Fi](wi-fi.html): API for connecting to the internet with a Wi-Fi device.
11
11
-[Cellular](cellular-api.html): API for connecting to the internet using a cellular device.
12
12
-[Mesh networking interface](mesh-api.html): Mbed OS provides two kinds of IPv6-based mesh networks - 6LoWPAN_ND and Thread.
13
13
14
-
Optional functionality:
14
+
### Network status updates
15
+
16
+
An application may choose to register a callback to monitoring status changes from network interfaces. The application can do this by using the following API:
15
17
16
18
-[Network status](network-status.html): API for monitoring network status changes.
19
+
20
+
### Default network interface
21
+
22
+
In Mbed OS, targets that provide network connectivity also provide a default network interface. This can be Ethernet, Wi-Fi, mesh or cellular. Using a default interface allows you to port applications to different targets and connectivity options.
23
+
24
+
The following example uses a default interface to connect to the network:
This example works on all IP-based connectivity options that Mbed OS supports. The Mbed OS configuration system provides configuration for the default interface at build time, so at run time, you can just call `connect()` without any parameters.
38
+
39
+
For example, when providing Wi-Fi SSID and password, you may use the following `mbed_app.json`:
40
+
41
+
```
42
+
{
43
+
"target_overrides": {
44
+
"*": {
45
+
"nsapi.default-wifi-security": "WPA_WPA2",
46
+
"nsapi.default-wifi-ssid": "\"ssid\"",
47
+
"nsapi.default-wifi-password": "\"password\""
48
+
}
49
+
}
50
+
}
51
+
```
52
+
53
+
Please see [Selecting the default network interface](configuration-connectivity.html#selecting-the-default-network-interface) for information about how to supply required configuration parameters on different connections.
54
+
55
+
Targets with connectivity set the `target.network-default-interface-type` configuration variable appropriately, either to their only interface or the one most commonly used. For targets that provide more than one type of connectivity, you may choose the default by overriding the `target.network-default-interface-type` configuration variable.
56
+
57
+
Applications may also ask for a specific type of connection, as the following table shows:
58
+
59
+
|Method|What connectivity is returned| Requirements |
|`*EthInterface::get_default_instance()`| Wired Ethernet interface, not Wi-Fi | none |
63
+
|`*MeshInterface::get_default_instance()`| Returns either `LoWPANNDInterface` or `ThreadInterface`, depending on which is set to default | Target provides a driver or macro `DEVICE_802_15_4_PHY` is enabled |
|`*NetworkInterface::get_default_instance()`| One of the above, depending on `target.network-default-interface-type`||
66
+
67
+
Note that the calls for a specific interface type do not preconfigure credentials such as SSID because an interface-type-specific application is expected to configure these in code. `NULL` is returned if no interface of that type is available.
68
+
69
+
Calls for a NetworkInterface will request one of the interface types depending on `target.default-network-interface-type`, and preconfigure the credentials. If credentials can't be preconfigured (for example because `nsapi.default-wifi-ssid` isn't set), the call returns `NULL` rather than an unconfigured interface.
70
+
71
+
An application may check the type of the interface returned by `NetworkInterface::get_default_instance()` by using the "dynamic downcast" methods:
72
+
73
+
```
74
+
// net set from NetworkInterface::get_default_instance() as above
75
+
WiFiInterface *wifi = net->wifiInterface();
76
+
if (wifi) {
77
+
printf("This is a Wi-Fi board.")
78
+
// call WiFi-specific methods
79
+
}
80
+
```
81
+
82
+
### Related content
83
+
84
+
-[Configuring the default network interface](configuration-connectivity.html#selecting-the-default-network-interface).
0 commit comments