mayuresh bharmoria / Mbed OS mbed-os-example-wifi
Committer:
mayur098
Date:
Thu Jun 21 17:50:21 2018 +0000
Revision:
0:8f8e8f3cbd1c
first commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mayur098 0:8f8e8f3cbd1c 1 # mbed-os-example-wifi #
mayur098 0:8f8e8f3cbd1c 2
mayur098 0:8f8e8f3cbd1c 3 Wi-Fi example for Mbed OS
mayur098 0:8f8e8f3cbd1c 4
mayur098 0:8f8e8f3cbd1c 5 ## Getting started with the Wi-Fi API ##
mayur098 0:8f8e8f3cbd1c 6
mayur098 0:8f8e8f3cbd1c 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.
mayur098 0:8f8e8f3cbd1c 8
mayur098 0:8f8e8f3cbd1c 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.
mayur098 0:8f8e8f3cbd1c 10
mayur098 0:8f8e8f3cbd1c 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.
mayur098 0:8f8e8f3cbd1c 12
mayur098 0:8f8e8f3cbd1c 13 ### Supported hardware ###
mayur098 0:8f8e8f3cbd1c 14
mayur098 0:8f8e8f3cbd1c 15 * [u-blox Odin board](https://os.mbed.com/platforms/ublox-EVK-ODIN-W2/) built-in Wi-Fi module.
mayur098 0:8f8e8f3cbd1c 16 * [Realtek RTL8195AM](https://os.mbed.com/platforms/REALTEK-RTL8195AM/) built-in Wi-Fi module.
mayur098 0:8f8e8f3cbd1c 17 * [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)_.
mayur098 0:8f8e8f3cbd1c 18 * [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)_.
mayur098 0:8f8e8f3cbd1c 19 * [NUCLEO-F429ZI](https://os.mbed.com/platforms/ST-Nucleo-F429ZI/) with ESP8266-01 module using pins D1 and D0.
mayur098 0:8f8e8f3cbd1c 20 * [NUCLEO-L476RG](https://os.mbed.com/platforms/ST-Nucleo-L476RG/) with ESP8266-01 module using pins D8 and D2.
mayur098 0:8f8e8f3cbd1c 21 * [GR-LYCHEE](https://os.mbed.com/platforms/Renesas-GR-LYCHEE/) with ESP32 module using pins P5_3, P3_14, P7_1 and P0_1.
mayur098 0:8f8e8f3cbd1c 22 * 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.
mayur098 0:8f8e8f3cbd1c 23 *(The Mbed target board the Wi-Fi shield connects to shouldn't have any other network interface, for example Ethernet.)*
mayur098 0:8f8e8f3cbd1c 24
mayur098 0:8f8e8f3cbd1c 25 ESP8266 is a fallback option if the build is for unsupported platform.
mayur098 0:8f8e8f3cbd1c 26
mayur098 0:8f8e8f3cbd1c 27 #### Connecting the ESP8266 ####
mayur098 0:8f8e8f3cbd1c 28
mayur098 0:8f8e8f3cbd1c 29 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.
mayur098 0:8f8e8f3cbd1c 30
mayur098 0:8f8e8f3cbd1c 31 **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.
mayur098 0:8f8e8f3cbd1c 32
mayur098 0:8f8e8f3cbd1c 33 #### Connecting the X-NUCLEO-IDW0XX1 ####
mayur098 0:8f8e8f3cbd1c 34
mayur098 0:8f8e8f3cbd1c 35 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.
mayur098 0:8f8e8f3cbd1c 36
mayur098 0:8f8e8f3cbd1c 37 ## Getting started ##
mayur098 0:8f8e8f3cbd1c 38
mayur098 0:8f8e8f3cbd1c 39 1. Import the example.
mayur098 0:8f8e8f3cbd1c 40
mayur098 0:8f8e8f3cbd1c 41 ```
mayur098 0:8f8e8f3cbd1c 42 mbed import mbed-os-example-wifi
mayur098 0:8f8e8f3cbd1c 43 cd mbed-os-example-wifi
mayur098 0:8f8e8f3cbd1c 44 ```
mayur098 0:8f8e8f3cbd1c 45
mayur098 0:8f8e8f3cbd1c 46 2. Configure the Wi-Fi shield to use.
mayur098 0:8f8e8f3cbd1c 47
mayur098 0:8f8e8f3cbd1c 48 Edit ```mbed_app.json``` to include the correct Wi-Fi shield, SSID and password:
mayur098 0:8f8e8f3cbd1c 49
mayur098 0:8f8e8f3cbd1c 50 ```
mayur098 0:8f8e8f3cbd1c 51 "config": {
mayur098 0:8f8e8f3cbd1c 52 "wifi-shield": {
mayur098 0:8f8e8f3cbd1c 53 "help": "Options are internal, WIFI_ESP8266, WIFI_IDW0XX1, WIFI_ESP32",
mayur098 0:8f8e8f3cbd1c 54 "value": "internal"
mayur098 0:8f8e8f3cbd1c 55 },
mayur098 0:8f8e8f3cbd1c 56 "wifi-ssid": {
mayur098 0:8f8e8f3cbd1c 57 "help": "WiFi SSID",
mayur098 0:8f8e8f3cbd1c 58 "value": "\"SSID\""
mayur098 0:8f8e8f3cbd1c 59 },
mayur098 0:8f8e8f3cbd1c 60 "wifi-password": {
mayur098 0:8f8e8f3cbd1c 61 "help": "WiFi Password",
mayur098 0:8f8e8f3cbd1c 62 "value": "\"Password\""
mayur098 0:8f8e8f3cbd1c 63 }
mayur098 0:8f8e8f3cbd1c 64 },
mayur098 0:8f8e8f3cbd1c 65 ```
mayur098 0:8f8e8f3cbd1c 66
mayur098 0:8f8e8f3cbd1c 67 Sample ```mbed_app.json``` files are provided for ESP8266 (```mbed_app_esp8266.json```), X-NUCLEO-IDW04A1 (```mbed_app_idw04a1.json```), X-NUCLEO-IDW01M1 (```mbed_app_idw01m1```) and ESP32 (```mbed_app_esp32.json```).
mayur098 0:8f8e8f3cbd1c 68
mayur098 0:8f8e8f3cbd1c 69 For built-in Wi-Fi, ignore the value of `wifi-shield`.
mayur098 0:8f8e8f3cbd1c 70
mayur098 0:8f8e8f3cbd1c 71 3. Compile and generate binary.
mayur098 0:8f8e8f3cbd1c 72
mayur098 0:8f8e8f3cbd1c 73 For example, for `GCC`:
mayur098 0:8f8e8f3cbd1c 74
mayur098 0:8f8e8f3cbd1c 75 ```
mayur098 0:8f8e8f3cbd1c 76 mbed compile -t GCC_ARM -m UBLOX_EVK_ODIN_W2
mayur098 0:8f8e8f3cbd1c 77 ```
mayur098 0:8f8e8f3cbd1c 78
mayur098 0:8f8e8f3cbd1c 79 4. Open a serial console session with the target platform using the following parameters:
mayur098 0:8f8e8f3cbd1c 80
mayur098 0:8f8e8f3cbd1c 81 * **Baud rate:** 9600
mayur098 0:8f8e8f3cbd1c 82 * **Data bits:** 8
mayur098 0:8f8e8f3cbd1c 83 * **Stop bits:** 1
mayur098 0:8f8e8f3cbd1c 84 * **Parity:** None
mayur098 0:8f8e8f3cbd1c 85
mayur098 0:8f8e8f3cbd1c 86 5. 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.
mayur098 0:8f8e8f3cbd1c 87
mayur098 0:8f8e8f3cbd1c 88 6. The serial console should display a similar output to below, indicating a successful Wi-Fi connection:
mayur098 0:8f8e8f3cbd1c 89
mayur098 0:8f8e8f3cbd1c 90 ```
mayur098 0:8f8e8f3cbd1c 91 WiFi example
mayur098 0:8f8e8f3cbd1c 92
mayur098 0:8f8e8f3cbd1c 93 Scan:
mayur098 0:8f8e8f3cbd1c 94 Network: Dave Hot Spot secured: Unknown BSSID: 00:01:02:03:04:05 RSSI: -58 Ch: 1
mayur098 0:8f8e8f3cbd1c 95 1 network available.
mayur098 0:8f8e8f3cbd1c 96
mayur098 0:8f8e8f3cbd1c 97 Connecting...
mayur098 0:8f8e8f3cbd1c 98 Success
mayur098 0:8f8e8f3cbd1c 99
mayur098 0:8f8e8f3cbd1c 100 MAC: 00:01:02:03:04:05
mayur098 0:8f8e8f3cbd1c 101 IP: 192.168.0.5
mayur098 0:8f8e8f3cbd1c 102 Netmask: 255.255.255.0
mayur098 0:8f8e8f3cbd1c 103 Gateway: 192.168.0.1
mayur098 0:8f8e8f3cbd1c 104 RSSI: -27
mayur098 0:8f8e8f3cbd1c 105
mayur098 0:8f8e8f3cbd1c 106 Sending HTTP request to www.arm.com...
mayur098 0:8f8e8f3cbd1c 107 sent 38 [GET / HTTP/1.1]
mayur098 0:8f8e8f3cbd1c 108 recv 64 [HTTP/1.1 301 Moved Permanently]
mayur098 0:8f8e8f3cbd1c 109
mayur098 0:8f8e8f3cbd1c 110 Done
mayur098 0:8f8e8f3cbd1c 111 ```
mayur098 0:8f8e8f3cbd1c 112
mayur098 0:8f8e8f3cbd1c 113 ## Troubleshooting
mayur098 0:8f8e8f3cbd1c 114
mayur098 0:8f8e8f3cbd1c 115 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.