Esp_now wi fi receiver problem

Hi,
I'm using esp_now(transmitter & receiver) to switch relays on/off ( relays on at LOW signal)
the problem is when power on receiver circuit ,esp32 and relay module at the same time,(relay module connected to +ve & -ve pins of esp32), there's no signal at receiver and showing error (invalid header) in serial monitor , but when power on esp32 first then connect relay module terminal to +ve & -ve pins ,it is working right .I need to solve this problem(power on all circuit at the same time.
many thanks for helping.
the code of receiver

#include <esp_now.h>
#include <WiFi.h>
#define LED_Pin1   4
#define LED_Pin2   12
typedef struct struct_message {
    int led1;
    int led2;
} struct_message ;
struct_message receive_Data; // Create a struct_message to receive data.
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  memcpy(&receive_Data, incomingData, sizeof(receive_Data));
  Serial.println();
  Serial.println("<<<<< Receive Data:");
  Serial.print("Bytes received: ");
  Serial.println(len);
 digitalWrite(LED_Pin1, receive_Data.led1);
  digitalWrite(LED_Pin2, receive_Data.led2);
  Serial.println("<<<<<"); 
}
void setup(){
  Serial.begin(115200);
       digitalWrite(LED_Pin1, HIGH);
   digitalWrite(LED_Pin2, HIGH);
  pinMode(LED_Pin1, OUTPUT);
  pinMode(LED_Pin2, 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(){}

Please post a hardware schematic.

Actually you need to first, determine if the problem is power sequencing or your code. Can you add a push button switch to you ESP_now and at the beginning of setup() add a loop to continually test the switch to see if it pressed? Make all the power tests you just described, and press the switch to begin you code for each test.

Perhaps there is something requiring a specific order of starting.

Hi,
Thank you to every one helping me to solve the problem

I think the problem in gpio 12 (but i dont why), because when i change by other gpio the circuit works perfectly w/o errors. I use TTGO ESP32-WROVER-B T8 V1.8.

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