Projects / ESP-NOW sensor network without a router

ESP-NOW sensor network without a router

Intermediate2.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Upload the gateway

    Flash the gateway sketch to the third board and open the serial monitor. Copy its MAC address.

  2. ESP32

    Edit the sensor sketch

    Paste the MAC into GATEWAY and set SENSOR_ID to 1.

  3. ESP32DHT22USB27.6°C

    Wire each sensor node

    DHT22 data to GPIO 4 with a 10 kΩ pull-up to 3V3.

  4. ESP32

    Upload to both sensor boards

    Use SENSOR_ID 1 on one and 2 on the other.

  5. ESP32

    Watch the gateway

    A line appears from each node every minute with a rising sequence number.

  6. ESP32USB

    Test sleep

    Power a node from a USB meter and see the current fall between sends.

  7. ESP32

    Spot lost packets

    A gap in the sequence numbers shows a missing packet.

In short

How do you build an ESP-NOW sensor network without a router?

Two sensor nodes send temperature and humidity to a gateway with ESP-NOW, which needs no Wi-Fi router and sleeps between readings. You need ESP32 DevKit V1 × 3, DHT22 Sensor × 2, Resistor 10 kΩ × 2, SSD1306 OLED Display, USB A to micro-USB cable (data) × 3 and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 150 minutes.

Level
Intermediate
Time
About 150 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
DHT22 VCC and GNDESP32 3V3 and GNDSensor supply
DHT22 DATAESP32 GPIO 4, with 10 kΩ to 3V3Pull-up
Wire the second sensor node the same~ Both nodes are identical
GatewayThird ESP32 on USBReceives and prints
USB powerPower bank or USB adapter for the sensor nodesA LiPo cannot be connected directly (a charged cell is above 3.6 V)

Code

Arduino IDE with the ESP32 board package by Espressif (version 3.x for the callback shown, on 2.x the receive callback takes the MAC address as its first argument). Install "DHT sensor library" by Adafruit. Upload the gateway first to read its MAC address. ESP-NOW on a classic ESP32 devkit still draws milliamps in sleep because of the board's regulator and USB chip, so a bare module is better for months on a battery.

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// ===== SENSOR NODE (upload to both sensor boards, set SENSOR_ID to 1 and 2) =====
#include <WiFi.h>
#include <esp_now.h>
#include <DHT.h>

uint8_t GATEWAY[] = {0x24, 0x6F, 0x28, 0x00, 0x00, 0x00};   // replace with your gateway's MAC
#define SENSOR_ID 1
DHT dht(4, DHT22);
typedef struct { uint8_t id; uint16_t seq; float t; float h; } Msg;
RTC_DATA_ATTR uint16_t seq = 0;            // survives deep sleep, to spot lost packets

void goToSleep() { esp_sleep_enable_timer_wakeup(60ULL * 1000000ULL); esp_deep_sleep_start(); }

void setup() {
  dht.begin();
  delay(2000);                              // the DHT22 needs time after power
  WiFi.mode(WIFI_STA);
  if (esp_now_init() != ESP_OK) goToSleep();
  esp_now_peer_info_t peer = {};
  memcpy(peer.peer_addr, GATEWAY, 6);
  peer.channel = 0; peer.encrypt = false;
  esp_now_add_peer(&peer);
  Msg m = {SENSOR_ID, seq++, dht.readTemperature(), dht.readHumidity()};
  esp_now_send(GATEWAY, (uint8_t *)&m, sizeof(m));
  delay(100);
  goToSleep();
}
void loop() {}

// ===== GATEWAY (upload to the third board, remove the // marks) =====
// #include <WiFi.h>
// #include <esp_now.h>
// typedef struct { uint8_t id; uint16_t seq; float t; float h; } Msg;
// void onRecv(const esp_now_recv_info_t *info, const uint8_t *data, int len) {   // ESP32 core 3.x
//   Msg m; memcpy(&m, data, sizeof(m));
//   Serial.printf("node %u #%u  %.1f C  %.0f %%\n", m.id, m.seq, m.t, m.h);
// }
// void setup() {
//   Serial.begin(115200);
//   WiFi.mode(WIFI_STA);
//   Serial.println(WiFi.macAddress());      // copy this into the sensor sketch
//   esp_now_init();
//   esp_now_register_recv_cb(onRecv);
// }
// void loop() {}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

[deep sleep for 1 min 0 s]

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Gateway serial monitorLines from node 1 and node 2 every minute
TemperatureWithin 1 °C of a reference thermometer
Cover one node's antenna with metalSequence gaps appear
Range testWorks through one or two walls

If it does not work

No messages

The MAC address is wrong or the gateway sketch is not running. Copy it again.

Compile error about the callback

Your core version differs. On 2.x the first argument is const uint8_t *mac.

DHT22 returns NaN

Check the pull-up and the 2 second wait after power.

Nodes miss readings

Move closer and keep antennas away from metal.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the ESP-NOW sensor network without a router?

ESP32 DevKit V1 × 3, DHT22 Sensor × 2, Resistor 10 kΩ × 2, SSD1306 OLED Display, USB A to micro-USB cable (data) × 3 and Jumper wires male to male (40 pcs, 20 cm). SSD1306 OLED Display: Optional: show the latest readings at the gateway.

How long does the ESP-NOW sensor network without a router take to build?

About 150 minutes for a intermediate maker, in 7 steps.

How do I know the ESP-NOW sensor network without a router works?

Gateway serial monitor: Lines from node 1 and node 2 every minute. Temperature: Within 1 °C of a reference thermometer. Cover one node's antenna with metal: Sequence gaps appear.

No messages: what should I check?

The MAC address is wrong or the gateway sketch is not running. Copy it again.

Compile error about the callback: what should I check?

Your core version differs. On 2.x the first argument is const uint8_t *mac.

DHT22 returns NaN: what should I check?

Check the pull-up and the 2 second wait after power.

Nodes miss readings: what should I check?

Move closer and keep antennas away from metal.