9 years, 4 months ago.

Have you got this working ?

Have you some more code available ? and how to communicate with PC ??

Got a few of these on order.

Cheers

Ceri

Question relating to:

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

Hi there, there is a bit of confusion over pin status at boot and baud rate of the Pins on the ESP8266-0X this is detailed on github, this link is a basic starter it will ensure you know where you are starting from, both the AT and NodeMCU firmware are there with some basic instructions.... https://github.com/genguskahn/ESP8266-For-DUMMIES at least this will give confidence in the status of the module, known firmware etc.

posted by Quincy Magoo 29 Jan 2015

Heres an mbed notebook page detailing how to do the firmware update process. http://developer.mbed.org/users/mbedAustin/notebook/esp8266-firmware-update/

posted by Austin Blackstone 28 Apr 2015

1 Answer

9 years, 4 months ago.

Hello Ceri,

I apologize for not posting an example code. I started this library as a set of functions in a simple mbed project. After a while, I decided to convert this set to a library. I am posting the example code below. This code was tested and works adequately. Note that after connecting to my wifi router, I wait for 8 seconds before getting the module IP. When I tried to get it right after connection, I got an "Error" reply. If I wait for about 8 seconds, I can get the IP without errors.

As for PC communication, I am still working on that. So far, I only send commands to the module, and get its reply into a string.l Then, I just print the reply string to the PC serial port (through USB). So far I am not accessing web pages or sockets. I am just checking if I connect to my network and getting the local (router-given) IP address.

As I mentioned in my original post, new commands will be added soon. Until there, you may use the SendCMD function to send any command to the module, passing the command string without the 0x0D-0x0A characters (these are added by the function).

I also recommend to look for recent posts at MCU on Eclipse, where Erich Styger has been working on these modules.

The program was tested with a FRDM-KL25 board, but it should work OK with other platforms. Just remember to change Tx and Rx pins for the ESP8266 object, according to the UART pins at the board you are using.

I hope it helps. Feel free to contact me for more information.

Cheers,

Antonio

ESP8266 Example code

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

// RUN THIS EXAMPLE WITH A SERIAL TERMINAL AT 115200bps


// Objects
Serial pc(USBTX, USBRX);
ESP8266 esp(PTE0, PTE1); // Tx and Rx, on MCU point of view

// 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"); // Resetting ESP
    esp.Reset();
    esp.RcvReply(rcv, 400);
    pc.printf("%s", rcv);
    wait(2);

    pc.printf("Sending AT\r\n"); // Sending "AT" to get "OK" reply
    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", "MyPwd"); // REPLACE "MyAP" and "MyPwd" by your network name and password, keeping commas
    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("THE END");
    while(1);
}

Accepted Answer

First of all, thanks for your effort. Second for people: Note that the firmware version you have also determines the baudrate you should use! It seems later firmware versions run on a default 9600 baudrate. (And nop there is no way to figure out which firmware version you have if you don't have the baudrate, so guessing it is, or automating an algorithm to find it).

But now after alot of tinkernig, randomly trying which pin should be high and which should be not, figuring out the online compiler didn't properly run my K20D50M I randomly choose for interfacing at correct UART baudrate (might be relevant to mention I accidently updated mbed-src of a completely different program :D), it is responding to commands :D.

posted by Erik - 21 Dec 2014

My module did also use 9600 baudrate. Maybe next time the library gets updated the baud rate should be added as an parameter to the constructor?

posted by Jonas Green 25 Dec 2014

Hello Jonas,

I have heard of the different baudrates in different firmware versions, and actually I think it is quite stupid to communicate at 9600 if the module works at higher rates. Anyway, I appreciate your feedback, and I have already added the baud rate as a parameter to the constructor. I am going to add other functions before releasing a new version, but it may take a few days since I am enjoying the holidays. However, I should have a new version soon.

posted by Antonio Quevedo 28 Dec 2014