CLI example for NNN50

Dependencies:   NNN50_WIFI_API

Fork of NNN50_WiFi_HelloWorld by Delta

Files at this revision

API Documentation at this revision

Comitter:
tsungta
Date:
Mon Apr 17 14:19:36 2017 +0000
Parent:
3:9bd3e863e15b
Child:
5:ffe1a4c4881e
Commit message:
This revision is based on mbed-os (mbedOS 5); NNN50_WIFI_API need to update to 22:5b38592 at least ; Add mbed_app.json for proper platform setting; Add .mbedignore (may not shown in IDE)

Changed in this revision

.mbedignore Show annotated file Show diff for this revision Revisions of this file
NNN50_WIFI_API.lib Show annotated file 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.bld Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.mbedignore	Mon Apr 17 14:19:36 2017 +0000
@@ -0,0 +1,1 @@
+mbed-os/features/netsocket/
--- a/NNN50_WIFI_API.lib	Sun Apr 02 10:16:20 2017 +0000
+++ b/NNN50_WIFI_API.lib	Mon Apr 17 14:19:36 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/Delta/code/NNN50_WIFI_API/#eb59b255b9e3
+https://developer.mbed.org/teams/Delta/code/NNN50_WIFI_API/#5b38592bc0e6
--- a/main.cpp	Sun Apr 02 10:16:20 2017 +0000
+++ b/main.cpp	Mon Apr 17 14:19:36 2017 +0000
@@ -15,24 +15,20 @@
 #include "EthernetInterface.h"
 #include "WIFIDevice.h"
 
-const char* ECHO_SERVER_ADDRESS = "192.168.1.100";
+const char* ECHO_SERVER_ADDRESS = "192.168.2.13";
 const int ECHO_SERVER_PORT = 1030;
 
-Serial uart(p17, p16);//temporary define for alpha release
-
 void scanCallback(tstrM2mWifiscanResult result)
 {
-    uart.printf("SSID: %s \n", result.au8SSID);
-    uart.printf("RSSI: %i \n", result.s8rssi);
+    printf("SSID: %s \n", result.au8SSID);
+    printf("RSSI: %i \n", result.s8rssi);
 }
 
 int main() {
 
     EthernetInterface eth;
     WIFIDevice wifi;
-    
-    uart.baud(9600);
-        
+
     eth.init();
 
     wifi.apScan(scanCallback);
@@ -42,14 +38,14 @@
     eth.connect();    
 
     if(wifi.is_AP_connected())
-        uart.printf("Connect Success! \n");
+        printf("Connect Success! \n");
     else
-        uart.printf("Connect Fail! \n");    
+        printf("Connect Fail! \n");    
 
-    uart.printf("MAC: %s\n", eth.getMACAddress());            
-    uart.printf("IP: %s\n", eth.getIPAddress());
-    uart.printf("Gateway: %s\n", eth.getGateway());
-    uart.printf("NetworkMask: %s\n", eth.getNetworkMask()); 
+    printf("MAC: %s\n", eth.getMACAddress());            
+    printf("IP: %s\n", eth.getIPAddress());
+    printf("Gateway: %s\n", eth.getGateway());
+    printf("NetworkMask: %s\n", eth.getNetworkMask()); 
 
     UDPSocket sock;
     sock.init();
@@ -58,14 +54,18 @@
     echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
     
     char out_buffer[] = "Hello World";
-    uart.printf("Sending  message '%s' to server (%s)\n",out_buffer,ECHO_SERVER_ADDRESS);
+    printf("Sending  message '%s' to server (%s)\n",out_buffer,ECHO_SERVER_ADDRESS);
     sock.sendTo(echo_server, out_buffer, sizeof(out_buffer));
     
-    char in_buffer[256];
+    char in_buffer[256];    //IMPORTANT, array size MUST >= the actual received data size or set to maximum of 1400 if there is uncertainty
     int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer));
     
-    in_buffer[n] = '\0';
-    uart.printf("Received message from server: '%s'\n", in_buffer);
+    if(n <0)
+        in_buffer[0] = '\0';//IMPORTANT, in case n = -1 when set_bloacking is timeout, prevent the illegal array in_buffer[-1] access 
+    else
+        in_buffer[n] = '\0';
+        
+    printf("Received message from server: '%s'\n", in_buffer);
     
     sock.close();
     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Apr 17 14:19:36 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#50b3418e45484ebf442b88cd935a2d5355402d7d
--- a/mbed.bld	Sun Apr 02 10:16:20 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Mon Apr 17 14:19:36 2017 +0000
@@ -0,0 +1,17 @@
+{
+    "config": {
+        "lf_clock_rc_calib_timer_interval": {
+            "value": 16,
+            "macro_name": "MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_TIMER_INTERVAL"
+        },
+        "lf_clock_rc_calib_mode_config": {
+            "value": 0,
+            "macro_name": "MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_MODE_CONFIG"
+        },
+        "uart_hwfc": {
+            "help": "Value: 1 for enable, 0 for disable",
+            "value": 0,
+            "macro_name": "MBED_CONF_NORDIC_UART_HWFC"
+        }        
+    }
+}
\ No newline at end of file