AT Parser and bufferedSerial based SPWF library

Dependencies:   ATParser

Dependents:   X_NUCLEO_IDW01M1v2

Fork of SPWF01SA by ST Expansion SW Team

Revision:
3:2af9df1068a5
Parent:
2:40d183d7dc19
Child:
4:042d5b9bb6e7
--- a/SPWFSA01.cpp	Thu Jun 30 06:59:25 2016 +0000
+++ b/SPWFSA01.cpp	Thu Jun 30 08:25:26 2016 +0000
@@ -232,15 +232,25 @@
     return getIPAddress() != 0;
 }
 
-bool SPWFSA01::open(const char *type, int id, const char* addr, int port)
+bool SPWFSA01::open(const char *type, int* id, const char* addr, int port)
 {
-    //IDs only 0-7
-    if(id > 7) {
-        return false;
-    }
+    
+    if(!_parser.send("AT+S.SOCKON=%s,%d,%s,ind", addr, port, type))
+        {
+            printf("\r\nerror opening socket\n");
+            return false;
+        }
+        
+    while(1)
+        {
+            if( _parser.recv(" ID: %d", id)
+                && _parser.recv("OK"))
+                break;
+            //TODO:implement time-out functionality in case of no response
+        }
+    printf("\r\nsock id = %d\r\n", *id);
 
-    return _parser.send("AT+CIPSTART=%d,\"%s\",\"%s\",%d", id, type, addr, port)
-        && _parser.recv("OK");
+    return true;
 }
 
 bool SPWFSA01::send(int id, const void *data, uint32_t amount)