this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Revision:
82:10072c1794d3
Parent:
81:637a87eb8170
Child:
83:9c271a50a70b
--- a/source/ATCmdManager.cpp	Sat Mar 23 16:28:34 2019 +0000
+++ b/source/ATCmdManager.cpp	Sun Mar 24 17:32:06 2019 +0000
@@ -51,12 +51,17 @@
     _parser.oob("AT+UBTLE=2", callback(this, &ATCmdManager::_oob_ena_ble_peri));
     _parser.oob("AT+CPWROFF", callback(this, &ATCmdManager::_oob_reboot));
     _parser.oob("AT+CGMR", callback(this, &ATCmdManager::_oob_get_fw_ver));
-    _parser.oob("AT+UWSC=", callback(this, &ATCmdManager::_oob_scanWiFiNetworks));
+    _parser.oob("AT+UWSCAN", callback(this, &ATCmdManager::_oob_scanWiFiNetworks));
     _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_connect2WiFiNetwork));
     _parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork));
     _parser.oob("AT+UDDRP", callback(this, &ATCmdManager::_oob_setupInternetConnection));
+    _parser.oob("AT+UWSC=0,2", callback(this, &ATCmdManager::_oob_setWiFiSSID));
+    _parser.oob("AT+UWSC=0,8", callback(this, &ATCmdManager::_oob_setWiFiPWD));
+    _parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_setWiFiSecurity));
  
-
+//AT+UWSC=0,2,<SSID>
+//AT+UWSC=0,8,<PWD>
+//AT+UWSC=0,5,2 (WPA)
     //_parser.oob("ATE0", callback(this, &ATCmdManager::_oob_startup_hdlr));
     printf("\n --- ATCmdManager constructor completed ---\n");
     at_resp = AT_RESP_NONE;
@@ -113,10 +118,10 @@
                 _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
-            case AT_HTTPS_RESP:  
-                // AT_HTTPS_RESP response state 
+            case AT_CONFIG_RESP:  
+                // AT_CONFIG_RESP response state 
                 _smutex.lock();
-                printf("\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\n");
+                printf("\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\n");
                 _parser.send("OK\n");
                 _smutex.unlock();
                 at_resp = AT_RESP_NONE;
@@ -131,6 +136,10 @@
                 break;
             default:
                 // UNKNOWN response state
+                _smutex.lock();
+                printf("\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\n");
+                _parser.send("OK\n");
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
         }
@@ -364,7 +373,7 @@
     int n;
     internet_config_t internet_config;
     _smutex.lock();
-    n = _parser.scanf("=%1d,%200[^,],%1d", &internet_config.peer_id, 
+    n = _parser.scanf("=%1d,%199[^,],%1d", &internet_config.peer_id, 
                                       url,
                                      &internet_config.connectionScheme);
     if(n>0) 
@@ -378,14 +387,109 @@
         data_msg.wifi_cmd = WIFI_CMD_INTERNET_CONFIG;
         data_msg.dataLen = sizeof(internet_config) + internet_config.url.length();
         memcpy(data_msg.buffer,&internet_config, data_msg.dataLen);
+        // queue next data request
         queueWiFiDataRequest(data_msg);
+        _parser.send("OK\n");
     } else {
         printf("\n[ATCMD MAN]: internet configuration failed %d fields parsed \n", n);
-        printf("\npeer_id = %d, url = %s, connScheme = %d\n", internet_config.peer_id, 
-                                                          url, 
-                                                          internet_config.connectionScheme);
+        _parser.send("NAK\n");
+    }
+    _smutex.unlock();
+}
+
+wifi_config_t ATCmdManager::init_wifi_config()
+{ 
+    wifi_config_t wifi_cfg;
+    wifi_cfg.ssid[0]  = NULL;
+    wifi_cfg.pass[0]  = NULL;
+    wifi_cfg.security = NSAPI_SECURITY_UNKNOWN;
+    return wifi_cfg;    
+}
+
+int ATCmdManager::readBytes(uint8_t *buf, int maxBytes)
+{ 
+    int c;
+    int sptr = 0;
+    for(int i=0;i<maxBytes;i++){
+        c = _parser.getc();
+        if(c==-1){
+            buf[sptr] = '\0'; // null terminate if string
+            return i;
+        }
+        if(c != ',' && c!= '"'){
+            buf[sptr++] = (uint8_t) c;
+        }
     }
-    _parser.send("OK\n");
+}
+
+void ATCmdManager::_oob_setWiFiSSID()
+{
+    int n;
+    wifi_config_t wifi_cfg = init_wifi_config();
+    _smutex.lock();
+    n = readBytes((uint8_t *)wifi_cfg.ssid, 32);
+    printf("[ATCMD MAN]: number of bytes read = %d\n", n);
+    if(n>0) 
+    {
+        printf("[ATCMD MAN]: wifi_cfg.ssid = %s\n", wifi_cfg.ssid);
+        // package and send on wifi data queue
+        wifi_data_msg_t data_msg;
+        data_msg.wifi_cmd = WIFI_CMD_CONFIG;
+        data_msg.dataLen = sizeof(wifi_config_t);
+        memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
+        queueWiFiDataRequest(data_msg);
+        _parser.send("OK\n");
+    } else {
+        printf("\n[ATCMD MAN]: wifi configuration failed  \n");
+        _parser.send("NAK\n");
+    }
+    _smutex.unlock();
+}
+
+void ATCmdManager::_oob_setWiFiPWD()
+{
+    int n;
+    wifi_config_t wifi_cfg = init_wifi_config();
+    _smutex.lock();
+    //n = _parser.scanf("%31[^\r\n]", wifi_cfg.pass);
+    n = readBytes((uint8_t *)wifi_cfg.pass, 32);
+    if(n>0) 
+    {
+        printf("ATCMD MAN]: wifi_cfg.pass = %s\n", wifi_cfg.pass);
+        // package and send on wifi data queue
+        wifi_data_msg_t data_msg;
+        data_msg.wifi_cmd = WIFI_CMD_CONFIG;
+        data_msg.dataLen = sizeof(wifi_config_t);
+        memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
+        queueWiFiDataRequest(data_msg);
+        _parser.send("OK\n");
+    } else {
+        printf("\n[ATCMD MAN]: wifi configuration failed  \n");
+        _parser.send("NAK\n");
+    }
+    _smutex.unlock();
+}
+
+void ATCmdManager::_oob_setWiFiSecurity()
+{
+    int n;
+    wifi_config_t wifi_cfg = init_wifi_config();
+    _smutex.lock();
+    n = _parser.scanf(",%d", &wifi_cfg.security);
+    if(n>0) 
+    {
+        printf("ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security));
+        // package and send on wifi data queue
+        wifi_data_msg_t data_msg;
+        data_msg.wifi_cmd = WIFI_CMD_CONFIG;
+        data_msg.dataLen = sizeof(wifi_config_t);
+        memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
+        queueWiFiDataRequest(data_msg);
+        _parser.send("OK\n");
+    } else {
+        printf("\n[ATCMD MAN]: wifi configuration failed  \n");
+        _parser.send("NAK\n");
+    }
     _smutex.unlock();
 }