Library for using the Wifi module ESP8266, first version with basic commands, soon new commands will be added

Dependents:   PIR_Sensor_wifi myESP8266forLOstFound Motin_Activated_Temperature_Humidity_BluetoothHC-06_ESP8266_IOT 1Project3_Robot1_Final ... more

Library updated in Dec 28, 2014. Now the ESP baudrate is passed as a parameter in the constructor. Also, some new functions were added. Here is an example code:

ESP8266 example code

#include "mbed.h"
#include <string>
#include "ESP8266.h"

// Objects
Serial pc(USBTX, USBRX);
ESP8266 esp(PTE0, PTE1, 115200);

// Global variables
char snd[255], rcv[1000]; // Strings for sending and receiving commands / data / replies

int main() {
    pc.baud(115200);
    pc.printf("START\r\n");
    wait(3);
    
    pc.printf("Reset ESP\r\n");
    esp.Reset();
    esp.RcvReply(rcv, 400);
    pc.printf("%s", rcv);
    wait(2);
    pc.printf("Sending AT\r\n");
    strcpy(snd, "AT");
    esp.SendCMD(snd);
    esp.RcvReply(rcv, 400);
    pc.printf("%s", rcv);
    wait(2);
    pc.printf("Set mode to AP\r\n");
    esp.SetMode(1);
    esp.RcvReply(rcv, 1000);
    pc.printf("%s", rcv);
    
    pc.printf("Receiving Wifi List\r\n");
    esp.GetList(rcv);
    pc.printf("%s", rcv);
    
    pc.printf("Connecting to AP\r\n");
    esp.Join("MyAP", "MyPasswd"); // Replace MyAP and MyPasswd with your SSID and password
    esp.RcvReply(rcv, 1000);
    pc.printf("%s", rcv);
    wait(8);
    pc.printf("Getting IP\r\n");
    esp.GetIP(rcv);
    pc.printf("%s", rcv);
    pc.printf("Setting multiple connections\r\n");
    esp.SetMultiple();
    esp.RcvReply(rcv, 1000);
    pc.printf("%s", rcv);
    pc.printf("Getting Connection Status\r\n");
    esp.GetConnStatus(rcv);
    pc.printf("%s", rcv);
    pc.printf("Start server mode on port 80\r\n");
    esp.StartServerMode(80);
    esp.RcvReply(rcv, 1000);
    pc.printf("%s", rcv);
    wait(4);
    pc.printf("Close server mode\r\n");
    esp.CloseServerMode();
    esp.RcvReply(rcv, 1000);
    pc.printf("THE END");
    while(1);
}

Download repository: zip gz

Files at revision 2:77388e8f0697

Name Size Actions
[up]
ESP8266.cpp 3852 Revisions Annotate
ESP8266.h 2345 Revisions Annotate