WiFi example for mbed OS, fork from https://github.com/ARMmbed/mbed-os-example-wifi

This is an example of a Wi-Fi application using the Wi-Fi and network socket APIs that Mbed OS provides.

The program brings up the Wi-Fi and the underlying network interface and uses it to scan available networks, connects to a network, prints interface and connection details and performs an HTTP operation.

For more information about Wi-Fi APIs, please visit the Mbed OS Wi-Fi documentation.

This example has been used on the following platforms

Committer:
1050186
Date:
Wed Dec 12 05:42:30 2018 +0000
Revision:
7:ab1ae55ec482
Parent:
5:01be82512f7a
Delete unnecessary files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-Renesas-Electronics-Corp 0:0593b97dec0b 1 # mbed-os-example-wifi #
group-Renesas-Electronics-Corp 0:0593b97dec0b 2
group-Renesas-Electronics-Corp 0:0593b97dec0b 3 Wi-Fi example for Mbed OS
group-Renesas-Electronics-Corp 0:0593b97dec0b 4
group-Renesas-Electronics-Corp 0:0593b97dec0b 5 ## Getting started with the Wi-Fi API ##
group-Renesas-Electronics-Corp 0:0593b97dec0b 6
group-Renesas-Electronics-Corp 0:0593b97dec0b 7 This is an example of a Wi-Fi application using the Wi-Fi and network socket APIs that [Mbed OS](https://github.com/ARMmbed/mbed-os) provides.
group-Renesas-Electronics-Corp 0:0593b97dec0b 8
group-Renesas-Electronics-Corp 0:0593b97dec0b 9 The program brings up the Wi-Fi and the underlying network interface and uses it to scan available networks, connects to a network, prints interface and connection details and performs an HTTP operation.
group-Renesas-Electronics-Corp 0:0593b97dec0b 10
group-Renesas-Electronics-Corp 0:0593b97dec0b 11 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.
group-Renesas-Electronics-Corp 0:0593b97dec0b 12
group-Renesas-Electronics-Corp 0:0593b97dec0b 13 ### Supported hardware ###
group-Renesas-Electronics-Corp 0:0593b97dec0b 14
1050186 5:01be82512f7a 15 * All Mbed OS boards with build-in Wi-Fi module:
1050186 5:01be82512f7a 16 * [u-blox ODIN-W2](https://os.mbed.com/platforms/ublox-EVK-ODIN-W2/)
1050186 5:01be82512f7a 17 * [Realtek RTL8195AM](https://os.mbed.com/platforms/REALTEK-RTL8195AM/)
1050186 5:01be82512f7a 18 * [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).
1050186 5:01be82512f7a 19 * [ST DISCO_F413ZH board](https://os.mbed.com/platforms/ST-Discovery-F413H/) with integrated [ISM43362 WiFi Inventek module](https://github.com/ARMmbed/wifi-ism43362).
1050186 5:01be82512f7a 20 * [Advantech WISE-150](https://os.mbed.com/modules/advantech-wise-1530/)
1050186 5:01be82512f7a 21 * USI WM-BN-BM-22
1050186 5:01be82512f7a 22 * MxChip EMW3166
1050186 5:01be82512f7a 23 * [GR-LYCHEE](https://os.mbed.com/platforms/Renesas-GR-LYCHEE/) with ESP32 module using pins P5_3, P3_14, P7_1 and P0_1.
1050186 5:01be82512f7a 24 * Boards with external WiFi shields.
1050186 5:01be82512f7a 25 * [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)_.
1050186 5:01be82512f7a 26 * [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)_.
1050186 5:01be82512f7a 27 * [NUCLEO-F429ZI](https://os.mbed.com/platforms/ST-Nucleo-F429ZI/) with ESP8266-01 module using pins D1 and D0.
1050186 5:01be82512f7a 28 * [NUCLEO-L476RG](https://os.mbed.com/platforms/ST-Nucleo-L476RG/) with ESP8266-01 module using pins D8 and D2.
1050186 5:01be82512f7a 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.
group-Renesas-Electronics-Corp 0:0593b97dec0b 30
1050186 5:01be82512f7a 31 #### Adding connectivity driver
1050186 5:01be82512f7a 32
1050186 5:01be82512f7a 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.
1050186 5:01be82512f7a 34
1050186 5:01be82512f7a 35 ```
1050186 5:01be82512f7a 36 mbed add <driver>
1050186 5:01be82512f7a 37 ```
1050186 5:01be82512f7a 38
1050186 5:01be82512f7a 39 For example adding ISM43362 driver `mbed add wifi-ism43362` or ESP8266 `mbed add esp8266-driver` or X-Nucleo-IDW01M1 driver `mbed add wifi-x-nucleo-idw01m1`
1050186 5:01be82512f7a 40
1050186 5:01be82512f7a 41 Then pin names need to be configured as instructed in the drivers README file.
group-Renesas-Electronics-Corp 0:0593b97dec0b 42
group-Renesas-Electronics-Corp 0:0593b97dec0b 43 #### Connecting the ESP8266 ####
group-Renesas-Electronics-Corp 0:0593b97dec0b 44
group-Renesas-Electronics-Corp 0:0593b97dec0b 45 To connect the ESP8266 module to your development board, look at the [ESP8266 Cookbook page](https://developer.mbed.org/users/4180_1/notebook/using-the-esp8266-with-the-mbed-lpc1768/). In general, this means hooking up the ESP8266 TX pin to `D0` and the ESP8266 RX pin to `D1` on your development board.
group-Renesas-Electronics-Corp 0:0593b97dec0b 46
group-Renesas-Electronics-Corp 0:0593b97dec0b 47 **Note:** On NUCLEO development boards, pins `D0` and `D1` are used for serial communication with the computer. Use pins `D8` (to ESP8266 TX) and `D2` (to ESP8266 RX) instead.
group-Renesas-Electronics-Corp 0:0593b97dec0b 48
group-Renesas-Electronics-Corp 0:0593b97dec0b 49 #### Connecting the X-NUCLEO-IDW0XX1 ####
group-Renesas-Electronics-Corp 0:0593b97dec0b 50
group-Renesas-Electronics-Corp 0:0593b97dec0b 51 To connect the [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://developer.mbed.org/components/X-NUCLEO-IDW01M1/) expansion board to your NUCLEO development board, plug the expansion board on top of the NUCLEO board using the Arduino or Morpho connector.
group-Renesas-Electronics-Corp 0:0593b97dec0b 52
group-Renesas-Electronics-Corp 0:0593b97dec0b 53 ## Getting started ##
group-Renesas-Electronics-Corp 0:0593b97dec0b 54
group-Renesas-Electronics-Corp 0:0593b97dec0b 55 1. Import the example.
group-Renesas-Electronics-Corp 0:0593b97dec0b 56
group-Renesas-Electronics-Corp 0:0593b97dec0b 57 ```
group-Renesas-Electronics-Corp 0:0593b97dec0b 58 mbed import mbed-os-example-wifi
group-Renesas-Electronics-Corp 0:0593b97dec0b 59 cd mbed-os-example-wifi
group-Renesas-Electronics-Corp 0:0593b97dec0b 60 ```
group-Renesas-Electronics-Corp 0:0593b97dec0b 61
1050186 5:01be82512f7a 62 1. Configure the Wi-Fi shield and settings.
group-Renesas-Electronics-Corp 0:0593b97dec0b 63 Edit ```mbed_app.json``` to include the correct Wi-Fi shield, SSID and password:
group-Renesas-Electronics-Corp 0:0593b97dec0b 64
1050186 5:01be82512f7a 65 ```json
1050186 5:01be82512f7a 66 {
1050186 5:01be82512f7a 67 "config": {
1050186 5:01be82512f7a 68 "wifi-ssid": {
1050186 5:01be82512f7a 69 "help": "WiFi SSID",
1050186 5:01be82512f7a 70 "value": "\"SSID\""
1050186 5:01be82512f7a 71 },
1050186 5:01be82512f7a 72 "wifi-password": {
1050186 5:01be82512f7a 73 "help": "WiFi Password",
1050186 5:01be82512f7a 74 "value": "\"PASSWORD\""
1050186 5:01be82512f7a 75 }
1050186 5:01be82512f7a 76 },
1050186 5:01be82512f7a 77 "target_overrides": {
1050186 5:01be82512f7a 78 "*": {
1050186 5:01be82512f7a 79 "platform.stdio-convert-newlines": true,
1050186 5:01be82512f7a 80 "esp8266.provide-default" : false
1050186 5:01be82512f7a 81 }
1050186 5:01be82512f7a 82 }
1050186 5:01be82512f7a 83 }
1050186 5:01be82512f7a 84 ```
group-Renesas-Electronics-Corp 0:0593b97dec0b 85
1050186 5:01be82512f7a 86 For build-in WiFi, you do not need to set any `provide-default` values. Those are required
1050186 5:01be82512f7a 87 if you use external WiFi shield.
group-Renesas-Electronics-Corp 0:0593b97dec0b 88
1050186 5:01be82512f7a 89 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```).
1050186 5:01be82512f7a 90
group-Renesas-Electronics-Corp 0:0593b97dec0b 91
1050186 5:01be82512f7a 92 1. Compile and generate binary.
1050186 5:01be82512f7a 93 For example, for `GCC`:
1050186 5:01be82512f7a 94 ```
1050186 5:01be82512f7a 95 mbed compile -t GCC_ARM -m UBLOX_EVK_ODIN_W2
1050186 5:01be82512f7a 96 ```
group-Renesas-Electronics-Corp 0:0593b97dec0b 97
1050186 5:01be82512f7a 98 1. Open a serial console session with the target platform using the following parameters:
group-Renesas-Electronics-Corp 0:0593b97dec0b 99 * **Baud rate:** 9600
group-Renesas-Electronics-Corp 0:0593b97dec0b 100 * **Data bits:** 8
group-Renesas-Electronics-Corp 0:0593b97dec0b 101 * **Stop bits:** 1
group-Renesas-Electronics-Corp 0:0593b97dec0b 102 * **Parity:** None
1050186 5:01be82512f7a 103
1050186 5:01be82512f7a 104 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.
group-Renesas-Electronics-Corp 0:0593b97dec0b 105
1050186 5:01be82512f7a 106 1. The serial console should display a similar output to below, indicating a successful Wi-Fi connection:
1050186 5:01be82512f7a 107 ```
1050186 5:01be82512f7a 108 WiFi example
1050186 5:01be82512f7a 109
1050186 5:01be82512f7a 110 Scan:
1050186 5:01be82512f7a 111 Network: Dave Hot Spot secured: Unknown BSSID: 00:01:02:03:04:05 RSSI: -58 Ch: 1
1050186 5:01be82512f7a 112 1 network available.
group-Renesas-Electronics-Corp 0:0593b97dec0b 113
1050186 5:01be82512f7a 114 Connecting...
1050186 5:01be82512f7a 115 Success
group-Renesas-Electronics-Corp 0:0593b97dec0b 116
1050186 5:01be82512f7a 117 MAC: 00:01:02:03:04:05
1050186 5:01be82512f7a 118 IP: 192.168.0.5
1050186 5:01be82512f7a 119 Netmask: 255.255.255.0
1050186 5:01be82512f7a 120 Gateway: 192.168.0.1
1050186 5:01be82512f7a 121 RSSI: -27
group-Renesas-Electronics-Corp 0:0593b97dec0b 122
1050186 5:01be82512f7a 123 Sending HTTP request to www.arm.com...
1050186 5:01be82512f7a 124 sent 38 [GET / HTTP/1.1]
1050186 5:01be82512f7a 125 recv 64 [HTTP/1.1 301 Moved Permanently]
group-Renesas-Electronics-Corp 0:0593b97dec0b 126
1050186 5:01be82512f7a 127 Done
1050186 5:01be82512f7a 128 ```
group-Renesas-Electronics-Corp 0:0593b97dec0b 129
group-Renesas-Electronics-Corp 0:0593b97dec0b 130 ## Troubleshooting
group-Renesas-Electronics-Corp 0:0593b97dec0b 131
group-Renesas-Electronics-Corp 0:0593b97dec0b 132 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.