ESP01S WIFI Module
The ESP8266 series wireless module is a series of high-cost-performance Wi-Fi SoC modules independently developed and designed by Anxinke Technology. This series of modules supports the standard IEEE 802.11 b/g/n protocol and has a complete built-in TCP/IP protocol stack. Users can use these modules to add networking functionality to existing devices or build independent network controllers. Even without understanding the underlying principles, users can easily get started with the module and achieve mobile Wi-Fi operations as long as they have some knowledge of serial communication. The module is developed based on the ESP8266 chip and integrates transparent transmission functionality, making it ready to use right out of the box. It supports serial AT commands, enabling users to access the network via serial communication. It is widely used in areas such as smart wearables, smart home, home security, remote controls, automotive electronics, smart lighting, and industrial IoT.
Module Source
Purchase Link:
https://item.taobao.com/item.htm?spm=a21n57.1.0.0.7b86523chejZKP&id=609138951184&ns=1&abbucket=0
Baidu Netdisk Download Link:
https://pan.baidu.com/s/13mQInPq5drMzs8sXzC14dQ
Password: pj4z
Specifications
Operating Voltage:3.0V-3.6V
Operating Current:IMAX = 170mA
Module Dimensions:14.4 x 24.7 MM
Control Method: Serial Interface
Instructions for Use
This Wi-Fi module has three modes: STA, AP, and STA+AP.
Here, we mainly use AP and STA modes as examples to implement short-range and long-range wireless control.
- In STA mode, the ESP8266 acts as a client connecting to a wireless router (or hotspot), allowing access to other devices on the network.
- In AP mode, the ESP8266 functions as an access point, allowing other devices to connect to it and enabling wireless communication.
- STA+AP mode simultaneously enables both functionalities.
Before using, you need to flash the MQTT firmware. Subsequent examples will use MQTT; if the MQTT firmware is not flashed, MQTT-related AT commands will continuously fail.
Firmware flashing wiring:
Development Board | ESP-01S |
---|---|
3V3 | 3V3 |
TXD | TX |
RXD | RX |
GND | GND |
GND | IO0 |
During flashing, make sure there is no serial code on the development board, otherwise the download will fail. If there is code and it's inconvenient to erase, you can hold down the reset button on the development board during the download process until it succeeds.
Flashing steps:
Hardware Connection
Development Board | ESP-01S |
---|---|
3V3 | 3V3 |
3 | RX |
2 | TX |
GND | GND |
Usage Method
Place the following two files in the project directory, at the same level as the .ino file.
File Download
📌 Download Center (Click the link)
📌 In the Download Center->Module Porting Guide [Non Porting Code], inside the Chapter Compression Package.
Enter the code:
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 11, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
#include "ESP01S_lib.h"
// 放弃以下针脚用于软件串口
#define RX_PIN 2 // 开发板的RX(连接到ESP-01S的TX)
#define TX_PIN 3 // 开发板的TX(连接到ESP-01S的RX)
unsigned long previousMillis = 0; // 存储上一次发送数据的时间
unsigned long currentMillis = 0;
ESP01S_lib wifi(TX_PIN,RX_PIN);
void setup() {
// 开始串口通讯
Serial.begin(115200); // 硬件串口与计算机通信
Serial.println("start");
//WIFI初始化
wifi.begin(115200);
//开启AP模式
int ret = wifi.AP_mode_begin("LCKFB", "12345678",8080);
//如果开启失败
if(ret != 1 )
{
Serial.print("Initialization failed with failure code: ");
Serial.print(ret);
}
}
void loop() {
int wifi_id = 300;//WIFI连接的ID,因为不会超过5个设备,所以随便选择一个大5的数
int again_wifi_id = 0;
char wifi_data[]={0};
int wifidatalen=0;
//接收WIFI发送过来的数据
wifi.WIFI_Data_Scan();
wifi.Get_WIFI_AP_Data(&wifi_id,wifi_data,&wifidatalen);
if( wifi_id != 300 )//如果ID有更新,说明有设备发来数据
{
Serial.print(wifidatalen);
Serial.print(" bytes of data from device ");
Serial.print(wifi_id);
Serial.print(" : ");
Serial.println(wifi_data);
again_wifi_id = wifi_id;
wifi_id = 300;//还原ID值,等待下一次接收
}
//每次隔5秒发送字符串给设备
currentMillis = millis();
if( currentMillis - previousMillis >= 5000 ){
previousMillis = currentMillis;
wifi.WIFI_Send_To_Client(again_wifi_id,"Hello LCKFB");
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Usage Testing
After uploading the code to the development board, open the serial monitor and wait for the network configuration to complete. Once done, open your phone's Wi-Fi settings, and you should see a Wi-Fi network named LCKFB. Connect using the password: 12345678. After the connection is successful, open the mobile app: TCP connection, and create a new connection with the address 192.168.4.1 and the port set to 8080. Once connected, the phone can send data to the development board, which will output the received data to the serial monitor. After the connection is established, the phone will receive data from the development board every 5 seconds.
If the phone cannot connect, please turn off the mobile data network. Some phones have a network selection feature that may prevent Wi-Fi communication if there is no internet connection available.