Projects / ESP-NOW range and packet loss

ESP-NOW range and packet loss

One ESP32 sends numbered messages and a second counts how many arrive, while you carry it through the house or along a street. Plot lost messages against distance and walls. It shows the real range of a cheap radio link, and why antenna position matters.

Intermediate1.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Upload the sender sketch

    To the first board and power it from a computer.

  2. ESP328.1 mASSD1306

    Wire the OLED to the second board

    GPIO 21 SDA, GPIO 22 SCL, 3V3 and GND.

  3. ESP32

    Upload the receiver sketch

    To the second board.

  4. ESP32

    Start close together

    Loss is 0 and the signal is strong.

  5. ESP32

    Walk away in steps of five metres

    Note the loss and signal at each step.

  6. ESP32

    Repeat through a wall

    Note how much worse it is.

  7. ESP32

    Chart the results

    Loss and signal against distance, one line for each route.

In short

How do you build an ESP-NOW range and packet loss?

One ESP32 sends numbered messages and a second counts how many arrive, while you carry it through the house or along a street. Plot lost messages against distance and walls. It shows the real range of a cheap radio link, and why antenna position matters. You need ESP32 DevKit V1 × 2, SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 90 minutes.

Level
Intermediate
Time
About 90 min
Parts
4

Parts list

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

Wiring

FromToWhy
Sender boardUSB power from a computer or power bankStays at the start point
Receiver boardUSB power bank, carried away from the senderCounts what arrives
OLED SDA and SCLReceiver GPIO 21 and GPIO 22I2C data and clock
OLED VCC and GNDReceiver 3V3 and GNDPower for the screen

Code

The file holds two separate sketches, one for each board, so copy each into its own Arduino window. The sender broadcasts a number that goes up by one every half second. The receiver notices gaps in the numbers: the messages it should have had so far, which is the last number minus the first plus one, minus those that arrived, is the count lost. It shows received, lost and the signal strength in dBm on the screen, and prints the same as comma separated lines on the serial monitor, ready for a spreadsheet. Signal strength is a negative number: closer to zero is stronger, and around minus 90 is very weak. Hold the sender still at the start, carry the receiver away in steps of about five metres, wait twenty messages at each step and note the loss and signal. Do this in a clear line, then through a wall or two, and try turning the board so its antenna points a different way. Do not carry the equipment across roads while looking at the screen, and stay in places you are allowed to be. The receiver callback uses the newer core 3 form, and a comment shows the older form. Install "Adafruit SSD1306" and "Adafruit GFX" for the screen. A broadcast is open to any board nearby, so this lab is a measuring tool, not a secure link.

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).

// ===== SENDER (upload to board one) =====
#include <WiFi.h>
#include <esp_now.h>

uint8_t broadcastAddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint32_t seq = 0;

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  if (esp_now_init() != ESP_OK) { Serial.println("ESP-NOW failed to start"); return; }
  esp_now_peer_info_t peer = {};
  memcpy(peer.peer_addr, broadcastAddr, 6);
  peer.channel = 0;
  peer.encrypt = false;
  esp_now_add_peer(&peer);
}

void loop() {
  esp_now_send(broadcastAddr, (uint8_t *)&seq, sizeof(seq));   // numbered message
  seq++;
  delay(500);
}

/* ===== RECEIVER (upload to board two, as a separate sketch) =====
   Copy everything below into a new sketch for the second board. */
/*
#include <WiFi.h>
#include <esp_now.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 oled(128, 64, &Wire, -1);

volatile uint32_t lastSeq = 0, startSeq = 0, got = 0;
volatile int rssi = 0;
volatile bool started = false, fresh = false;
unsigned long lastHeard = 0;

// Core 3.x callback. On core 2.x use: void onReceive(const uint8_t *mac, const uint8_t *data, int len)
// and drop the RSSI line, because core 2 does not pass the radio details.
void onReceive(const esp_now_recv_info_t *info, const uint8_t *data, int len) {
  if (len < 4) return;
  uint32_t s;
  memcpy(&s, data, 4);
  if (!started || s < lastSeq) {         // first message, or the sender restarted
    startSeq = s;
    got = 0;
    started = true;
  }
  lastSeq = s;
  got++;
  rssi = info->rx_ctrl->rssi;
  lastHeard = millis();
  fresh = true;
}

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  WiFi.mode(WIFI_STA);
  if (esp_now_init() != ESP_OK) { Serial.println("ESP-NOW failed to start"); return; }
  esp_now_register_recv_cb(onReceive);
  Serial.println("seq,received,lost,rssi");
}

void loop() {
  if (fresh) {
    fresh = false;
    uint32_t expected = lastSeq - startSeq + 1;
    uint32_t lost = expected - got;
    Serial.print(lastSeq); Serial.print(',');
    Serial.print(got); Serial.print(',');
    Serial.print(lost); Serial.print(',');
    Serial.println(rssi);
    oled.clearDisplay();
    oled.setTextSize(1);
    oled.setTextColor(SSD1306_WHITE);
    oled.setCursor(0, 0);  oled.print("Last message: "); oled.print(lastSeq);
    oled.setCursor(0, 14); oled.print("Received: "); oled.print(got);
    oled.setCursor(0, 28); oled.print("Lost: "); oled.print(lost);
    oled.setCursor(0, 42); oled.print("Signal: "); oled.print(rssi); oled.print(" dBm");
    oled.display();
  }
  if (started && millis() - lastHeard > 3000) {
    oled.clearDisplay();
    oled.setCursor(0, 20);
    oled.print("No signal");
    oled.display();
    lastHeard = millis();
  }
  delay(10);
}
*/

Test checklist

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

CheckExpected
Close togetherLost 0, strong signal
Further awaySignal falls and lost grows
Through wallsWorse than the same distance in clear air
Turn the boardThe signal changes
Serial monitorPrints seq, received, lost and rssi

If it does not work

Compile error about rx_ctrl

You are on core 2: use the older callback and drop the RSSI line.

No messages arrive

Both sketches need WiFi.mode(WIFI_STA) before ESP-NOW starts.

Blank screen

Check GPIO 21 and 22 and try address 0x3D.

Lost count jumps at the start

Restart the receiver after the sender is running.

Results vary a lot

Wait for twenty messages at each step and repeat.

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 range and packet loss?

ESP32 DevKit V1 × 2, SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the ESP-NOW range and packet loss take to build?

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

How do I know the ESP-NOW range and packet loss works?

Close together: Lost 0, strong signal. Further away: Signal falls and lost grows. Through walls: Worse than the same distance in clear air.

Compile error about rx_ctrl: what should I check?

You are on core 2: use the older callback and drop the RSSI line.

No messages arrive: what should I check?

Both sketches need WiFi.mode(WIFI_STA) before ESP-NOW starts.

Blank screen: what should I check?

Check GPIO 21 and 22 and try address 0x3D.

Lost count jumps at the start: what should I check?

Restart the receiver after the sender is running.