A quick example of a simple WiFi application using the WiFi and network-socket APIs that is provided as a part of mbed-os.

The program brings up the WiFi and the underlying network interface, and uses it to scans available networks, connects to a network, prints interface and connection details and performs simple HTTP operation.

Supported hardware:

Not that the mbed target board the WiFi shield gets connected to shouldn't have any other network interface e.g. Ethernet.

ESP8266 is a fallback option and will be used if the build is for unsupported platform.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Fri Aug 31 12:15:03 2018 +0100
Parent:
76:f2a57e114ab5
Child:
78:c67fa97198d7
Commit message:
Remove external drivers

.
Commit copied from https://github.com/ARMmbed/mbed-os-example-wifi

Changed in this revision

Jenkinsfile Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
esp8266-driver.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
wifi-ism43362.lib Show diff for this revision Revisions of this file
wifi-x-nucleo-idw01m1.lib Show diff for this revision Revisions of this file
--- a/Jenkinsfile	Tue Aug 28 11:15:03 2018 +0100
+++ b/Jenkinsfile	Fri Aug 31 12:15:03 2018 +0100
@@ -13,11 +13,10 @@
 
 // List of targets with supported RF shields to compile
 def targets = [
-  "UBLOX_EVK_ODIN_W2": ["builtin"],
-  "REALTEK_RTL8195AM": ["builtin"],
-  "K64F": ["WIFI_ESP8266"],
-  "NUCLEO_F401RE": ["WIFI_IDW0XX1"],
-  "NUCLEO_F429ZI": ["WIFI_ESP8266"]
+  "UBLOX_EVK_ODIN_W2": ["internal"],
+  "REALTEK_RTL8195AM": ["internal"],
+  "K64F": ["esp8266-driver"],
+  "NUCLEO_F429ZI": ["esp8266-driver"]
   ]
 
 // Map toolchains to compilers
@@ -29,9 +28,8 @@
 
 // Supported RF shields
 def radioshields = [
-  "builtin",
-  "WIFI_IDW0XX1",
-  "WIFI_ESP8266"
+  "internal",
+  "esp8266-driver"
   ]
 
 def stepsForParallel = [:]
@@ -67,11 +65,6 @@
           checkout scm
           def config_file = "mbed_app.json"
 
-          if ("${radioShield}" != "internal") {
-            // Replace default rf shield
-            execute("sed -i 's/\"value\": \"internal\"/\"value\": \"${radioShield}\"/' ${config_file}")
-          }
-
           // Set mbed-os to revision received as parameter
           execute ("mbed deploy --protocol ssh")
           if (params.mbed_os_revision != '') {
@@ -85,6 +78,12 @@
             }
           }
           execute("mbed new .")
+
+          if ("${radioShield}" != "internal") {
+            // Replace default rf shield
+            execute("mbed add ${radioShield}")
+          }
+
           execute ("mbed compile --build out/${target}_${toolchain}_${radioShield}/ -m ${target} -t ${toolchain} -c --app-config ${config_file}")
         }
         stash name: "${target}_${toolchain}_${radioShield}", includes: '**/mbed-os-example-wifi.bin'
--- a/README.md	Tue Aug 28 11:15:03 2018 +0100
+++ b/README.md	Fri Aug 31 12:15:03 2018 +0100
@@ -27,6 +27,18 @@
     * [NUCLEO-L476RG](https://os.mbed.com/platforms/ST-Nucleo-L476RG/) with ESP8266-01 module using pins D8 and D2.
     * 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.
 
+#### Adding connectivity driver
+
+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.
+
+```
+mbed add <driver>
+```
+
+For example adding ISM43362 driver `mbed add wifi-ism43362` or ESP8266 `mbed add esp8266-driver`
+
+Then pin names need to be configured as instructed in the drivers README file.
+
 #### Connecting the ESP8266 ####
 
 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.
--- a/esp8266-driver.lib	Tue Aug 28 11:15:03 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://github.com/armmbed/esp8266-driver/#5a88ff9c75e34d65e359d7f239bacc456824ed0e
--- a/main.cpp	Tue Aug 28 11:15:03 2018 +0100
+++ b/main.cpp	Fri Aug 31 12:15:03 2018 +0100
@@ -17,43 +17,8 @@
 #include "mbed.h"
 #include "TCPSocket.h"
 
-#define internal        1
-#define WIFI_ESP8266    2
-#define WIFI_IDW0XX1    3
-#define WIFI_ISM43362   4
-
 WiFiInterface *wifi;
 
-#if MBED_CONF_APP_WIFI_SHIELD == WIFI_ESP8266
-
-#include "ESP8266Interface.h"
-
-WiFiInterface *WiFiInterface::get_default_instance() {
-    static ESP8266Interface esp(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX);
-    return &esp;
-}
-
-#elif MBED_CONF_APP_WIFI_SHIELD == WIFI_ISM43362
-
-#include "ISM43362Interface.h"
-
-WiFiInterface *WiFiInterface::get_default_instance() {
-    static ISM43362Interface ism;
-    return &ism;
-}
-
-#elif MBED_CONF_APP_WIFI_SHIELD == WIFI_IDW0XX1
-
-#include "SpwfSAInterface.h"
-
-WiFiInterface *WiFiInterface::get_default_instance() {
-    static SpwfSAInterface spwf(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX);
-    return &spwf;
-}
-
-#endif
-
-
 const char *sec2str(nsapi_security_t sec)
 {
     switch (sec) {
--- a/mbed_app.json	Tue Aug 28 11:15:03 2018 +0100
+++ b/mbed_app.json	Fri Aug 31 12:15:03 2018 +0100
@@ -1,9 +1,5 @@
 {
     "config": {
-        "wifi-shield": {
-            "help": "Options are internal, WIFI_ESP8266, WIFI_ISM43362, WIFI_IDW0XX1",
-            "value": "internal"
-        },
         "wifi-ssid": {
             "help": "WiFi SSID",
             "value": "\"SSID\""
@@ -11,33 +7,11 @@
         "wifi-password": {
             "help": "WiFi Password",
             "value": "\"PASSWORD\""
-        },
-        "wifi-tx": {
-            "help": "TX pin for serial connection to external device",
-            "value": "D1"
-        },
-        "wifi-rx": {
-            "help": "RX pin for serial connection to external device",
-            "value": "D0"
         }
     },
     "target_overrides": {
         "*": {
             "platform.stdio-convert-newlines": true
-        },
-        "DISCO_F413ZH": {
-            "wifi-shield": "WIFI_ISM43362"
-        },
-        "DISCO_L475VG_IOT01A": {
-            "wifi-shield": "WIFI_ISM43362"
-        },
-        "NUCLEO_L476RG": {
-            "wifi-tx": "D8",
-            "wifi-rx": "D2"
-        },
-        "NUCLEO_F401RE": {
-            "wifi-tx": "D8",
-            "wifi-rx": "D2"
         }
     }
 }
--- a/wifi-ism43362.lib	Tue Aug 28 11:15:03 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://github.com/armmbed/wifi-ism43362/#3154f96fd23522f6ef18fd248feb9214f94e32aa
--- a/wifi-x-nucleo-idw01m1.lib	Tue Aug 28 11:15:03 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://github.com/ARMmbed/wifi-x-nucleo-idw01m1/#b8348c58a9e6f80263f43219c56f90b81d8717cc