A quick example of a simple WiFi application using the WiFi and network-socket APIs that is provided as a part of mbed-os.
Revision 57:921d2524844d, committed 2018-03-10
- Comitter:
- CJW
- Date:
- Sat Mar 10 15:00:36 2018 +0000
- Parent:
- 56:bea82468efd3
- Commit message:
- Revert to using the LCD screen
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Mar 09 11:30:49 2018 +0000 +++ b/main.cpp Sat Mar 10 15:00:36 2018 +0000 @@ -40,7 +40,7 @@ #endif // MBED_CONF_APP_WIFI_SHIELD == WIFI_IDW0XX1 #endif -Serial pc(USBTX, USBRX); // tx, rx +//Serial pc(USBTX, USBRX); // tx, rx ...You can use pc.printf(message) for serial access! C12832 lcd(PE_14, PE_12, PD_12, PD_11, PE_9); @@ -48,7 +48,7 @@ { lcd.cls(); lcd.locate(0, 3); - pc.printf(message); + lcd.printf(message); } const char *sec2str(nsapi_security_t sec) @@ -74,7 +74,7 @@ { WiFiAccessPoint *ap; - pc.printf("Scan:\n"); + lcd.printf("Scan:\n"); int count = wifi->scan(NULL,0); @@ -84,11 +84,11 @@ ap = new WiFiAccessPoint[count]; count = wifi->scan(ap, count); 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(), + lcd.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()); } - pc.printf("%d networks available.\n", count); + lcd.printf("%d networks available.\n", count); delete[] ap; return count; @@ -144,22 +144,22 @@ { int count = 0; - pc.printf("WiFi example\n\n"); + lcd.printf("WiFi example\n\n"); count = scan_demo(&wifi); if (count == 0) { - pc.printf("No WIFI APNs found - can't continue further.\n"); + lcd.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) { - pc.printf("\nConnection error\n"); + lcd.printf("\nConnection error\n"); return -1; } - pc.printf("Success\n\n"); + lcd.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());