Wifi Module-ESP-01s

Wifi Module-ESP-01s

Bluetooth, ESP-01s, Zigbee, NB-lot and other communication modules are all designed based on AT commands
What is an AT command?

The AT instruction set is from the terminal equipment (Terminal Equipment, TE) or data terminal equipment (Data Terminal
Equipment, DTE) to Terminal Adapter (Terminal Adapter, TA) or Data Circuit Terminal Equipment (Data Circuit
Terminal Equipment, DCE).
It has a definition for the size of the transmitted data packet: that is, for the transmission of AT commands, except for the two characters of AT, up to 1056 characters can be received
The length in characters (including the final null character).
Each AT command line can only contain one AT command; for the URC instruction or response actively reported by the terminal device to the PC
Responses also require at most one line, and multiple indications or responses are not allowed in one line. AT command ends with carriage return
end, the response or report ends with a carriage return and line feed.
Initial configuration and verification
The factory baud rate of ESP-01s is normally 115200. Note: AT commands and control types must be added with a carriage return, and no carriage return is required for data transmission.

  • After power on, output a series of system startup information through the serial port. Some purchased modules may have unstable voltage and cause garbled characters. The ready shall prevail.
################################################# #
arch:ESP8266, 1
compile_time:Ai-Thinker|B & amp;T
wifi_mac:4c75250dAE2F
sdk_version:v3.4-22-g967752e2
firmware_version: 2.2.0
compile_time: Jun 30 2021 11:28:20
ready
###################################################
  • After power on, send AT commands to test whether the communication and module functions are normal
AT

OK
  • Configure to 9600 baud rate by command
AT+UART=9600,8,1,0,0

Internet access settings

  • Set working mode
AT + CWMODE=3 //1. is station (device) mode 2. is AP (routing) mode 3. is dual mode

OK
  • Access home router configuration in device mode
AT + CWJAP="TP-LINK_3E30","18650711783" //command
WIFI CONNECTED //result
WIFI GOT IP //result
  • Query IP address
AT + CIFSR //command
 + CIFSR:APIP,"192.168.4.1"
 + CIFSR:APMAC,"4e:75:25:0d:ae:2f"
 + CIFSR:STAIP,"192.168.0.148"
 + CIFSR:STAMAC,"4c:75:25:0d:ae:2f"
OK

Connect to TCP server

  1. Switch network assistant, build TCP server
  2. connect to the server
AT + CIPSTART="TCP","192.168.0.113",8888 //Command, note that double quotation marks and commas must be entered in half-width (English)
CONNECT //result: success
OK
  1. send data
AT + CIPSEND=4 // Set the length of the data to be sent (here is 4 bytes)
>CLCA // After seeing the greater than sign, enter a message, CLCA, do not press Enter
Response: SEND OK //Result: success
//Attention, in this case, AT + CIPSEND=length command must be sent before each sending, and then send data!

Transparent

Every time you send data, you need to set the character length. If it is set to transparent transmission, it is a bit like the bluetooth module.

AT + CIPMODE=1 //Enable transparent transmission mode
Response: OK
AT + CIPSEND //Bring carriage return
Response: > //Send and receive data freely at this time

Exit transparent transmission mode

//In the process of sending data through transparent transmission, if a single? packet data " + + + " is recognized, then exit the transparent transmission

The above series are handed over to the single chip microcomputer to realize

#include "reg52.h"
#include "intrins.h"
#include <string.h>

#define SIZE 12
sfr AUXR = 0x8E;
sbit D5 = P3^7;
sbit D6 = P3^6;

char buffer[SIZE];
code char LJWL[] = "AT + CWJAP="TP-LINK_830B","dzz020398"\r\
";
code char LJFWQ[] = "AT + CIPSTART="TCP","192.168.1.104",8880\r\
";
char TCMS[] = "AT + CIPMODE=1\r\
"; //Transparent transmission command
char SJCS[] = "AT + CIPSEND\r\
"; //Data transmission start command
char RESET[] = "AT + RST\r\
";

char AT_OK_Flag = 0;
char AT_Connect_Net_Flag = 0;

void UartInit(void) //[email protected]
{<!-- -->
SCON = 0x50; // Configure serial port working mode 1, REN enables receiving
TMOD &= 0xF0;
TMOD |= 0x20; // configure timer 1 working mode 8-bit auto-reload
\t
TH1 = 0xFD;
TL1 = 0xFD; // initial value of 9600 baud rate
TR1 = 1; // start timer
\t
// enable total interrupt
EA = 1;
// Enable serial port interrupt
ES = 1;
}

void Delay1000ms() //@11.0592MHz
{<!-- -->
unsigned char i, j, k;

//_nop_();
i = 8;
j = 1;
k = 243;
do
{<!-- -->
do
{<!-- -->
while (--k);
} while (--j);
} while (--i);
}



void sendByte(char data_msg)
{<!-- -->
SBUF = data_msg;
while(!TI);
TI = 0;
}

void sendString(char *str)
{<!-- -->
while(*str != '\0'){<!-- -->
sendByte(*str);
str++;
}
}

void main()
{<!-- -->
int mark = 0;
D5 = D6 = 1; // off
// Configure the communication mode of the C51 serial port
UartInit();
Delay1000ms(); //Give espwifi module power-on time

sendString(LJWL);
//while(!AT_Connect_Net_Flag);
while(!AT_OK_Flag);
AT_OK_Flag = 0;
\t
sendString(LJFWQ);
while(!AT_OK_Flag);
AT_OK_Flag = 0;
\t
sendString(TCMS);
while(!AT_OK_Flag);
AT_OK_Flag = 0;
\t
sendString(SJCS);
while(!AT_OK_Flag);
\t
if(AT_Connect_Net_Flag){<!-- -->
D5 = 0; // Turn on D5, which means the network is successfully connected
}
\t
if(AT_OK_Flag){<!-- -->
D6 = 0; // Turn on D6, which means connecting to the server and opening the transparent transmission mode successfully
}
\t
while(1){<!-- -->
Delay1000ms();
// Write data to the sending buffer to complete the data sending
sendString("dzz henshuai\r\
");
}
}

void Uart_Handler() interrupt 4
{<!-- -->
static int i = 0;//static variable, initialized once
char tmp;
if(RI)//In the interrupt processing function, the response to the receiving interrupt
{<!-- -->
RI = 0;//clear receive interrupt flag bit
tmp = SBUF;
\t\t
if(tmp == 'W' || tmp == 'O' || tmp == 'L' || tmp == 'F'){<!-- -->
i = 0;
}
buffer[i + + ] = tmp;
\t\t\t
if(buffer[0] == 'W' & amp; & amp; buffer[5] == 'G'){<!-- -->
AT_Connect_Net_Flag = 1;
memset(buffer, '\0', SIZE);
}
\t\t\t
if(buffer[0] == 'O' & amp; & amp; buffer[1] == 'K'){<!-- -->
AT_OK_Flag = 1;
memset(buffer, '\0', SIZE);
}
\t\t\t
if(buffer[0] == 'F' & amp; & amp; buffer[1] == 'A'){<!-- -->
for(i = 0; i < 5; i ++ ){<!-- -->
D5 = 0;
Delay1000ms();
D5 = 1;
Delay1000ms();
}
sendString(RESET);
memset(buffer, '\0', SIZE);
}
\t\t
if(buffer[0] == 'L' & amp; & amp; buffer[2] == '1'){<!-- -->
D5 = 0;//light up D5
memset(buffer, '\0', SIZE);
}
if(buffer[0] == 'L' & amp; & amp; buffer[2] == '0'){<!-- -->
D5 = 1; // turn off D5
memset(buffer, '\0', SIZE);
}
if(i == 12){<!-- -->
i = 0;
}
}
\t\t
if(TI);
}