Song Luan / Mbed OS mbed-os-example-wifi-ble
Committer:
se7ensong
Date:
Thu Mar 05 15:28:31 2020 +0000
Revision:
1:eaa032f2e818
Parent:
0:2c7230488e2e
example updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
se7ensong 0:2c7230488e2e 1 # mbed-os-example-wifi #
se7ensong 0:2c7230488e2e 2
se7ensong 0:2c7230488e2e 3 Wi-Fi example for Mbed OS
se7ensong 0:2c7230488e2e 4
se7ensong 0:2c7230488e2e 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).)
se7ensong 0:2c7230488e2e 6
se7ensong 0:2c7230488e2e 7 ## Getting started with the Wi-Fi API ##
se7ensong 0:2c7230488e2e 8
se7ensong 0:2c7230488e2e 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.
se7ensong 0:2c7230488e2e 10
se7ensong 0:2c7230488e2e 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.
se7ensong 0:2c7230488e2e 12
se7ensong 0:2c7230488e2e 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.
se7ensong 0:2c7230488e2e 14
se7ensong 0:2c7230488e2e 15 ### Supported hardware ###
se7ensong 0:2c7230488e2e 16
se7ensong 0:2c7230488e2e 17 * All Mbed OS boards with build-in Wi-Fi module:
se7ensong 0:2c7230488e2e 18 * [u-blox ODIN-W2](https://os.mbed.com/platforms/ublox-EVK-ODIN-W2/)
se7ensong 0:2c7230488e2e 19 * [Realtek RTL8195AM](https://os.mbed.com/platforms/REALTEK-RTL8195AM/)
se7ensong 0:2c7230488e2e 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).
se7ensong 0:2c7230488e2e 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).
se7ensong 0:2c7230488e2e 22 * [Advantech WISE-150](https://os.mbed.com/modules/advantech-wise-1530/)
se7ensong 0:2c7230488e2e 23 * USI WM-BN-BM-22
se7ensong 0:2c7230488e2e 24 * MxChip EMW3166
se7ensong 0:2c7230488e2e 25 * Boards with external WiFi shields.
se7ensong 0:2c7230488e2e 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)_.
se7ensong 0:2c7230488e2e 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)_.
se7ensong 0:2c7230488e2e 28 * [NUCLEO-F429ZI](https://os.mbed.com/platforms/ST-Nucleo-F429ZI/) with ESP8266-01 module using pins D1 and D0.
se7ensong 0:2c7230488e2e 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.
se7ensong 0:2c7230488e2e 30
se7ensong 0:2c7230488e2e 31 #### Adding connectivity driver
se7ensong 0:2c7230488e2e 32
se7ensong 0:2c7230488e2e 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.
se7ensong 0:2c7230488e2e 34
se7ensong 0:2c7230488e2e 35 ```
se7ensong 0:2c7230488e2e 36 mbed add <driver>
se7ensong 0:2c7230488e2e 37 ```
se7ensong 0:2c7230488e2e 38
se7ensong 0:2c7230488e2e 39 For example adding ISM43362 driver `mbed add wifi-ism43362` or X-Nucleo-IDW01M1 driver `mbed add wifi-x-nucleo-idw01m1`
se7ensong 0:2c7230488e2e 40 The ESP8266 driver is already suplied by Mbed OS.
se7ensong 0:2c7230488e2e 41
se7ensong 0:2c7230488e2e 42 Then pin names need to be configured as instructed in the drivers README file.
se7ensong 0:2c7230488e2e 43
se7ensong 0:2c7230488e2e 44 ## Getting started ##
se7ensong 0:2c7230488e2e 45
se7ensong 0:2c7230488e2e 46 1. Import the example.
se7ensong 0:2c7230488e2e 47
se7ensong 0:2c7230488e2e 48 ```
se7ensong 0:2c7230488e2e 49 mbed import mbed-os-example-wifi
se7ensong 0:2c7230488e2e 50 cd mbed-os-example-wifi
se7ensong 0:2c7230488e2e 51 ```
se7ensong 0:2c7230488e2e 52
se7ensong 0:2c7230488e2e 53 1. Configure the Wi-Fi shield and settings.
se7ensong 0:2c7230488e2e 54 Edit ```mbed_app.json``` to include the correct Wi-Fi shield, SSID and password:
se7ensong 0:2c7230488e2e 55
se7ensong 0:2c7230488e2e 56 ```json
se7ensong 0:2c7230488e2e 57 {
se7ensong 0:2c7230488e2e 58 "config": {
se7ensong 0:2c7230488e2e 59 "wifi-ssid": {
se7ensong 0:2c7230488e2e 60 "help": "WiFi SSID",
se7ensong 0:2c7230488e2e 61 "value": "\"SSID\""
se7ensong 0:2c7230488e2e 62 },
se7ensong 0:2c7230488e2e 63 "wifi-password": {
se7ensong 0:2c7230488e2e 64 "help": "WiFi Password",
se7ensong 0:2c7230488e2e 65 "value": "\"PASSWORD\""
se7ensong 0:2c7230488e2e 66 }
se7ensong 0:2c7230488e2e 67 },
se7ensong 0:2c7230488e2e 68 "target_overrides": {
se7ensong 0:2c7230488e2e 69 "*": {
se7ensong 0:2c7230488e2e 70 "platform.stdio-convert-newlines": true,
se7ensong 0:2c7230488e2e 71 "esp8266.provide-default" : false
se7ensong 0:2c7230488e2e 72 }
se7ensong 0:2c7230488e2e 73 }
se7ensong 0:2c7230488e2e 74 }
se7ensong 0:2c7230488e2e 75 ```
se7ensong 0:2c7230488e2e 76
se7ensong 0:2c7230488e2e 77 For build-in WiFi, you do not need to set any `provide-default` values. Those are required
se7ensong 0:2c7230488e2e 78 if you use external WiFi shield.
se7ensong 0:2c7230488e2e 79
se7ensong 0:2c7230488e2e 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```).
se7ensong 0:2c7230488e2e 81
se7ensong 0:2c7230488e2e 82
se7ensong 0:2c7230488e2e 83 1. Compile and generate binary.
se7ensong 0:2c7230488e2e 84 For example, for `GCC`:
se7ensong 0:2c7230488e2e 85 ```
se7ensong 0:2c7230488e2e 86 mbed compile -t GCC_ARM -m UBLOX_EVK_ODIN_W2
se7ensong 0:2c7230488e2e 87 ```
se7ensong 0:2c7230488e2e 88
se7ensong 0:2c7230488e2e 89 1. Open a serial console session with the target platform using the following parameters:
se7ensong 0:2c7230488e2e 90 * **Baud rate:** 9600
se7ensong 0:2c7230488e2e 91 * **Data bits:** 8
se7ensong 0:2c7230488e2e 92 * **Stop bits:** 1
se7ensong 0:2c7230488e2e 93 * **Parity:** None
se7ensong 0:2c7230488e2e 94
se7ensong 0:2c7230488e2e 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.
se7ensong 0:2c7230488e2e 96
se7ensong 0:2c7230488e2e 97 1. The serial console should display a similar output to below, indicating a successful Wi-Fi connection:
se7ensong 0:2c7230488e2e 98 ```
se7ensong 0:2c7230488e2e 99 WiFi example
se7ensong 0:2c7230488e2e 100
se7ensong 0:2c7230488e2e 101 Scan:
se7ensong 0:2c7230488e2e 102 Network: Dave Hot Spot secured: Unknown BSSID: 00:01:02:03:04:05 RSSI: -58 Ch: 1
se7ensong 0:2c7230488e2e 103 1 network available.
se7ensong 0:2c7230488e2e 104
se7ensong 0:2c7230488e2e 105 Connecting...
se7ensong 0:2c7230488e2e 106 Success
se7ensong 0:2c7230488e2e 107
se7ensong 0:2c7230488e2e 108 MAC: 00:01:02:03:04:05
se7ensong 0:2c7230488e2e 109 IP: 192.168.0.5
se7ensong 0:2c7230488e2e 110 Netmask: 255.255.255.0
se7ensong 0:2c7230488e2e 111 Gateway: 192.168.0.1
se7ensong 0:2c7230488e2e 112 RSSI: -27
se7ensong 0:2c7230488e2e 113
se7ensong 0:2c7230488e2e 114 Done
se7ensong 0:2c7230488e2e 115 ```
se7ensong 0:2c7230488e2e 116
se7ensong 0:2c7230488e2e 117 ## Troubleshooting
se7ensong 0:2c7230488e2e 118
se7ensong 0:2c7230488e2e 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.
se7ensong 0:2c7230488e2e 120
se7ensong 0:2c7230488e2e 121 ### License and contributions
se7ensong 0:2c7230488e2e 122
se7ensong 0:2c7230488e2e 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.
se7ensong 0:2c7230488e2e 124
se7ensong 0:2c7230488e2e 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.