08/01/19 - Two-way Communication, first attempt failed

A project log for My attempt at an ESP-NOW Mesh

Designing a custom mesh for sensors, home automation and remote controlling using Espressif's ESP-NOW

david-mDavid M. 08/01/2019 at 19:490 Comments

To begin developing two-way communication, I will began with the example sketches. I have tried combining both Master and Slave example sketches into one but failed. To help me resolve this issue, I have reached out for help on Arduino and Espressif forums. While I wait for answers, I decided to explore more closely the advantages and disadvantages of using a pre-built mesh library, like Painless Mesh or ESP-MDF. Here's a snippet of code which I tried to use, but failed:

void setup()
  // configure device AP mode
  // This is the mac address of the Slave in AP Mode
  Serial.print("AP MAC: ");
  Serial.print("STA MAC: ");
  // Init ESPNow with a fallback logic
  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info.

unsigned long nextManage;

void loop() 
  // In the loop we scan for slave
  // If Slave is found, it would be populate in `slave` variable
  // We will check if `slave` is defined and then we proceed further
  if ( == CHANNEL2)
  { // check if slave channel is defined
    // `slave` is defined
    // Add slave as peer if it has not been added already
    bool isPaired = manageSlave();
    nextManage = millis() + 10000;
    while (isPaired)
      if (packetRecieved)
        packetRecieved = false;
        // Send data to device

      unsigned long t = millis();
      if (t > nextManage)
        nextManage = t + 10000;
        // pair success or already paired
        isPaired = manageSlave();
    Serial.println("Slave pair failed!");
Fig. 23 - My first, failed attempt at a two-way ESP-NOW communication sketch.