Wrapper library for ESP8266

Dependents:   ESP8266_LOCALPHANT_KL25Z_UPDATED ESP8266_LocalPhant_KL25Z LAB24_Coordinator DataLoggingUsingESP8266 ... more

Fork of ESP8266 by Antonio Quevedo

Files at this revision

API Documentation at this revision

Comitter:
janhavi
Date:
Sat Jun 11 14:05:06 2016 +0000
Parent:
2:77388e8f0697
Commit message:
Changes in ESP library

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
diff -r 77388e8f0697 -r 4f24e7e803a1 ESP8266.cpp
--- a/ESP8266.cpp	Sun Dec 28 21:58:49 2014 +0000
+++ b/ESP8266.cpp	Sat Jun 11 14:05:06 2016 +0000
@@ -1,4 +1,7 @@
 #include "ESP8266.h"
+#define HTTPCMD "GET "
+#define protocol " HTTP/1.0\n\n"
+
 
 // Constructor
 ESP8266::ESP8266(PinName tx, PinName rx, int br) : comm(tx, rx) {
@@ -62,7 +65,7 @@
 }
 
 // Receive reply until no character is received after a given timeout in miliseconds
-void ESP8266::RcvReply(char * r, int to) {
+bool ESP8266::RcvReply(char * r, int to) {
     Timer t;
     bool ended = 0;
     char c;
@@ -80,6 +83,7 @@
         }
     }
     AddChar(r, 0x00);
+    return ended;
 }
 
 // Gets the AP list. Parameter: the string to receive the list
@@ -165,4 +169,34 @@
     char rs[20];
     strcpy(rs, "AT+CIPSERVER=0");
     SendCMD(rs);
-}
\ No newline at end of file
+}
+
+void ESP8266::setTransparent(void){
+    char rs[20];
+    strcpy(rs, "AT+CIPMODE=0");
+    SendCMD(rs);
+}
+
+void ESP8266::startTCPConn(char *IP, int port){
+    char rs[100];
+    sprintf(rs, "AT+CIPSTART=\"TCP\",\"%s\",%d", IP, port);
+    SendCMD(rs);
+}
+
+void ESP8266::sendURL(char *URL, char *command){
+    char url[300], snd[300], http_cmd[300];
+    
+    strcpy(http_cmd, HTTPCMD);
+    
+    strcat(http_cmd, URL);
+    strcat(http_cmd, protocol);
+    
+    strcpy(url, http_cmd);
+    sprintf(snd,"AT+CIPSENDEX=%d",strlen(url));
+    strcpy(command, url);
+    SendCMD(snd);
+    wait(3);
+    SendCMD(url);
+}
+    
+    
\ No newline at end of file
diff -r 77388e8f0697 -r 4f24e7e803a1 ESP8266.h
--- a/ESP8266.h	Sun Dec 28 21:58:49 2014 +0000
+++ b/ESP8266.h	Sat Jun 11 14:05:06 2016 +0000
@@ -23,7 +23,7 @@
 
 void SendCMD(char * s);
 void Reset(void);
-void RcvReply(char * r, int to);
+bool RcvReply(char * r, int to);
 void GetList(char * l);
 void Join(char * id, char * pwd);
 void GetIP(char * ip);
@@ -34,6 +34,9 @@
 void GetConnStatus(char * st);
 void StartServerMode(int port);
 void CloseServerMode(void);
+void setTransparent(void);
+void startTCPConn(char * IP, int port);
+void sendURL(char *URL, char *command);
 
 private:
 Serial comm;