Just for testing

Dependencies:   mbed

Fork of ESP8266_MDM by Oxford CWM Team

Revision:
1:e2385bba1ab1
Parent:
0:7176e20dbdf6
--- a/main.cpp	Wed Jun 08 10:10:31 2016 +0000
+++ b/main.cpp	Wed Jun 08 11:05:52 2016 +0000
@@ -7,7 +7,7 @@
 
 #define FUNCNAME "MAIN"
 
-#ifdef DEBUG
+#ifdef NoDEBUG
 #define DBG(x, ...) pc.printf("    ["FUNCNAME" : DBG] "x" <line %d>\r\n", ##__VA_ARGS__,__LINE__);
 #else
 #define DBG(x, ...)
@@ -26,7 +26,7 @@
 #endif
 
 #ifdef INFOMESSAGES
-#define INFO(x, ...) pc->printf("["FUNCNAME" : INFO] "x"\r\n", ##__VA_ARGS__);
+#define INFO(x, ...) pc.printf("["FUNCNAME" : INFO] "x"\r\n", ##__VA_ARGS__);
 #else
 #define INFO(x, ...)
 #endif
@@ -40,6 +40,9 @@
 DigitalOut reset(p26,1);
 volatile int state=0;
 volatile int ready=0;
+
+char ipAddress[20];
+char macAddress[32];
 char *buffer;
 unsigned int bufferPnt=0;
 
@@ -54,12 +57,17 @@
     }
     while(dev.readable()) {
         c = (char)dev.getc();
-        pc.putc(c);
+#ifdef DEBUG
+  //      pc.putc(c);
+#endif
         buffer[bufferPnt]=c;
         bufferPnt++;
-        if (bufferPnt>1024){
+        if (bufferPnt>1024) {
             ready=1;
-            }
+        }
+        if ((c==0x0a)||(c==0x0d)){
+             ready=1;
+             }else
         if (c==0x0a) {
             if (bufferPnt>1) {
                 if (buffer[bufferPnt -2]==0x0d) {
@@ -68,8 +76,8 @@
                 }
             }
         }
-        if (!dev.readable()){
-          wait(0.001);
+        if (!dev.readable()) {
+            wait_us(100);
         }
     }
 }
@@ -115,12 +123,11 @@
         if (ready) {
             ready=0;
             bufferPnt=0;
-            pc.printf("%d]%s\n\r",state,buffer);
+            INFO("[%d]",state);
             switch (state) {
                 case 0: {
                     resp=OKResponse(buffer,"WIFI GOT IP");
                     if (resp!=NULL) {
-                        DBG(">>>>>>HERE");
                         wait(1);
                         dev.printf("AT\r\n");
                         state++;
@@ -131,7 +138,6 @@
                 case 2: {
                     resp=OKResponse(buffer,"OK");
                     if (resp!=NULL) {
-                        DBG(">>>>>>HERE 2");
                         dev.printf("AT\r\n");
                         state++;
                     }
@@ -140,7 +146,6 @@
                 case 3: {
                     resp=OKResponse(buffer,"OK");
                     if (resp!=NULL) {
-                        DBG(">>>>>>HERE 3");
                         dev.printf("AT+RST\r\n");
                         state++;
                     }
@@ -150,7 +155,6 @@
                 case 4: {
                     resp=OKResponse(buffer,"WIFI GOT IP");
                     if (resp!=NULL) {
-                        DBG(">>>>>>HERE 4");
                         dev.printf("AT+CWMODE=1\r\n");
                         state++;
                     }
@@ -160,7 +164,7 @@
                 case 5: {
                     resp=OKResponse(buffer,"OK");
                     if (resp!=NULL) {
-                        DBG(">>>>>>HERE 5");
+                        
                         dev.printf("AT+CWJAP=\"CWMWIFI\",\"CWM2016TT\"\r\n");
                         state++;
                     }
@@ -170,7 +174,6 @@
                 case 6: {
                     resp=OKResponse(buffer,"OK");
                     if (resp!=NULL) {
-                        DBG(">>>>>>HERE 5");
                         wait(1);
                         dev.printf("AT+CIFSR\r\n");
                         state++;
@@ -179,16 +182,29 @@
                     break;
                 }
                 case 7: {
-                    resp=OKResponse(buffer,"OK");
+                    resp=OKResponse(buffer,"+CIFSR:STAIP,");
                     if (resp!=NULL) {
-                        DBG(">>>>>>HERE 5");
-                        wait(1);
-                        dev.printf("AT+CIFSR\r\n");
+                        char *strt = strtok(buffer,"\"");
+                        strcpy(ipAddress,strtok(NULL,"\""));
+                        strtok(NULL,"\"");
+                         strcpy(macAddress,strtok(NULL,"\""));
+                        INFO("mac Address = %s", macAddress);
+                        INFO("IP Address = %s", ipAddress);
+                          dev.printf("AT+CIPMUX=1\r\n");
                         state++;
                     }
 
                     break;
                 }
+                case 8: {
+                    resp=OKResponse(buffer,"OK");
+                    if (resp!=NULL) {
+                       INFO("Ready");
+                       state++;
+                    }
+
+                     break;
+                }
 
 
             }