stm32l432 esp8266,MQ13,MQ7,SSD1306,SD1303,HC04

Dependents:   Nucleo_SSD1306_DS1302_ESP8266_AM2320_BME280

Fork of ESP8266 by Antonio Quevedo

Revision:
2:77388e8f0697
Parent:
1:399414d48048
Child:
3:a1da4dcd891a
--- a/ESP8266.cpp	Wed Dec 17 13:54:34 2014 +0000
+++ b/ESP8266.cpp	Sun Dec 28 21:58:49 2014 +0000
@@ -1,8 +1,8 @@
 #include "ESP8266.h"
 
 // Constructor
-ESP8266::ESP8266(PinName tx, PinName rx) : comm(tx, rx) {
-    comm.baud(115200);
+ESP8266::ESP8266(PinName tx, PinName rx, int br) : comm(tx, rx) {
+    comm.baud(br);
 }
 
 // Destructor
@@ -25,6 +25,29 @@
     s[k + 1] = 0;
 }
 
+// Converts integer number to null-terminated string
+void ESP8266::itoa(int n, char * s) {
+    char k = 0;
+    char r[11];
+    
+    if(n == 0) {
+        s[0] = '0';
+        s[1] = 0;
+    } else {
+        while(n != 0) {
+            r[k]= (n % 10) + '0';
+            n = n / 10;
+            k++;
+        }
+        while(k > 0) {
+            s[n] = r[k - 1] + '0';
+            n++;
+            k--;
+        }
+        s[n] = 0;
+    }
+}
+
 // Sends command to ESP8266. Receives the command string
 void ESP8266::SendCMD(char * s) {
     AddEOL(s);
@@ -117,4 +140,29 @@
     char rs[15];
     strcpy(rs, "AT+CIPMUX=1");
     SendCMD(rs);
+}
+
+// Gets connection status. Parameter: string to contain status
+void ESP8266::GetConnStatus(char * st) {
+    char cmd[15];
+    strcpy(cmd, "AT+CIPSTATUS");
+    SendCMD(cmd);
+    RcvReply(st, 2000);
+}
+
+// Starts server mode. Parameter: port to be used
+void ESP8266::StartServerMode(int port) {
+    char rs[25];
+    char t[4];
+    strcpy(rs, "AT+CIPSERVER=1,");
+    itoa(port, t);
+    strcat(rs, t);
+    SendCMD(rs);
+}
+
+// Close server mode.
+void ESP8266::CloseServerMode(void) {
+    char rs[20];
+    strcpy(rs, "AT+CIPSERVER=0");
+    SendCMD(rs);
 }
\ No newline at end of file