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

Dependencies:   C12832

Fork of mbed-os-example-mbed5-wifi by mbed-os-examples

Files at this revision

API Documentation at this revision

Comitter:
CJW
Date:
Fri Mar 09 11:30:49 2018 +0000
Parent:
55:31af282f6ea5
Commit message:
WiFi Example

Changed in this revision

C12832.lib 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-os.lib 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-x-nucleo-idw01m1.lib Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Fri Mar 09 11:30:49 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/askksa12543/code/C12832/#990d5eec2ef6
--- a/esp8266-driver.lib	Fri Feb 16 10:15:02 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://github.com/armmbed/esp8266-driver/#264468722a97cc2c8e0a517da06a542eb52fb9cb
--- a/main.cpp	Fri Feb 16 10:15:02 2018 +0000
+++ b/main.cpp	Fri Mar 09 11:30:49 2018 +0000
@@ -16,11 +16,12 @@
 
 #include "mbed.h"
 #include "TCPSocket.h"
+#include "C12832.h"
 
 #define WIFI_ESP8266    1
 #define WIFI_IDW0XX1    2
 
-#if TARGET_UBLOX_EVK_ODIN_W2
+#if 1
 #include "OdinWiFiInterface.h"
 OdinWiFiInterface wifi;
 
@@ -39,6 +40,16 @@
 #endif // MBED_CONF_APP_WIFI_SHIELD == WIFI_IDW0XX1
 
 #endif
+Serial pc(USBTX, USBRX); // tx, rx
+
+C12832  lcd(PE_14, PE_12, PD_12, PD_11, PE_9);
+
+void lcd_print(const char* message)
+{
+    lcd.cls();
+    lcd.locate(0, 3);
+    pc.printf(message);
+}
 
 const char *sec2str(nsapi_security_t sec)
 {
@@ -63,7 +74,7 @@
 {
     WiFiAccessPoint *ap;
 
-    printf("Scan:\n");
+    pc.printf("Scan:\n");
 
     int count = wifi->scan(NULL,0);
 
@@ -72,13 +83,12 @@
 
     ap = new WiFiAccessPoint[count];
     count = wifi->scan(ap, count);
-    for (int i = 0; i < count; i++)
-    {
-        printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(),
-               sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
-               ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
+    for (int i = 0; i < count; i++) {
+        pc.printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(),
+                   sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
+                   ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
     }
-    printf("%d networks available.\n", count);
+    pc.printf("%d networks available.\n", count);
 
     delete[] ap;
     return count;
@@ -104,8 +114,7 @@
     char sbuffer[] = "GET / HTTP/1.1\r\nHost: www.arm.com\r\n\r\n";
     nsapi_size_t size = strlen(sbuffer);
     response = 0;
-    while(size)
-    {
+    while(size) {
         response = socket.send(sbuffer+response, size);
         if (response < 0) {
             printf("Error sending data: %d\n", response);
@@ -135,22 +144,22 @@
 {
     int count = 0;
 
-    printf("WiFi example\n\n");
+    pc.printf("WiFi example\n\n");
 
     count = scan_demo(&wifi);
     if (count == 0) {
-        printf("No WIFI APNs found - can't continue further.\n");
+        pc.printf("No WIFI APNs found - can't continue further.\n");
         return -1;
     }
 
     printf("\nConnecting to %s...\n", MBED_CONF_APP_WIFI_SSID);
     int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
     if (ret != 0) {
-        printf("\nConnection error\n");
+        pc.printf("\nConnection error\n");
         return -1;
     }
 
-    printf("Success\n\n");
+    pc.printf("Success\n\n");
     printf("MAC: %s\n", wifi.get_mac_address());
     printf("IP: %s\n", wifi.get_ip_address());
     printf("Netmask: %s\n", wifi.get_netmask());
--- a/mbed-os.lib	Fri Feb 16 10:15:02 2018 +0000
+++ b/mbed-os.lib	Fri Mar 09 11:30:49 2018 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#569159b784f70feaa32ce226aaca896fb83452f7
+https://github.com/ARMmbed/mbed-os/#8b54959f5bca08a8ad44a701bafd634afbb38b03
--- a/mbed_app.json	Fri Feb 16 10:15:02 2018 +0000
+++ b/mbed_app.json	Fri Mar 09 11:30:49 2018 +0000
@@ -6,11 +6,11 @@
 	},
         "wifi-ssid": {
             "help": "WiFi SSID",
-            "value": "\"SSID\""
+            "value": "\"SnackBeans\""
         },
         "wifi-password": {
             "help": "WiFi Password",
-            "value": "\"PASSWORD\""
+            "value": "\"crocodile\""
         },
         "wifi-tx": {
             "help": "TX pin for serial connection to external device",
--- a/wifi-x-nucleo-idw01m1.lib	Fri Feb 16 10:15:02 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://github.com/ARMmbed/wifi-x-nucleo-idw01m1/#5871f7011d7ff2c50e3faf992ebab88e9f69dc95
\ No newline at end of file