ESP8266 AT Cmds Examples
Example 1 Example 2 Example 3

Example 1
/*H********************************************************************
*
**********************************************************************/
#include <SoftwareSerial.h>                        

//************************* DEFINES ************************************
#define DEBUG   true                                 
#define ESPTX   9
#define ESPRX   8
#define BAUD    115200               

//************************* PROTOTYPES ************************************
int  sndDat( char *outBUf, char *cmd, int timot, bool debug );
void initWifiModule();

//************************* VARIABLES ************************************
SoftwareSerial  Esp( ESPRX, ESPTX );                   

/*F********************************************************************
*
**********************************************************************/
void 
setup()
{
    Serial.begin( BAUD );           
    Esp.begin( BAUD );     
    initWifiModule();                              
}
/*F********************************************************************
*
**********************************************************************/
void 
loop()                                                         
{
    int     connId;
    String  webpage, cipSend, clsCmmd; 

    if( Esp.available() )                                           
    {    
        if( Esp.find( "+IPD," ) )
        {
            delay( 1000 );
            connId = Esp.read() - 48;
            webpage = "<h1>Hello WorplyLend!<</h1>
            cipSend = "AT+CIPSEND=";                     // BUILD CMD STRING
            cipSend += connId;
            cipSend += ",";
            cipSend += webpage.length();
            cipSend += "\r\n";
            sndDat( cipSend, 1000, DEBUG);
            sndDat( webpage, 1000, DEBUG);
            clsCmmd = "AT+CIPCLOSE=";              // BUILD CLOSE CMD STRING
            clsCmmd += connId;                       // APPEND CONNECTION ID
            clsCmmd += "\r\n";    
            sndDat( clsCmmd, 3000, DEBUG );
        }
    }
}
/*F********************************************************************
*
**********************************************************************/
String 
sndDat( String command, const int timOt, boolean debug)
{
    long int  end;
    char      chr;

    String response = "";                                             
    Esp.print( command );                                          
    end = millis() + timOt;                                      
    while( end  > millis())                                 
    {      
        while( Esp.available() )                                      
        {
            chr = Esp.read();                                     
            response += chr;                                                  
        }  
    }    
    if( debug )                                                        
        Serial.print( response );
    return( response );                                                  
}
/*F********************************************************************
*
**********************************************************************/
void 
initWifiModule()
{
    sndDat( "AT+RST\r\n", 2000, DEBUG);
    sndDat( "AT+CWJAP=\"SSID\",\"Password\"\r\n", 2000, DEBUG);
    delay( 3000 );
    sndDat( "AT+CWMODE=1\r\n", 1500, DEBUG);
    delay( 1500 );
    sndDat( "AT+CIFSR\r\n", 1500, DEBUG);
    delay( 1500 );
    sndDat( "AT+CIPMUX=1\r\n", 1500, DEBUG);
    delay( 1500 );
    sndDat( "AT+CIPSERVER=1,80\r\n", 1500, DEBUG);
}

Example 2
#include <SoftwareSerial.h>

//************************* DEFINES ************************************
#define DEBUG true  // MARCHEAZA CA VARIABILA DEBUG ESTE ADEVARATA

//************************* PROTOTYPES ************************************
String sndDat( String command, const int timeout, boolean debug);

//************************* VARIABLES ************************************
SoftwareSerial esp8266( 2, 3); // connect ESP TX line to pin 2, RX pin 3
                             
/*F********************************************************************
*
**********************************************************************/
void 
setup()
{
    Serial.begin( 9600 );                     // INIT CONSOLE SERIAL TO 9600
    esp8266.begin( 9600 );                        // INIT ESP SERIAL TO 9600
    sndDat( "AT+RST\r\n", 5000, DEBUG);                     // RST ESP8266
    sndDat( "AT+CWMODE=2\r\n", 1000, DEBUG); // CONFIG ESP AS ACCESS POINT 
    sndDat( "AT+CIFSR\r\n", 1000, DEBUG);                // GET IP ADDRESS
    sndDat( "AT+CIPMUX=1\r\n", 1000, DEBUG);     // CONFIG FOR MULTI CONNS
    sndDat( "AT+CIPSERVER=1,80\r\n", 1000, DEBUG); // ENAB SERVER, PORT:80
}
/*F********************************************************************
*
**********************************************************************/
void 
loop()
{
	if( esp8266.available() )                 // CHECK DATA AVAILABLE FROM ESP
	{    
		if( esp8266.find("+IPD,") )
		{
			sndDat( "AT+CIPSEND=0,30\r\n", 1000, DEBUG);       // SEND CMD
			delay( 2000 );
			esp8266.println( "hello!!\r\n");
			delay( 2000 );
			sndDat( "AT+CIPCLOSE=0\r\n", 1000, DEBUG);       // CLOSE CONN
			sndDat( "AT+CIPCLOSE=1\r\n", 1000, DEBUG);       // CLOSE CONN
			sndDat( "AT+CIPCLOSE=2\r\n", 1000, DEBUG);       // CLOSE CONN
			sndDat( "AT+CIPCLOSE=3\r\n", 1000, DEBUG);       // CLOSE CONN
			sndDat( "AT+CIPCLOSE=4\r\n", 1000, DEBUG);       // CLOSE CONN
			sndDat( "AT+CIPCLOSE=0\r\n", 1000, DEBUG);       // CLOSE CONN
			sndDat( "AT+CIPCLOSE=1\r\n", 1000, DEBUG);       // CLOSE CONN
		}
	}
}
/F********************************************************
* SEND DATA TO ESP8266.
* Params: COMMAND: DATA/COMMAND TO SEND, TIMEOUT: RESPONSE WAIT TIME
* DEBUG: PRINT TO CONSOLE (TRUE = YES, FALSE = NO)
* Returns: RESPONSE FROM ESP8266
********************************************************/
int
sndDat( char *buf, char *cmd, int timot, bool debug )
{
	int       ndx;
	ulong     time;
	char      chr;

	esp8266.print( cmd );                  // SEND READ CHARACTER TO ESP8266
	time = millis() + timeout;
	for( ndx =0; (time > millis()); )
	{
		while( esp8266.available() )                   // ESP DATA AVAILABLE
		{
			chr = esp8266.read();                     // READ NEXT CHARACTER
			buf[ndx++] = chr;
		}  
	}
	if( debug )
		Serial.print( buf );
	return( OK );
}


Example 3
ESP Converstaions
===========================================================================
            From: Arduino and ESP8266, CIPSTA_DEF command
https://forum.arduino.cc/t/arduino-and-esp8266-cipsta_def-command/594110
===========================================================================

// ESP8266, CIPSTA_DEF COMMAND
AT+CWJAP?                                                // JOINED TO AN AP?
AT+CIFSR                                                // SET MY IP ADDRESS

If AP name and IP address are correct then valid connection is assumed. If
either of above are not correct then configuration is assumed to be invalid
and following sent to configure it:

AT+CWDHCP_DEF=1,0                  // DISABLE DHCP (NEED TO USE A STATIC IP)
AT+CWQAP                                                  // QUIT CURRENT AP
AT+CWJAP="ESSID","password"                // AP NAME AND PASSWORD SPECIFIED
AT+CIPSTA_DEF="10.210.210.117","10.210.210.125","255.255.255.192" // Set IP addr

This does actually work up to second command, but final command seems to fail.
If I do not disable DHCP, then I do get an IP address assigned by DHCP server
so I know that I am connecting to WiFi network. [64 Chr limit]

Last command that sets a static IP address echoes back as follows:
    AT+CIPSTA_DEF="10.210.210.117","10.210.210.125","255.255.255.19 // TOO LONG

The β€˜2"’ truncated and command does not get executed as IP address is not changed. If I paste command into serial monitor and send it manually, it works as expected. I am currently programming using a UNO with ESP8266 connected to pins 5 and 6, and I am using softwareserial to communicate with it.

BTW, I also tried this:
AT+CIPSTA="10.210.210.117","10.210.210.125","255.255.255.192"
//                      WORKS OK
Serial1.print( F( "AT+CIPSTA_DEF=\"" AR_WL_ADDR "\","));
delay( 200 );
Serial1.println( F( "\"" AR_WL_GATE "\",\"" AR_WL_MASK "\""));
if( !replyContains( "OK", 400, 200)) 
    return false;

    AT+CIPSTA?                                                  // QUERY CMD

    +CIPSTA:ip:<"ip">                                            // SET CMDS
    +CIPSTA:gateway:<"gateway">
    +CIPSTA:netmask:<"netmask">

    AT+CIPSTA=<"ip">[,<"gateway">,<"netmask">]
The deprecated variant of command without β€œ_DEF” seems to get echoed back complete but I do not get OK reply and IP address is not getting set.
typedef unsigned long ulong;
typedef unsigned int  uint;

/*F********************************************************************
* code that sequence sends config commands:
**********************************************************************/
bool 
wifiCfg()
{
                                      // SET OPERATING MODE AND DISABLE DHCP
    Serial1.println( F( "AT+CWDHCP_DEF=1,0" ) );
    if( !replyContains( "OK", 400, 200 ) ) 
        return( false );
    Serial1.println( F( "AT+CWQAP" ));          // IF CONNECTED TO AP, DCONN
    if( replyContains( "OK", 400, 200))
    {
                                                    // CONNECT TO DEFINED AP
        Serial1.println( F( "AT+CWJAP=\"" AR_WL_NAME "\",\"" AR_WL_PASS "\""));
        if( !replyContains( "CONNECTED", 10000, 800)) 
            return( false );
        Serial1.println( F( "AT+CIPSTA_DEF=\"" AR_WL_ADDR "\"
            , \"" AR_WL_GATE "\", \"" AR_WL_MASK "\""));      // SET IP ADDR
        if( !replyContains( "OK", 400, 300)) 
            return( false );
    }
    return( true );                                    // SUCCESS!
}
/*F********************************************************************
* replyContains() wait for response:
**********************************************************************/
bool 
rplyContains( const char *rply, uint waitA, uint waitB) 
{
    int       val1, val2;
    uint8_t   rplyLen, idx, chr;
	ulong     end;

    rplyLen = strplyLenen( rply );                           // CLEAR BUFFER
    idx = chr = 0;
    if( !waitA) 
        waitA = 1000;                                       // DFLT TIMEOUTS
    if( !waitB) 
        waitB = 100;
    end = millis() + waitA;               // SET TIMEOUT THRESHOLD
    val1 = val2 =0;
    while( millis() < end) 
    {
        while( esp8266.available()) 
        {
            chr = esp8266.read();                          // READ CHARACTER
            val1++;
            //      Serial.print( chr, HEX );
            //      Serial.print( "[" );
            Serial.print( (char)chr );
            //      Serial.print( "] " );
            /* if( chr == 10)                                   // BREAK ON LF
            {
                if( idx < rplyLen) 
                    idx = 0;
                break;
            } */
            // Match character
            if( (chr == rply[idx]) && (idx < rplyLen)) 
                idx++;                     // MATCHED, NOW LOOK FOR NEXT ONE
            else
                if( idx != rplyLen)
                    idx = 0;         // NOT MATCHED - RESET MATCHING PROCESS
        }
        if( val2 > 0) 
        {
            if( val1 > 0 ) 
            {                      // RCVD CHARS - UPDT CNT, WAIT LOOP AGAIN
                val2 += val1;
                val1 = 0;
            }
            else
                break;         // IF NOTHING FURTHER RECEIVED THEN EXIT LOOP
        }
        delay( waitB );
    }
    Serial.println();
    Serial.print( F( "RL:"));
    Serial.println( rplyLen);
    Serial.print( F( "IDX:"));
    Serial.println( idx);
    if( idx == rplyLen) 
    {
        Serial.print( F( "Found: "));
        Serial.println( rply );
    }
    if( idx == rplyLen ) 
        return( true );                                     // REPLY MATCHED
    return( false );                                    // REPLY NOT MATCHED
}