Very simple example using ESP-WROOM-02 (ESP-8266) from LPC1114

Dependencies:   SoftSerial mbed

Committer:
kazz12211
Date:
Fri May 13 12:05:34 2016 +0000
Revision:
0:e450010334e1
Use ESP-WROOM-02 (ESP-8266) from LPC1114 using SoftSerial.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kazz12211 0:e450010334e1 1 /**
kazz12211 0:e450010334e1 2 * Use ESP-8266 (called ESP-WROOM-02 in Japan) from LPC1114
kazz12211 0:e450010334e1 3 * LPC1114 has only 1 Hardware UART so this class uses SoftSerial to
kazz12211 0:e450010334e1 4 * communicate with ESP-8266.
kazz12211 0:e450010334e1 5 * I wrote like this class for Arduino then partially ported to mbed.
kazz12211 0:e450010334e1 6 *
kazz12211 0:e450010334e1 7 * 2016/05/13
kazz12211 0:e450010334e1 8 * By Kazuo Tsubaki
kazz12211 0:e450010334e1 9 **/
kazz12211 0:e450010334e1 10
kazz12211 0:e450010334e1 11 #ifndef __ESP8266__
kazz12211 0:e450010334e1 12 #define __ESP8266__
kazz12211 0:e450010334e1 13
kazz12211 0:e450010334e1 14 #include <mbed.h>
kazz12211 0:e450010334e1 15 #include "SoftSerial.h"
kazz12211 0:e450010334e1 16
kazz12211 0:e450010334e1 17 class ESP8266 {
kazz12211 0:e450010334e1 18 public:
kazz12211 0:e450010334e1 19
kazz12211 0:e450010334e1 20 // Constructor
kazz12211 0:e450010334e1 21 ESP8266(SoftSerial *s);
kazz12211 0:e450010334e1 22 ~ESP8266();
kazz12211 0:e450010334e1 23
kazz12211 0:e450010334e1 24 // Example for configuring ESP
kazz12211 0:e450010334e1 25 bool config();
kazz12211 0:e450010334e1 26 // Use Serial to logging
kazz12211 0:e450010334e1 27 void setLogger(Serial *log);
kazz12211 0:e450010334e1 28
kazz12211 0:e450010334e1 29 // Connect to WiFi AP
kazz12211 0:e450010334e1 30 bool connect(char *ssid, char *password);
kazz12211 0:e450010334e1 31 // Send command to ESP-8266 (see AT command list of the module)
kazz12211 0:e450010334e1 32 void sendRequest(char *req);
kazz12211 0:e450010334e1 33 // Read resultant response of AT command. Needs some waits to read after AT command.
kazz12211 0:e450010334e1 34 char *readResponse();
kazz12211 0:e450010334e1 35
kazz12211 0:e450010334e1 36 // AT
kazz12211 0:e450010334e1 37 bool nop();
kazz12211 0:e450010334e1 38 // AT+GMR
kazz12211 0:e450010334e1 39 void version();
kazz12211 0:e450010334e1 40 // AT+RST
kazz12211 0:e450010334e1 41 bool reset();
kazz12211 0:e450010334e1 42 // AT+CWMODE=n n= 1:Station Mode, 2:AP Mode, 3:Station Mode + AP Mode
kazz12211 0:e450010334e1 43 bool mode(int mode);
kazz12211 0:e450010334e1 44 // AT+CIPMUX=n n= 0:Single, 1=Multi
kazz12211 0:e450010334e1 45 bool connectionMode(int connMode);
kazz12211 0:e450010334e1 46 // AT+CIPSTA?
kazz12211 0:e450010334e1 47 void connectionStatus();
kazz12211 0:e450010334e1 48
kazz12211 0:e450010334e1 49 private:
kazz12211 0:e450010334e1 50
kazz12211 0:e450010334e1 51 void sendCmd();
kazz12211 0:e450010334e1 52 void getReply();
kazz12211 0:e450010334e1 53 bool _ok();
kazz12211 0:e450010334e1 54
kazz12211 0:e450010334e1 55 private:
kazz12211 0:e450010334e1 56
kazz12211 0:e450010334e1 57 char cmdbuffer[266];
kazz12211 0:e450010334e1 58 char replybuffer[1024];
kazz12211 0:e450010334e1 59 SoftSerial *stream;
kazz12211 0:e450010334e1 60 int replycount, timeout, getcount;
kazz12211 0:e450010334e1 61 Timer t;
kazz12211 0:e450010334e1 62 Serial *logger;
kazz12211 0:e450010334e1 63 };
kazz12211 0:e450010334e1 64
kazz12211 0:e450010334e1 65
kazz12211 0:e450010334e1 66 #endif