ESP-NOW is a connectionless Wi-Fi communication protocol defined by Espressif Systems. In ESP-NOW, application data is encapsulated in action frames from each provider and then transferred from one Wi-Fi device to another without connection. CTR and CBC-MAC Protocol (CCMP) can be used to secure action frames. ESP-NOW is widely used in smart lighting, remote control, sensors and other fields
Most of the open source projects are about the WiFi function of ESP8266, and there is basically no ESP_NOW protocol. I think this ESP_NOW is actually very good. In terms of power consumption, response speed and signal coverage, it is stronger than the 315M/433M module. At the same time, it automatically With verification, packet loss and errors rarely occur in actual measurements.
The production of the ESP_NOW gateway is also simpler than the 315M/433M module. Just use another ESP8266 or ESP32.
In terms of hardware, ESP8266 is used as the sending end of the ESP_NOW switch. When the switch is not pressed, ESP8266 is in a permanent sleep state. When the switch is pressed, it resets the chip and latches the pressed switch. After the chip starts, it reads You can determine which button was pressed by taking the port status, and at the same time send data through the ESP_NOW protocol. After the data is sent, it enters the sleep state again.
In terms of power consumption, it is about 20mA when transmitting and less than 5uA when sleeping. If it is not switched on and off very frequently, a 200mAH lithium battery is estimated to last for one year.
At present, the project has been tested, functions normally, and has been put into use.
[x] Schematic design
[x] PCB diagram design
[x] PCB proofing
[x] Welding test
[x] Functional testing
[x] Program testing
The more innovative part of the circuit is the circuit that resets and latches the IO status at the same time. When the switch is pressed, RST can be reset and the corresponding port is pulled high. After the ESP8266 detects the port, the port level is pulled low. , release the latch state.
#include
extern "C" {
#include
}
#define espNowSwitchID 0x01
#define WIFI_CHANNEL 1
#define SEND_TIMEOUT 10000
#define SW1 14
#define SW2 12
#define SW3 13
#define K4 4
uint8_t remoteMac[] = {0x1A, 0xFE, 0x34, 0xCB, 0x68, 0x45};
/*发送数据定义
D0: espNow ID[0-255]
D1: keyValue[0-3]
D2: AD使能 0-未采集 1-已采集
D3-D4: AD数据[电池电压]
*/
uint8_t transferData[8] = {espNowSwitchID};//
volatile boolean readingSent;
uint8_t keyValue = 0;
void setup() {
if (digitalRead(SW1))keyValue = 1;
if (digitalRead(SW2))keyValue = 2;
if (digitalRead(SW3))keyValue = 3;
pinMode(SW1, OUTPUT);
pinMode(SW2, OUTPUT);
pinMode(SW3, OUTPUT);
digitalWrite(SW1, LOW);
digitalWrite(SW2, LOW);
digitalWrite(SW3, LOW);
WiFi.mode(WIFI_STA);
WiFi.begin();
if (esp_now_init() != 0) {
ESP.restart();
}
delay(1); // This delay seems to make it work more reliably???
esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
esp_now_add_peer(remoteMac, ESP_NOW_ROLE_SLAVE, WIFI_CHANNEL, NULL, 0);
esp_now_register_send_cb([](uint8_t* mac, uint8_t status) {
readingSent = true;
});
sendReading();
}
void loop() {
if (readingSent || (millis() > SEND_TIMEOUT)) {
ESP.deepSleep(0);
}
}
void sendReading() {
readingSent = false;
transferData[1] = keyValue;
esp_now_send(NULL, transferData, 8);
}
There is a problem with the packaging of HT7333 in the PCB! ! ! Remember to transfer here
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet