simple wifi test program. Will connect to an HTTP server for testing.

Fork of mbed-os-example-wifi-adv-wise-1530 by Alan Chuang

Committer:
chuanga
Date:
Fri Feb 22 13:13:10 2019 +0800
Revision:
0:3c5e2cc8251b
adding wifi example program for wise-1530 wifi module

Who changed what in which revision?

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