A quick example of a simple WiFi application using the WiFi and network-socket APIs that is provided as a part of mbed-os.

The program brings up the WiFi and the underlying network interface, and uses it to scans available networks, connects to a network, prints interface and connection details and performs simple HTTP operation.

Supported hardware:

Not that the mbed target board the WiFi shield gets connected to shouldn't have any other network interface e.g. Ethernet.

ESP8266 is a fallback option and will be used if the build is for unsupported platform.

Tue Oct 08 14:00:11 2019 +0100
Merge pull request #172 from ARMmbed/mbed-os-5.14

Mbed os 5.14
Commit copied from https://github.com/ARMmbed/mbed-os-example-wifi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:857719181846 1 # mbed-os-example-wifi #
mbed_official 0:857719181846 2
mbed_official 49:d44cac40bf15 3 Wi-Fi example for Mbed OS
mbed_official 0:857719181846 4
mbed_official 93:d2ba18c82ce3 5 (Note: To see this example in a rendered form you can import into the Arm Mbed Online Compiler, please see [the documentation](https://os.mbed.com/docs/mbed-os/latest/apis/wi-fi.html#wi-fi-example).)
mbed_official 93:d2ba18c82ce3 6
mbed_official 49:d44cac40bf15 7 ## Getting started with the Wi-Fi API ##
mbed_official 0:857719181846 8
mbed_official 91:dab9882e2b49 9 This is an example of a Wi-Fi application using the Wi-Fi APIs that [Mbed OS](https://github.com/ARMmbed/mbed-os) provides.
mbed_official 0:857719181846 10
mbed_official 91:dab9882e2b49 11 The program brings up the Wi-Fi and the underlying network interface and uses it to scan available networks, connects to a network and prints interface and connection details.
mbed_official 49:d44cac40bf15 12
mbed_official 49:d44cac40bf15 13 For more information about Wi-Fi APIs, please visit the [Mbed OS Wi-Fi](https://os.mbed.com/docs/latest/reference/wi-fi.html) documentation.
mbed_official 0:857719181846 14
mbed_official 0:857719181846 15 ### Supported hardware ###
mbed_official 0:857719181846 16
mbed_official 71:a0fbcc153b55 17 * All Mbed OS boards with build-in Wi-Fi module:
mbed_official 71:a0fbcc153b55 18 * [u-blox ODIN-W2](https://os.mbed.com/platforms/ublox-EVK-ODIN-W2/)
mbed_official 71:a0fbcc153b55 19 * [Realtek RTL8195AM](https://os.mbed.com/platforms/REALTEK-RTL8195AM/)
mbed_official 71:a0fbcc153b55 20 * [ST DISCO IOT board](https://os.mbed.com/platforms/ST-Discovery-L475E-IOT01A/) with integrated [ISM43362 WiFi Inventek module](https://github.com/ARMmbed/wifi-ism43362).
mbed_official 71:a0fbcc153b55 21 * [ST DISCO_F413ZH board](https://os.mbed.com/platforms/ST-Discovery-F413H/) with integrated [ISM43362 WiFi Inventek module](https://github.com/ARMmbed/wifi-ism43362).
mbed_official 71:a0fbcc153b55 22 * [Advantech WISE-150](https://os.mbed.com/modules/advantech-wise-1530/)
mbed_official 71:a0fbcc153b55 23 * USI WM-BN-BM-22
mbed_official 71:a0fbcc153b55 24 * MxChip EMW3166
mbed_official 71:a0fbcc153b55 25 * Boards with external WiFi shields.
mbed_official 71:a0fbcc153b55 26 * [NUCLEO-F401RE](https://os.mbed.com/platforms/ST-Nucleo-F401RE/) with [X-NUCLEO-IDW04A1](http://www.st.com/content/st_com/en/products/ecosystems/stm32-open-development-environment/stm32-nucleo-expansion-boards/stm32-ode-connect-hw/x-nucleo-idw04a1.html) Wi-Fi expansion board using pins D8 and D2 _(of the Arduino connector)_.
mbed_official 71:a0fbcc153b55 27 * [NUCLEO-F401RE](https://os.mbed.com/platforms/ST-Nucleo-F401RE/) with [X-NUCLEO-IDW01M1](https://os.mbed.com/components/X-NUCLEO-IDW01M1/) Wi-Fi expansion board using pins PA_9 and PA_10 _(of the Morpho connector)_.
mbed_official 71:a0fbcc153b55 28 * [NUCLEO-F429ZI](https://os.mbed.com/platforms/ST-Nucleo-F429ZI/) with ESP8266-01 module using pins D1 and D0.
mbed_official 71:a0fbcc153b55 29 * Other Mbed targets with an ESP8266 module, [X-NUCLEO-IDW04A1](http://www.st.com/content/st_com/en/products/ecosystems/stm32-open-development-environment/stm32-nucleo-expansion-boards/stm32-ode-connect-hw/x-nucleo-idw04a1.html) or [X-NUCLEO-IDW01M1](https://os.mbed.com/components/X-NUCLEO-IDW01M1/) expansion board.
mbed_official 0:857719181846 30
mbed_official 77:b74ac6641a3e 31 #### Adding connectivity driver
mbed_official 77:b74ac6641a3e 32
mbed_official 77:b74ac6641a3e 33 If the target does not have internal WiFi driver, or Mbed OS does not supply one, you need to add driver to your application and configure it to provide default WiFi interface.
mbed_official 77:b74ac6641a3e 34
mbed_official 77:b74ac6641a3e 35 ```
mbed_official 77:b74ac6641a3e 36 mbed add <driver>
mbed_official 77:b74ac6641a3e 37 ```
mbed_official 77:b74ac6641a3e 38
mbed_official 90:1def9d67d6e4 39 For example adding ISM43362 driver `mbed add wifi-ism43362` or X-Nucleo-IDW01M1 driver `mbed add wifi-x-nucleo-idw01m1`
mbed_official 90:1def9d67d6e4 40 The ESP8266 driver is already suplied by Mbed OS.
mbed_official 77:b74ac6641a3e 41
mbed_official 77:b74ac6641a3e 42 Then pin names need to be configured as instructed in the drivers README file.
mbed_official 77:b74ac6641a3e 43
mbed_official 44:63be19b7a3db 44 ## Getting started ##
mbed_official 0:857719181846 45
mbed_official 49:d44cac40bf15 46 1. Import the example.
mbed_official 0:857719181846 47
mbed_official 32:bca3f5f442b3 48 ```
mbed_official 32:bca3f5f442b3 49 mbed import mbed-os-example-wifi
mbed_official 32:bca3f5f442b3 50 cd mbed-os-example-wifi
mbed_official 32:bca3f5f442b3 51 ```
mbed_official 71:a0fbcc153b55 52
mbed_official 82:122bb3ae6de5 53 1. Configure the Wi-Fi shield and settings.
mbed_official 49:d44cac40bf15 54 Edit ```mbed_app.json``` to include the correct Wi-Fi shield, SSID and password:
mbed_official 0:857719181846 55
mbed_official 86:92e4be20dc8b 56 ```json
mbed_official 82:122bb3ae6de5 57 {
mbed_official 82:122bb3ae6de5 58 "config": {
mbed_official 82:122bb3ae6de5 59 "wifi-ssid": {
mbed_official 82:122bb3ae6de5 60 "help": "WiFi SSID",
mbed_official 82:122bb3ae6de5 61 "value": "\"SSID\""
mbed_official 82:122bb3ae6de5 62 },
mbed_official 82:122bb3ae6de5 63 "wifi-password": {
mbed_official 82:122bb3ae6de5 64 "help": "WiFi Password",
mbed_official 82:122bb3ae6de5 65 "value": "\"PASSWORD\""
mbed_official 82:122bb3ae6de5 66 }
mbed_official 82:122bb3ae6de5 67 },
mbed_official 82:122bb3ae6de5 68 "target_overrides": {
mbed_official 82:122bb3ae6de5 69 "*": {
mbed_official 82:122bb3ae6de5 70 "platform.stdio-convert-newlines": true,
mbed_official 82:122bb3ae6de5 71 "esp8266.provide-default" : false
mbed_official 82:122bb3ae6de5 72 }
mbed_official 82:122bb3ae6de5 73 }
mbed_official 82:122bb3ae6de5 74 }
mbed_official 86:92e4be20dc8b 75 ```
mbed_official 0:857719181846 76
mbed_official 82:122bb3ae6de5 77 For build-in WiFi, you do not need to set any `provide-default` values. Those are required
mbed_official 82:122bb3ae6de5 78 if you use external WiFi shield.
mbed_official 82:122bb3ae6de5 79
mbed_official 49:d44cac40bf15 80 Sample ```mbed_app.json``` files are provided for ESP8266 (```mbed_app_esp8266.json```), X-NUCLEO-IDW04A1 (```mbed_app_idw04a1.json```) and X-NUCLEO-IDW01M1 (```mbed_app_idw01m1```).
mbed_official 71:a0fbcc153b55 81
mbed_official 33:12f0df4d51d7 82
mbed_official 71:a0fbcc153b55 83 1. Compile and generate binary.
mbed_official 71:a0fbcc153b55 84 For example, for `GCC`:
mbed_official 71:a0fbcc153b55 85 ```
mbed_official 71:a0fbcc153b55 86 mbed compile -t GCC_ARM -m UBLOX_EVK_ODIN_W2
mbed_official 71:a0fbcc153b55 87 ```
mbed_official 32:bca3f5f442b3 88
mbed_official 71:a0fbcc153b55 89 1. Open a serial console session with the target platform using the following parameters:
mbed_official 36:aa0b6789bbd2 90 * **Baud rate:** 9600
mbed_official 36:aa0b6789bbd2 91 * **Data bits:** 8
mbed_official 36:aa0b6789bbd2 92 * **Stop bits:** 1
mbed_official 36:aa0b6789bbd2 93 * **Parity:** None
mbed_official 71:a0fbcc153b55 94
mbed_official 71:a0fbcc153b55 95 1. Copy or drag the application `mbed-os-example-wifi.bin` in the folder `mbed-os-example-wifi/BUILD/<TARGET NAME>/<PLATFORM NAME>` onto the target board.
mbed_official 36:aa0b6789bbd2 96
mbed_official 71:a0fbcc153b55 97 1. The serial console should display a similar output to below, indicating a successful Wi-Fi connection:
mbed_official 71:a0fbcc153b55 98 ```
mbed_official 71:a0fbcc153b55 99 WiFi example
mbed_official 71:a0fbcc153b55 100
mbed_official 71:a0fbcc153b55 101 Scan:
mbed_official 71:a0fbcc153b55 102 Network: Dave Hot Spot secured: Unknown BSSID: 00:01:02:03:04:05 RSSI: -58 Ch: 1
mbed_official 71:a0fbcc153b55 103 1 network available.
mbed_official 36:aa0b6789bbd2 104
mbed_official 71:a0fbcc153b55 105 Connecting...
mbed_official 71:a0fbcc153b55 106 Success
mbed_official 36:aa0b6789bbd2 107
mbed_official 71:a0fbcc153b55 108 MAC: 00:01:02:03:04:05
mbed_official 71:a0fbcc153b55 109 IP:
mbed_official 71:a0fbcc153b55 110 Netmask:
mbed_official 71:a0fbcc153b55 111 Gateway:
mbed_official 71:a0fbcc153b55 112 RSSI: -27
mbed_official 36:aa0b6789bbd2 113
mbed_official 71:a0fbcc153b55 114 Done
mbed_official 71:a0fbcc153b55 115 ```
mbed_official 0:857719181846 116
mbed_official 49:d44cac40bf15 117 ## Troubleshooting
mbed_official 0:857719181846 118
mbed_official 49:d44cac40bf15 119 If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
mbed_official 88:20f23913c4a7 120
mbed_official 88:20f23913c4a7 121 ### License and contributions
mbed_official 88:20f23913c4a7 122
mbed_official 88:20f23913c4a7 123 The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info.
mbed_official 88:20f23913c4a7 124
mbed_official 88:20f23913c4a7 125 This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.