ESP8266

Dependencies:   mbed

Fork of Client-ESP8266 by Digital dog

Files at this revision

API Documentation at this revision

Comitter:
chanagan2540
Date:
Mon Dec 11 15:18:07 2017 +0000
Parent:
3:2df821b3eb35
Commit message:
esp8266

Changed in this revision

ESP8266.cpp Show annotated file Show diff for this revision Revisions of this file
ESP8266.h 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
--- a/ESP8266.cpp	Mon Dec 11 07:16:00 2017 +0000
+++ b/ESP8266.cpp	Mon Dec 11 15:18:07 2017 +0000
@@ -146,14 +146,28 @@
     strcat(cmd, o);
     AddChar(cmd, 0x22);
     AddChar(cmd, 0x2C);
-    AddChar(cmd, 0x22);
+//    AddChar(cmd, 0x22);
     strcat(cmd, v);
-    AddChar(cmd, 0x22);
+//    AddChar(cmd, 0x22);
     SendCMD(cmd);
 }
 
-void ESP8266::sent(void) {
+void ESP8266::SendData(char* str) {
+    int size = strlen(str);
+    char rs[50];
+    char num[5];
+    strcpy(rs,"AT+CIPSEND=");
+    itoa(size, num); //convert number of data size to charactor
+    strcat(rs,num); //concatinate number of data size
+    SendCMD(rs);
+    //check ">" เจอเครื่องหมายพร้อมรับข้อมูลไหม
+    SendCMD(str); //ส่งข้อมูลที่ต้องการ
+    //Check OK
+    SendCMD("AT+CIPCLOSE"); //เพื่อปิดการเชื่อมต่อ
+}
+
+void ESP8266::check(void) {
     char rs[10];
-    strcpy(rs, "AT+CIPSEND=5");
+    strcpy(rs, "AT+CIPSEND=?");
     SendCMD(rs);
 }
--- a/ESP8266.h	Mon Dec 11 07:16:00 2017 +0000
+++ b/ESP8266.h	Mon Dec 11 15:18:07 2017 +0000
@@ -21,7 +21,8 @@
   */
   ~ESP8266();
 
-void sent(void);
+void check(void);
+void SendData(char * str);
 void transfer(void);
 void look(void);
 void SetPath(char * t, char* o, char * v);
--- a/main.cpp	Mon Dec 11 07:16:00 2017 +0000
+++ b/main.cpp	Mon Dec 11 15:18:07 2017 +0000
@@ -2,8 +2,8 @@
 #include <string>
 #include "ESP8266.h"
 
-ESP8266 esp(D8, D2, 9600);
-Serial pc(D1, D0);
+ESP8266 esp(D8, D2, 115200);
+Serial pc(D1, D0, 115200);
 
 char snd[255], rcv[1000];
 
@@ -62,21 +62,26 @@
     wait(4);
     
     pc.printf("Connect to Server\r\n");
-    esp.SetPath("UDP", "172.20.10.2", "80");
+    esp.SetPath("TCP", "172.20.10.2", "80");
     esp.RcvReply(rcv, 5000);
     pc.printf("%s", rcv);
     wait(4);
     
-    pc.printf("Sent\r\n");
-    esp.sent();
-    esp.RcvReply(rcv, 1000);
-    pc.printf("%s", rcv);
-    wait(4);
+    //pc.printf("Sent Data\r\n");
+//    esp.SendData("hello");
+//    esp.RcvReply(rcv, 1000);
+//    pc.printf("%s", rcv);
+//    wait(4);
+    
+    while(1) {
+        esp.RcvReply(rcv, 5000);
+        pc.printf("%s", rcv);
+        wait(2);
         
-    //while(1) {
-//        esp.SetPath("TCP", "192.168.1.53", "80");
-//        esp.RcvReply(rcv, 5000);
-//        pc.printf("%s", rcv);
-//        wait(2);
-//    }
+        pc.printf("Check Data\r\n");
+        esp.check();
+        esp.RcvReply(rcv, 400);
+        pc.printf("%s", rcv);
+        wait(2);
+    }
 }
\ No newline at end of file