Build a reliable, long-range mesh network using ESP-NOW, a proprietary peer-to-peer protocol from Espressif. This system allows dozens of sensors to communicate with a central gateway over hundreds of meters without needing a WiFi router or an internet connection.
Standard WiFi is power-hungry and reliant on an Access Point. ESP-NOW is a low-power wireless communication protocol that allows devices to connect directly via MAC addresses. In this mesh project, multiple "Leaf Nodes" monitor environmental data and transmit it to a "Gateway Node" that bridges the data to the web.
Because ESP-NOW doesn't require a handshake with a router, nodes can wake up, send data, and return to deep sleep in milliseconds, allowing a sensor to run for years on a single LiPo battery.
| Part Name | Qty |
|---|---|
| ESP32 (Gateway Node) | 1 |
| ESP32 or ESP8266 (Sensor Nodes) | 2+ |
| DHT22 Temperature & Humidity Sensors | 2+ |
| LiPo Battery (for Nodes) | 2+ |
Each Leaf Node connects to a sensor. The protocol manages the wireless links automatically via software.
| Peripheral | Device Pin | ESP32 Pin | Notes |
|---|---|---|---|
| DHT22 Sensor | OUT / Data | GPIO 4 | 10k Pull-up resistor |
| Status LED | Anode | GPIO 2 | On-board LED blink |
| Battery In | VCC | VIN / 5V | Via 3.3V LDO |
#include <esp_now.h>
#include <WiFi.h>
// REPLACE WITH THE MAC ADDRESS OF YOUR GATEWAY
uint8_t gatewayAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
typedef struct struct_message {
int id;
float temp;
float hum;
} struct_message;
struct_message myData;
esp_now_peer_info_t peerInfo;
void setup() {
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) return;
memcpy(peerInfo.peer_addr, gatewayAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
esp_now_add_peer(&peerInfo);
}
void loop() {
myData.id = 1;
myData.temp = 24.5; // Read from DHT
myData.hum = 55.0;
esp_now_send(gatewayAddress, (uint8_t *) &myData, sizeof(myData));
delay(10000);
}