wifi-demo0730

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
faker_71
Date:
Thu Jul 30 06:38:50 2020 +0000
Parent:
5:dfea6fd1abba
Commit message:
2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r dfea6fd1abba -r 7c9cc335b762 main.cpp
--- a/main.cpp	Tue Jul 21 06:42:34 2020 +0000
+++ b/main.cpp	Thu Jul 30 06:38:50 2020 +0000
@@ -5,6 +5,7 @@
 
 Serial pc(USBTX, USBRX);
 Serial esp(p28, p27); // tx, rx
+//Serial esp(p9, p10); // tx, rx
 
 //DS18B20 thermom(A0, DS18B20::RES_12_BIT);
 
@@ -52,14 +53,14 @@
 char cmdbuff[32];
 char replybuff[1024];
 
-//char webdata[1024]; // This may need to be bigger depending on WEB browser used
-//char webbuff[4096];     // Currently using 1986 characters, Increase this if more web page data added
+char webdata[1024]; // This may need to be bigger depending on WEB browser used
+char webbuff[4096];     // Currently using 1986 characters, Increase this if more web page data added
 
-char webdata[4096]; // This may need to be bigger depending on WEB browser used
-char webbuff[4096*4];     // Currently using 1986 characters, Increase this if more web page data added
+//char webdata[4096]; // This may need to be bigger depending on WEB browser used
+//char webbuff[4096*4];     // Currently using 1986 characters, Increase this if more web page data added
 
 
-void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),SendWEB(),sendcheck();
+void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),SendWEB(),sendcheck(),touchuan();
 void gettime(),gettemp(),getbattery(),setRTC(),beep();
 
 // manual set RTC values
@@ -155,12 +156,13 @@
 strcat(webbuff, "</button></td></tr><td></td><td>");
 strcat(webbuff, "<button id='backbtn' type='button' style='width:100px;height:60px' value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK");
 strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>");
+
 /*
+
+//begin
 strcat(webbuff, "<strong>Addition functions:</strong><table>");
 strcat(webbuff, "<td>");//ok
-
 strcat(webbuff, "<button id='avoidbtn' type='button' style='width:100px;height:60px' value=\"AVOIDANCE\"  onClick='send_mes_fun(this.id,this.value)' >");
-
 strcat(webbuff, "AVOIDANCE</button></td><td>");
 strcat(webbuff, "<button id='tracebtn' type='button' style='width:100px;height:60px' value=\"LINE TRACE\"  onClick='send_mes_fun(this.id,this.value)' >LINE TRACE");
 strcat(webbuff, "</button></td><td>");
@@ -180,12 +182,13 @@
 strcat(webbuff, "<table>");        
 strcat(webbuff, "<td>");
 strcat(webbuff, "</td>");    
-strcat(webbuff, "</table>");    */
+strcat(webbuff, "</table>");    //end
+
+*/
+
 strcat(webbuff, "</center>");
-
 strcat(webbuff, "</body>");
 strcat(webbuff, "</html>");
-
 strcat(webbuff, "<script language=\"javascript\" type=\"text/javascript\">");
 strcat(webbuff, "function send_mes(btnmes,btnval){");
 strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;");
@@ -209,21 +212,103 @@
 strcat(webbuff, "document.getElementById(\"funprint\").innerHTML=btnval;");
 strcat(webbuff, "}");
 strcat(webbuff, "}");
-strcat(webbuff, "</script>");
+strcat(webbuff, "</script>+++");
 // end of WEB page data
     bufl = strlen(webbuff); // get total page buffer length
-    sprintf(cmdbuff,"AT+CIPSEND=%d,%d\r\n", linkID, bufl); // send IPD link channel and buffer character length.
-    timeout=200;
-    getcount=7;
+    //sprintf(cmdbuff,"AT+CIPSEND=%d,%d\r\n", linkID, bufl); // send IPD link channel and buffer character length.
+    
+    sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, 1500); // send IPD link channel and buffer character length.
+    timeout=500;
+    getcount=40;
     SendCMD();
     getreply();
+    pc.printf(replybuff);
+    pc.printf("\n++++++++++ AT+CIPSENDBUF=%d,%d+++++++++\r\n", linkID, 1500);
+    
     pc.printf("\n++++++++++ bufl is %d ++++++++++\r\n",bufl);
+    
+    //pastthrough mode
     SendWEB();  // send web page
+   
     memset(webbuff, '\0', sizeof(webbuff));
     sendcheck();
 }
 
+// Large WEB buffer data send
+void SendWEB()
+{
+    int i=0;
+    if(esp.writeable()) {
+        while(webbuff[i]!='\0') {
+            esp.putc(webbuff[i]);
+                 
+          //****  
+          //output at command when 2000 
+            if(i==1499){    
+                    wait_ms(10);
+                    sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, 1500); // send IPD link channel and buffer character length.
+                    pc.printf("\r\n++++++++++ AT+CIPSENDBUF=%d,%d ++++++++++\r\n", linkID, 1500);
+                    timeout=600;
+                    getcount=50;
+                    SendCMD();
+                    getreply();
+                    pc.printf(replybuff);
+                    pc.printf("\r\n+++++++++++++++++++\r\n");
+                    
+               }    
+               
+    //****  
+            i++;     
+            pc.printf("%c",webbuff[i]);
+        }
+    }
+    
+    
+    //****
+    /*
+    sprintf(cmdbuff,"AT+CIPCLOSE\r\n"); // send IPD link channel and buffer character length.        
+    SendCMD();
+    */
+    //*****
+    
+     pc.printf("\n++++++++++ send web i= %dinfo ++++++++++\r\n",i);
+}
+
+
 //  wait for ESP "SEND OK" reply, then close IP to load web page
+
+//touchuan mode
+void touchuan(){
+    strcpy(cmdbuff, "AT+CIPMUX=0\r\n");
+    pc.printf("\n++++++++++ AT+CIPMUX=0\r\n+++++++++");
+    timeout=500;
+    getcount=40;
+    SendCMD();
+    getreply();
+    pc.printf(replybuff);
+    strcpy(cmdbuff, "AT+CIPSTART=\"TCP\",\"192.168.4.2\",8080\r\n"); // send IPD link channel and buffer character length.
+    pc.printf("\n++++++++++ AT+CIPSTART=0\r\n+++++++++");
+    timeout=500;
+    getcount=40;
+    SendCMD();
+    getreply();
+    pc.printf(replybuff);
+    strcpy(cmdbuff, "AT+CIPMODE=1\r\n"); // send IPD link channel and buffer character length.
+    pc.printf("\n++++++++++ AT+CIPMODE=1\r\n+++++++++");
+    timeout=500;
+    getcount=40;
+    SendCMD();
+    getreply();
+    pc.printf(replybuff);
+    strcpy(cmdbuff, "AT+CIPSEND\r\n"); // send IPD link channel and buffer character length.
+    pc.printf("\n++++++++++ AT+CIPSEND\r\n+++++++++");
+    timeout=500;
+    getcount=40;
+    SendCMD();
+    getreply();
+    pc.printf(replybuff);
+}
+    
 void sendcheck()
 {
     weberror=1;
@@ -273,20 +358,22 @@
         strcpy(webdata, webbuff + x);
         weberror=0;
         int numMatched = sscanf(webdata,"+IPD,%d,%d:%s", &linkID, &ipdLen, type);
-        int i=0;
+        //int i=0;
         pc.printf("+++++++++++++++++succed+++++++++++++++++++++");
         pc.printf("%s",webdata);
         
      
         
         if( strstr(webdata, "LEFT") != NULL ) {
-            ledR=!ledR;
-           
+            //ledR=!ledR;
+             led1=!led1;
+             pc.printf("+++++++++++++++++ledR+++++++++++++++++++++\r\n");
+       
         }
         
         if( strstr(webdata, "RIGHT") != NULL ) {
             ledG=!ledG;
-           
+           pc.printf("+++++++++++++++++ledG+++++++++++++++++++++\r\n");
         }
         pc.printf("+++++++++++++++++succed+++++++++++++++++++++");
         
@@ -405,19 +492,6 @@
 {
     esp.printf("%s", cmdbuff);
 }
-// Large WEB buffer data send
-void SendWEB()
-{
-    int i=0;
-    if(esp.writeable()) {
-        while(webbuff[i]!='\0') {
-            esp.putc(webbuff[i]);
-            i++;
-            pc.printf("%s",webbuff[i]);
-        }
-    }
-     pc.printf("\n++++++++++ send web info ++++++++++\r\n");
-}
 // Get Command and ESP status replies
 void getreply()
 {