Esp Now 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 before, transmitter power on,
the output pins of receiver go LOW and relays switch on,
but it go HIGH when transmitter power on.
I need to set the output pins of receiver to HIGH by default (when power on)
and before the transmitter power on.
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));
 digitalWrite(LED_Pin1, receive_Data.led1);
  digitalWrite(LED_Pin2, receive_Data.led2);
  Serial.print("Receive Data: ");
  Serial.println("<<<<<");
}
void setup(){
  Serial.begin(115200);
  pinMode(LED_Pin1, OUTPUT);
  pinMode(LED_Pin2, OUTPUT);
  WiFi.mode(WIFI_STA); //--> Set device as a Wi-Fi Station
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  esp_now_register_recv_cb(OnDataRecv);
}
void loop()
{} 

Welcome to the forum

What have you tried ?
Presumably you know how to use digitalWrite()

1 Like

Thank you very much, its OK.

Please post your revised sketch showing how you solved it so that future users see how it was done

the solution by use digitalWrite() function( digitalWrite(LED_Pin1, HIGH); digitalWrite(LED_Pin2, HIGH); in void setup() function to set output pins HIGH at power on.


#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));
 digitalWrite(LED_Pin1, receive_Data.led1);
  digitalWrite(LED_Pin2, receive_Data.led2);
}
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); //--> Set device as a Wi-Fi Station
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  esp_now_register_recv_cb(OnDataRecv); //--> Register for a callback function that will be called when data is received
}
void loop(){}

It looks like you got my hint in post #2 :grinning:

Good luck with your project

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