Skip to content

Commit 46efd61

Browse files
author
Seppo Takalo
committed
Clarify default interface
1 parent 63d8e56 commit 46efd61

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

docs/reference/api/connectivity/networksocket/networkinterface.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ For example, when providing Wi-Fi SSID and password, you may use the following `
4242
{
4343
"target_overrides": {
4444
"*": {
45-
"target.network-default-interface-type": "WIFI",
4645
"nsapi.default-wifi-security": "WPA_WPA2",
4746
"nsapi.default-wifi-ssid": "\"ssid\"",
4847
"nsapi.default-wifi-password": "\"password\""
@@ -53,7 +52,7 @@ For example, when providing Wi-Fi SSID and password, you may use the following `
5352

5453
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.
5554

56-
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.
55+
Targets with connectivity set the `target.network-default-interface-type` configuration variable appropriately, either to their only interface or their most-commonly-used one. 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.
5756

5857
Applications may also ask for a specific type of connection, as the following table shows:
5958

@@ -62,10 +61,22 @@ Applications may also ask for a specific type of connection, as the following ta
6261
|`*WiFiInterface::get_default_instance()`| Wi-Fi interface | Requires security parameters (mode, SSID, password) |
6362
|`*EthInterface::get_default_instance()` | Wired Ethernet interface, not Wi-Fi | none |
6463
|`*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 |
65-
| `*CellularBase::get_default_instance` | Return cellular connectivity | Requires network parameters (pin, APN, username, password) |
66-
| `*NetworkInterface::get_default_instance()` | First one from above that is found | |
64+
| `*CellularBase::get_default_instance()` | Return cellular connectivity | Requires network parameters (pin, APN, username, password) |
65+
| `*NetworkInterface::get_default_instance()` | One of the above, depending on `target.network-default-interface-type` | |
6766

68-
Please note that any of those functions may return `NULL` when the interface of this type or its configuration is not found.
67+
Note that the calls for a specific interface type do not preconfigure credentials such as SSID, as an interface-type-specific application is expected to configure these in code. NULL will be 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+
// net set from NetworkInterface::get_default_instance() as above
74+
WiFiInterface *wifi = net->wifiInterface();
75+
if (wifi) {
76+
printf("This is a Wi-Fi board.")
77+
// call WiFi-specific methods
78+
}
79+
```
6980

7081
### Related content
7182

0 commit comments

Comments
 (0)