├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── CONTRIBUTING.md ├── Jenkinsfile ├── LICENSE ├── README.md ├── drivers └── COMPONENT_wifi_ism43362.lib ├── main.cpp ├── mbed-os.lib ├── mbed_app.json ├── mbed_app_esp8266.json ├── resources ├── official_armmbed_example_badge.png └── warning.png └── tests ├── README.md ├── wifi.log └── wifi_scan.log /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: 'type: bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 28 | 29 | ### Description of defect 30 | 31 | 35 | 36 | 37 | #### Target(s) affected by this defect ? 38 | 39 | 40 | #### Toolchain(s) (name and version) displaying this defect ? 41 | 42 | 43 | #### What version of Mbed-os are you using (tag or sha) ? 44 | 53 | 54 | 55 | #### What version(s) of tools are you using. List all that apply (E.g. mbed-cli) 56 | 57 | 58 | #### How is this defect reproduced ? 59 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Mbed OS 2 | 3 | Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor. 4 | 5 | To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html). 6 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [ 2 | [$class: 'StringParameterDefinition', name: 'mbed_os_revision', defaultValue: '', description: 'Revision of mbed-os to build. Use format "pull/PR-NUMBER/head" to access mbed-os PR'], 3 | [$class: 'BooleanParameterDefinition', name: 'smoke_test', defaultValue: true, description: 'Runs HW smoke test with example'] 4 | ]]]) 5 | 6 | if (env.MBED_OS_REVISION == null) { 7 | echo 'First run in this branch, using default parameter values' 8 | env.MBED_OS_REVISION = '' 9 | } 10 | if (env.MBED_OS_REVISION == '') { 11 | echo 'Using mbed OS revision from mbed-os.lib' 12 | } else { 13 | echo "Using given mbed OS revision: ${env.MBED_OS_REVISION}" 14 | if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) { 15 | echo "Revision is a Pull Request" 16 | } 17 | } 18 | 19 | // Map RaaS instances to corresponding test suites 20 | def raas = [ 21 | "wifi_smoke_disco_l475vg_iot01a.json": "mervi" 22 | ] 23 | 24 | // List of targets with supported RF shields to compile 25 | def targets = [ 26 | "K64F": ["esp8266-driver"], 27 | "DISCO_L475VG_IOT01A": ["wifi-ism43362"] 28 | ] 29 | 30 | // Map toolchains to compilers 31 | def toolchains = [ 32 | ARM: "armcc", 33 | GCC_ARM: "arm-none-eabi-gcc" 34 | ] 35 | 36 | // Supported RF shields 37 | def radioshields = [ 38 | "internal", 39 | "esp8266-driver", 40 | "wifi-ism43362" 41 | ] 42 | 43 | def stepsForParallel = [:] 44 | 45 | // Jenkins pipeline does not support map.each, we need to use oldschool for loop 46 | for (int i = 0; i < targets.size(); i++) { 47 | for(int j = 0; j < toolchains.size(); j++) { 48 | for(int k = 0; k < radioshields.size(); k++) { 49 | def target = targets.keySet().asList().get(i) 50 | def allowed_shields = targets.get(target) 51 | def toolchain = toolchains.keySet().asList().get(j) 52 | def compilerLabel = toolchains.get(toolchain) 53 | def radioshield = radioshields.get(k) 54 | 55 | def stepName = "${target} ${toolchain} ${radioshield}" 56 | if(allowed_shields.contains(radioshield)) { 57 | stepsForParallel[stepName] = buildStep(target, compilerLabel, toolchain, radioshield) 58 | } 59 | } 60 | } 61 | } 62 | 63 | def parallelRunSmoke = [:] 64 | 65 | // Need to compare boolean against string value 66 | if (params.smoke_test == true) { 67 | echo "Running smoke tests" 68 | // Generate smoke tests based on suite amount 69 | for(int i = 0; i < raas.size(); i++) { 70 | def suite_to_run = raas.keySet().asList().get(i) 71 | def raasName = raas.get(suite_to_run) 72 | 73 | // Parallel execution needs unique step names. Remove .json file ending. 74 | def smokeStep = "${raasName} ${suite_to_run.substring(0, suite_to_run.indexOf('.'))}" 75 | parallelRunSmoke[smokeStep] = run_smoke(raasName, suite_to_run, toolchains, targets, radioshields) 76 | } 77 | } else { 78 | echo "Skipping smoke tests" 79 | } 80 | 81 | timestamps { 82 | parallel stepsForParallel 83 | parallel parallelRunSmoke 84 | } 85 | 86 | def buildStep(target, compilerLabel, toolchain, radioShield) { 87 | return { 88 | stage ("${target}_${compilerLabel}_${radioShield}") { 89 | node ("${compilerLabel}") { 90 | deleteDir() 91 | dir("mbed-os-systemtest") { 92 | git "git@github.com:ARMmbed/mbed-os-systemtest.git" 93 | } 94 | dir("mbed-os-example-wifi") { 95 | checkout scm 96 | def config_file = "mbed_app.json" 97 | 98 | if ("${target}" == "K64F") { 99 | config_file = "mbed_app_esp8266.json" 100 | } 101 | 102 | //Update json files for internal tests 103 | execute("python ../mbed-os-systemtest/wifi/configuration-scripts/update-mbed-app-json.py") 104 | 105 | // Set mbed-os to revision received as parameter 106 | execute ("mbed deploy --protocol ssh") 107 | if (params.mbed_os_revision != '') { 108 | dir ("mbed-os") { 109 | if (params.mbed_os_revision.matches('pull/\\d+/head')) { 110 | execute("git fetch origin ${params.mbed_os_revision}:PR") 111 | execute("git checkout PR") 112 | } else { 113 | execute ("git checkout ${params.mbed_os_revision}") 114 | } 115 | } 116 | } 117 | execute("mbed new .") 118 | 119 | execute ("mbed compile --build out/${target}_${toolchain}_${radioShield}/ -m ${target} -t ${toolchain} -c --app-config ${config_file}") 120 | } 121 | stash name: "${target}_${toolchain}_${radioShield}", includes: '**/mbed-os-example-wifi.bin' 122 | archive '**/mbed-os-example-wifi.bin' 123 | step([$class: 'WsCleanup']) 124 | } 125 | } 126 | } 127 | } 128 | 129 | def run_smoke(raasName, suite_to_run, toolchains, targets, radioshields) { 130 | return { 131 | env.RAAS_USERNAME = "ci" 132 | env.RAAS_PASSWORD = "ci" 133 | // Remove .json from suite name 134 | def suiteName = suite_to_run.substring(0, suite_to_run.indexOf('.')) 135 | stage ("smoke_${raasName}_${suiteName}") { 136 | //node is actually the type of machine, i.e., mesh-test boild down to linux 137 | node ("linux") { 138 | deleteDir() 139 | dir("mbed-clitest") { 140 | git "git@github.com:ARMmbed/mbed-clitest.git" 141 | execute("git checkout ${env.LATEST_CLITEST_STABLE_REL}") 142 | dir("mbed-clitest-suites") { 143 | git "git@github.com:ARMmbed/mbed-clitest-suites.git" 144 | dir("cellular") { 145 | git "git@github.com:ARMmbed/mbed-clitest-cellular.git" 146 | } 147 | } 148 | 149 | for (int i = 0; i < targets.size(); i++) { 150 | for(int j = 0; j < toolchains.size(); j++) { 151 | for(int k = 0; k < radioshields.size(); k++) { 152 | def target = targets.keySet().asList().get(i) 153 | def allowed_shields = targets.get(target) 154 | def toolchain = toolchains.keySet().asList().get(j) 155 | def radioshield = radioshields.get(k) 156 | 157 | if(allowed_shields.contains(radioshield)) { 158 | unstash "${target}_${toolchain}_${radioshield}" 159 | } 160 | } 161 | } 162 | } 163 | execute("python clitest.py --suitedir mbed-clitest-suites/suites/ --suite ${suite_to_run} --type hardware --reset \ 164 | --raas https://${raasName}.mbedcloudtesting.com:443 --tcdir mbed-clitest-suites/cellular --raas_queue --raas_queue_timeout 3600 \ 165 | --raas_share_allocs --failure_return_value -v -w --log log_${raasName}_${suiteName}") 166 | archive "log_${raasName}_${suiteName}/**/*" 167 | } 168 | } 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](./resources/warning.png) 2 | ## This example has been deprecated 3 | 4 | Please use the [sockets example](https://github.com/ARMmbed/mbed-os-example-sockets). It contains all the functionality of the old Wi-Fi example. 5 | 6 | --- 7 | 8 | # mbed-os-example-wifi # 9 | 10 | Wi-Fi example for Mbed OS 11 | 12 | (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).) 13 | 14 | ## Getting started with the Wi-Fi API ## 15 | 16 | This is an example of a Wi-Fi application using the Wi-Fi APIs that [Mbed OS](https://github.com/ARMmbed/mbed-os) provides. 17 | 18 | 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. 19 | 20 | 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. 21 | 22 | ### Supported hardware ### 23 | 24 | * All Mbed OS boards with build-in Wi-Fi module: 25 | * [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). 26 | * [ST DISCO_F413ZH board](https://os.mbed.com/platforms/ST-Discovery-F413H/) with integrated [ISM43362 WiFi Inventek module](https://github.com/ARMmbed/wifi-ism43362). 27 | * Boards with external WiFi shields. 28 | * [NUCLEO-F429ZI](https://os.mbed.com/platforms/ST-Nucleo-F429ZI/) with ESP8266-01 module using pins D1 and D0. 29 | 30 | ## Getting started ## 31 | 32 | 1. Import the example. 33 | 34 | ``` 35 | mbed import mbed-os-example-wifi 36 | cd mbed-os-example-wifi 37 | ``` 38 | 39 | Or if you fetched the example with `git clone`, run `mbed deploy` inside the cloned repository. 40 | 41 | 1. Configure the Wi-Fi shield and settings. 42 | Edit ```mbed_app.json``` to include the correct Wi-Fi shield, SSID and password: 43 | 44 | ```json 45 | { 46 | "config": { 47 | "wifi-ssid": { 48 | "help": "WiFi SSID", 49 | "value": "\"SSID\"" 50 | }, 51 | "wifi-password": { 52 | "help": "WiFi Password", 53 | "value": "\"PASSWORD\"" 54 | } 55 | }, 56 | "target_overrides": { 57 | "*": { 58 | "platform.stdio-convert-newlines": true, 59 | "esp8266.provide-default" : false 60 | } 61 | } 62 | } 63 | ``` 64 | 65 | For build-in WiFi, you do not need to set any `provide-default` values. Those are required 66 | if you use external WiFi shield. 67 | 68 | A sample ```mbed_app.json``` file is provided for ESP8266 (```mbed_app_esp8266.json```). 69 | 70 | 71 | 1. Compile and generate binary. 72 | For example, for `GCC`: 73 | ``` 74 | mbed compile -t GCC_ARM -m DISCO_L475VG_IOT01A 75 | ``` 76 | 77 | 1. Open a serial console session with the target platform using the following parameters: 78 | * **Baud rate:** 9600 79 | * **Data bits:** 8 80 | * **Stop bits:** 1 81 | * **Parity:** None 82 | 83 | 1. Copy or drag the application `mbed-os-example-wifi.bin` in the folder `mbed-os-example-wifi/BUILD//` onto the target board. 84 | 85 | 1. The serial console should display a similar output to below, indicating a successful Wi-Fi connection: 86 | ``` 87 | WiFi example 88 | 89 | Scan: 90 | Network: Dave Hot Spot secured: Unknown BSSID: 00:01:02:03:04:05 RSSI: -58 Ch: 1 91 | 1 network available. 92 | 93 | Connecting... 94 | Success 95 | 96 | MAC: 00:01:02:03:04:05 97 | IP: 192.168.0.5 98 | Netmask: 255.255.255.0 99 | Gateway: 192.168.0.1 100 | RSSI: -27 101 | 102 | Done 103 | ``` 104 | 105 | ## Troubleshooting 106 | 107 | 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. 108 | 109 | ### License and contributions 110 | 111 | 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. 112 | 113 | This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide. 114 | -------------------------------------------------------------------------------- /drivers/COMPONENT_wifi_ism43362.lib: -------------------------------------------------------------------------------- 1 | https://github.com/ARMmbed/wifi-ism43362/#9e1851a7fe5e2ffb07533aacc7114df2e73f7784 2 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /* WiFi Example 2 | * Copyright (c) 2016 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mbed.h" 18 | 19 | WiFiInterface *wifi; 20 | 21 | const char *sec2str(nsapi_security_t sec) 22 | { 23 | switch (sec) { 24 | case NSAPI_SECURITY_NONE: 25 | return "None"; 26 | case NSAPI_SECURITY_WEP: 27 | return "WEP"; 28 | case NSAPI_SECURITY_WPA: 29 | return "WPA"; 30 | case NSAPI_SECURITY_WPA2: 31 | return "WPA2"; 32 | case NSAPI_SECURITY_WPA_WPA2: 33 | return "WPA/WPA2"; 34 | case NSAPI_SECURITY_UNKNOWN: 35 | default: 36 | return "Unknown"; 37 | } 38 | } 39 | 40 | int scan_demo(WiFiInterface *wifi) 41 | { 42 | WiFiAccessPoint *ap; 43 | 44 | printf("Scan:\n"); 45 | 46 | int count = wifi->scan(NULL,0); 47 | 48 | if (count <= 0) { 49 | printf("scan() failed with return value: %d\n", count); 50 | return 0; 51 | } 52 | 53 | /* Limit number of network arbitrary to 15 */ 54 | count = count < 15 ? count : 15; 55 | 56 | ap = new WiFiAccessPoint[count]; 57 | count = wifi->scan(ap, count); 58 | 59 | if (count <= 0) { 60 | printf("scan() failed with return value: %d\n", count); 61 | return 0; 62 | } 63 | 64 | for (int i = 0; i < count; i++) { 65 | printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(), 66 | sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2], 67 | ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel()); 68 | } 69 | printf("%d networks available.\n", count); 70 | 71 | delete[] ap; 72 | return count; 73 | } 74 | 75 | int main() 76 | { 77 | printf("WiFi example\n"); 78 | 79 | #ifdef MBED_MAJOR_VERSION 80 | printf("Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); 81 | #endif 82 | 83 | wifi = WiFiInterface::get_default_instance(); 84 | if (!wifi) { 85 | printf("ERROR: No WiFiInterface found.\n"); 86 | return -1; 87 | } 88 | 89 | int count = scan_demo(wifi); 90 | if (count == 0) { 91 | printf("No WIFI APs found - can't continue further.\n"); 92 | return -1; 93 | } 94 | 95 | printf("\nConnecting to %s...\n", MBED_CONF_APP_WIFI_SSID); 96 | int ret = wifi->connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2); 97 | if (ret != 0) { 98 | printf("\nConnection error: %d\n", ret); 99 | return -1; 100 | } 101 | 102 | printf("Success\n\n"); 103 | printf("MAC: %s\n", wifi->get_mac_address()); 104 | SocketAddress a; 105 | wifi->get_ip_address(&a); 106 | printf("IP: %s\n", a.get_ip_address()); 107 | wifi->get_netmask(&a); 108 | printf("Netmask: %s\n", a.get_ip_address()); 109 | wifi->get_gateway(&a); 110 | printf("Gateway: %s\n", a.get_ip_address()); 111 | printf("RSSI: %d\n\n", wifi->get_rssi()); 112 | 113 | wifi->disconnect(); 114 | 115 | printf("\nDone\n"); 116 | } 117 | -------------------------------------------------------------------------------- /mbed-os.lib: -------------------------------------------------------------------------------- 1 | https://github.com/ARMmbed/mbed-os/#d6784c3ee6ada8e886801d0197904d3ab94c891c 2 | -------------------------------------------------------------------------------- /mbed_app.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "wifi-ssid": { 4 | "help": "WiFi SSID", 5 | "value": "\"SSID\"" 6 | }, 7 | "wifi-password": { 8 | "help": "WiFi Password", 9 | "value": "\"PASSWORD\"" 10 | } 11 | }, 12 | "target_overrides": { 13 | "*": { 14 | "platform.stdio-convert-newlines": true 15 | }, 16 | "DISCO_L475VG_IOT01A": { 17 | "target.components_add": ["wifi_ism43362"], 18 | "ism43362.provide-default": true 19 | }, 20 | "DISCO_F413ZH": { 21 | "target.components_add": ["wifi_ism43362"], 22 | "ism43362.provide-default": true 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mbed_app_esp8266.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "wifi-ssid": { 4 | "help": "WiFi SSID", 5 | "value": "\"SSID\"" 6 | }, 7 | "wifi-password": { 8 | "help": "WiFi Password", 9 | "value": "\"PASSWORD\"" 10 | } 11 | }, 12 | "target_overrides": { 13 | "*": { 14 | "platform.stdio-convert-newlines": true, 15 | "esp8266.provide-default" : true 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /resources/official_armmbed_example_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ARMmbed/mbed-os-example-wifi/620d33b7ea9249c7c061ee9e654b34fec25d0b6b/resources/official_armmbed_example_badge.png -------------------------------------------------------------------------------- /resources/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ARMmbed/mbed-os-example-wifi/620d33b7ea9249c7c061ee9e654b34fec25d0b6b/resources/warning.png -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Testing examples 2 | 3 | Examples are tested using tool [htrun](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-host-tests) and templated print log. 4 | 5 | To run the test, use following command after you build the example: 6 | ```bash 7 | $ mbedhtrun -d -p -m -f ./BUILD///mbed-os-example-wifi.bin --compare-log tests/wifi.log 8 | ``` 9 | For example: 10 | ```bash 11 | $ mbedhtrun -d /media/user01/DAPLINK -p /dev/ttyACM0 -m K64F -f ./BUILD/K64F/GCC_ARM/mbed-os-example-wifi.bin --compare-log tests/wifi.log 12 | ``` 13 | 14 | 15 | More details about `htrun` are [here](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-host-tests#testing-mbed-os-examples). 16 | 17 | -------------------------------------------------------------------------------- /tests/wifi.log: -------------------------------------------------------------------------------- 1 | WiFi example 2 | Mbed OS version 3 | Scan: 4 | Network: 5 | \d+ networks available. 6 | Connecting to 7 | Success 8 | MAC: (?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2} 9 | IP: (?:[0-9]{1,3}\.){3}[0-9]{1,3} 10 | Netmask: (?:[0-9]{1,3}\.){3}[0-9]{1,3} 11 | Gateway: (?:[0-9]{1,3}\.){3}[0-9]{1,3} 12 | RSSI: -?\d+ 13 | Done 14 | -------------------------------------------------------------------------------- /tests/wifi_scan.log: -------------------------------------------------------------------------------- 1 | WiFi example 2 | Mbed OS version 3 | Scan: 4 | Network: 5 | \d+ networks available. 6 | Connecting to --------------------------------------------------------------------------------