#7 Introduction to ESP01 WiFi Module Commands | Arduino Mega | APDaga Tech

#7 Introduction to ESP01 WiFi Module Commands | Arduino Mega | APDaga Tech

IoT Tutorial #7 [ Arduino Mega Tutorials #7]


Here, I will explain step by step (Manually) how you can send data to the server using ESP01 Wi-Fi Module. (Not using any Program)


Basic knowledge of communication layers is as follows:


Communication Layers:
Application Layer : Generate Msg Signal (Eg. Serial Monitor)
Network Layer      : Assign Source and Destination IP Address to Msg
Data Link Layer    : Data packet will be framed bit by bit
Physical Layer       : Transmitted / Received via medium.

Follow these steps:
  1. Connect ESP01 Module in configuration mode
    PIN Diagram of ESP01: (This module works on 3.3v) (NOT 5v)
    +---------------------------+
    | |=| |=| |=|============== |
    | | | | | | | ANTENA |
    | | |=| |=| | Facing ur side|
    | ========================= |
    | |
    | GND GPIO0 GPIO2 RxD |
    | o o o o |
    | |
    | o o o o |
    | TxD CH_PD RST Vcc |
    +---------------------------+
    Connections for configuration:
    ESP01      Arduino
    Vcc -> 3.3V
    GND -> GND
    TxD -> Tx0
    RxD -> Rx0
    CH_PD -> 3.3V
  2. Open Arduino Serial Monitor and Set Baud Rate = 115200 and select "Both NL and CR" Option

  3. Type following AT commands in given Sequence
    FORMAT:
    ---------------------------
    <Command>
    :Explanation
    --<Expected Output>
    ---------------------------



    AT
    :Attention Command
    --OK
    AT+CWMODE=1  
    :Setting Mode=1
    --OK
    AT+CWLAP
    :Searching for all available Access Points
    --<List of Available Wi-Fi access points>
    AT+CWJAP="<SSID Name>","<password>"
    :To Connect to any Access Point
    Eg. AT+CWJAP="SuiteUp","123456789"
    --WIFI CONNECTED
    --WIFI GOT IPs
    --OK
    AT+CWJAP?  
    :To check to which SSID we are connected
    --<Connected WiFi SSID Name>
    AT+CIFSR
    :To check IP & MAC addr of the WiFi Module
    --<Static IP Address>
    --<Static MAC Address>



    AT+CIPMUX=0
    :To set Mux = 0
    --OK
    AT+CIPSTART="TCP","google.com",80
    :We are asking module to start TCP IP Communication with google.com at port no. 80
    --CONNECT
    --OK
    AT+CIPSEND=18
    :Send 18 Bytes of data
    --OK
    > (prompt is opened)
    This will open a prompt like ">". Then you can send the data using GET command in that prompt as shown below:
    GET /HTTP/1.0\r\n\r\n
    :Send API string
    --Recv 18 bytes
    --SEND OK
    you can check: "/HTTP/1.0\r\n\r\n" This string contains 18 character.

    If we mention fewer bytes in the previous command then send more no. of byte then the server will accept only mentioned no. of byte and ignore remaining bytes.

    Instead of "/HTTP/1.0\r\n\r\n", you can call APIs to send the data to the server and make the graph or do the analysis and post work.

    If your ESP01 module isn't working as expected and you need to reset it to default, you can use the following command:

    AT+RESTORE
    : To Restore all settings to Default
    --OK

    To understand better Watch the demonstration video below.
Demonstration:








Click here to see more codes for Arduino Mega (ATMega 2560) and similar Family.

Feel free to ask doubts in the comment section. I will try my best to solve it.
If you find this helpful by any mean like, comment and share the post.
This is the simplest way to encourage me to keep doing such work.

Thanks and Regards,
-Akshay P. Daga

7 تعليقات

  1. That is really nice to hear. thank you for the update and good luck. Unique wifi names

    ردحذف
  2. Hello.. oke it works..but can you give me simple sketch to turn on a led from android apps?

    ردحذف
  3. Thank you for this fascinating post, I am happy I observed this website on Google. Not just content, in fact, the whole site is fantastic. IP Address

    ردحذف
  4. Hi... Could you help me please.
    wich is the rigth string about "AT+CIPSEND" for this GET to my site:
    www.abbici.org
    /cgi-bin/auto_robot_arduino?fu=gianfry&fp=4rdu1n0&ro=1&val=0
    you can test it free
    change val=1 or 0
    Thank you
    @}-,-'----
    Gianfranco

    ردحذف
  5. I have solved:

    #include "SoftwareSerial.h"
    SoftwareSerial esp(19, 18);// RX, TX 19, 18 with MEGA

    int conta = 0;
    String strtmp;
    String strcopy;

    void setup()
    {
    esp.begin(115200); // Arduino to ESP01 Communication
    }

    void loop()
    {
    esp.println("AT+CIPMUX=0"); // To Set MUX = 0
    delay(2000); // Wait for 2 sec

    // TCP connection
    String cmd = "AT+CIPSTART=\"TCP\",\"www.abbici.org\",80";
    esp.println(cmd); // Send above command to Rx1, Tx1
    delay(2000); // Wait for 20 Sec

    // prepare GET string
    strtmp = String(conta % 2);
    String getStr = "GET /cgi-bin/auto_robot_arduino?fu=gianfry&fp=4rdu1n0&ro=1&val=" + strtmp;
    getStr += " HTTP/1.1";
    getStr += "\r\n";
    getStr += "Host: www.abbici.org";
    getStr += "\r\n";
    getStr += "Connection: close";
    getStr += "\r\n";
    getStr += "\r\n";
    getStr += "\r\n";
    cmd = "AT+CIPSEND="; // send data length
    cmd += String(getStr.length());
    esp.println(cmd); // Send Data length command to Tx1, Rx1
    delay(200);

    esp.print(getStr); // Send Data length command to Tx1, Rx1
    delay(2000);

    esp.println("AT+CIPCLOSE\r\n"); // Send Close Connection command to Rx1, Tx1
    delay(5000); // wait for 5sec
    conta++;
    }

    ردحذف
  6. I forgot: This is a simple example... conta changes value to send my site

    ردحذف
إرسال تعليق
أحدث أقدم