Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: PIR_Sensor_wifi myESP8266forLOstFound Motin_Activated_Temperature_Humidity_BluetoothHC-06_ESP8266_IOT 1Project3_Robot1_Final ... more
Homepage
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);
}