ESPNOW with light sleep mode not working

Hello, I am using a ESP32 to tell another ESP32 via ESPNOW to turn on it's built-in LED. I need to put the first ESP32 into light sleep mode to conserve battery life. I put the wakeup cause for the first ESP32 to wakeup when one of its built-in touch-pins are pressed. I then put it into light sleep mode. I also turned off the wifi before I put it into light sleep mode and on after it woke up from light sleep mode. When I uploaded the code, the LED of the second ESP32 would not turn on. Here is my code...

Code for first ESP32:

#include <Arduino.h>
#include <WiFi.h>
#include <esp_now.h>
#include <esp_wifi.h>

uint8_t addressB2[] = {0xEC, 0x94, 0xCB, 0x4C, 0x76, 0x18};

touch_pad_t touchPin;
void callback() {}

void setup()
{
    Serial.begin(115200);
    WiFi.mode(WIFI_STA);

    if (esp_now_init() != ESP_OK)
    {
        Serial.println("Error initializing ESP-NOW");
        return;
    }

    esp_now_peer_info_t peerInfo;
    memcpy(peerInfo.peer_addr, addressB2, 6);
    peerInfo.channel = 0;  
    peerInfo.encrypt = false;
  
    if(esp_now_add_peer(&peerInfo) != ESP_OK)
    {
        Serial.println("Failed to add peer");
        return;
    }
}

void loop()
{
    esp_wifi_stop();
    touchAttachInterrupt(15, callback, 70);
    esp_sleep_enable_touchpad_wakeup();
    esp_light_sleep_start();

    touchPin = esp_sleep_get_touchpad_wakeup_status();
    int touch = 0;

    if(touchPin == 3)
    {
        touch = 1;
    }

    else
    {   
        touch = 0;
    }

    esp_wifi_start();
    esp_now_send(addressB2, (uint8_t*) &touch, sizeof(touch));
}

Code for second ESP32:

#include <Arduino.h>
#include <WiFi.h>
#include <esp_now.h>

uint8_t addressB1[] = {0xEC, 0x94, 0xCB, 0x4C, 0xB2, 0xF0};

void OnDataRecv(const uint8_t * mac, const uint8_t *data, int len)
{
    int * messagePointer = (int*)data;

    if(*messagePointer == 1) { Serial.println("Touched"); digitalWrite(2, HIGH); delay(1000); }
    else { Serial.println("Not Touched"); digitalWrite(2, LOW); }
}

void setup()
{
    Serial.begin(115200);
    pinMode(2, OUTPUT);
    WiFi.mode(WIFI_STA);

    if (esp_now_init() != ESP_OK)
    {
        Serial.println("Error initializing ESP-NOW");
        return;
    }

    esp_now_register_recv_cb(OnDataRecv);
}

void loop()
{
    
}

Any advice for how to use ESPNOW and put it into light sleep mode too? Thanks in advance.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.