The problem of entering a 0 value between two different cards while transferring data to a single card with ESP-NOW

Hello, I am working on a project, but when I send the data I receive from the sensors on 2 devices to the receiving card with ESP Now, a zero value is inserted in between. The 1st card sends the value 10, the 2nd card sends 25, the receiving card writes 10 on the screen for the first 1 second, then it returns to 0 and this continues continuously. It repeats, the same happens to the sender with the value 25, but when only one device is active, that is, when 10 senders are working and 25 senders are off, the receiver receives this value of 10 without any problems, there is no zero in between. How can I solve this, I would be glad if you can help me.

transmitter1 code

#include "esp_now.h"
#include "WiFi.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "MAX30100_PulseOximeter.h"

// EKRAN TANIMLAMA
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define REPORTING_PERIOD_MS     2500

//NABIZ SENSÖRÜ TANIMLAMA
PulseOximeter pox;
uint32_t tsLastReport = 0;
int deger1,deger2;
//nabız algılandığında
void onBeatDetected()
{
    Serial.println("Nabız Algılandı.");
}

uint8_t broadcastAddress[] = {0xF4, 0x12, 0xFA, 0xDF, 0x73, 0x6C};  // ALICI kartın MAC adresi


typedef struct struct_message {
  int nabiz;
  int spo;
  int nabiziki;
  int spoiki;
} struct_message;


struct_message myData;


esp_now_peer_info_t peerInfo;


void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  //Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Veri gönderme başarılı" : "Veri gönderme başarısız");
}

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


  if (esp_now_init() != ESP_OK) {
    Serial.println("ESP-NOW başlatılamadı");
    return;
  }


  esp_now_register_send_cb(OnDataSent);


  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;  
  peerInfo.encrypt = false;


  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Eşleşme başarısız");
    return;
  }
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }

    pox.setOnBeatDetectedCallback(onBeatDetected);


}
void loop() {
pox.update();

  if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
    deger1=int(pox.getHeartRate());
    deger2=int(pox.getSpO2());
    display.clearDisplay();
    display.setTextSize(2);      
    display.setTextColor(SSD1306_WHITE); 
    display.setCursor(0,0);     
    display.print("Nabiz:");
    display.setTextSize(1);
    display.setCursor(0,20);     
    display.print("SPO2:");
    display.setTextSize(2);
    display.setCursor(70,0);     
    display.print(int(pox.getHeartRate()));
    display.setTextSize(1);
    display.setCursor(35,20);     
    display.print(int(pox.getSpO2()));
    display.display();
    myData.nabiz=deger1;
    myData.spo=deger2;
    Serial.print(deger1);
    Serial.println(" Nabiz Değeri 1");
    Serial.print(deger2);
    Serial.println(" Spo2 Değeri 1");
        tsLastReport = millis();
    }
      esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
}



transmitter2 code

#include "esp_now.h"
#include "WiFi.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "MAX30100_PulseOximeter.h"

// EKRAN TANIMLAMA
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define REPORTING_PERIOD_MS     2500

//NABIZ SENSÖRÜ TANIMLAMA
PulseOximeter pox;
uint32_t tsLastReport = 0;
int deger1,deger2;
//nabız algılandığında
void onBeatDetected()
{
    Serial.println("Nabız Algılandı.");
}

uint8_t broadcastAddress[] = {0xF4, 0x12, 0xFA, 0xDF, 0x73, 0x6C};  // ALICI kartın MAC adresi


typedef struct struct_message {
  int nabiz;
  int spo;
  int nabiziki;
  int spoiki;
} struct_message;


struct_message myData;


esp_now_peer_info_t peerInfo;


void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  //Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Veri gönderme başarılı" : "Veri gönderme başarısız");
}

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


  if (esp_now_init() != ESP_OK) {
    Serial.println("ESP-NOW başlatılamadı");
    return;
  }


  esp_now_register_send_cb(OnDataSent);


  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;  
  peerInfo.encrypt = false;


  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Eşleşme başarısız");
    return;
  }
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }

    pox.setOnBeatDetectedCallback(onBeatDetected);


}
void loop() {
pox.update();

  if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
    deger1=int(pox.getHeartRate());
    deger2=int(pox.getSpO2());
    display.clearDisplay();
    display.setTextSize(2);      
    display.setTextColor(SSD1306_WHITE); 
    display.setCursor(0,0);     
    display.print("Nabiz:");
    display.setTextSize(1);
    display.setCursor(0,20);     
    display.print("SPO2:");
    display.setTextSize(2);
    display.setCursor(70,0);     
    display.print(int(pox.getHeartRate()));
    display.setTextSize(1);
    display.setCursor(35,20);     
    display.print(int(pox.getSpO2()));
    display.display();
    myData.nabiziki=deger1;
    myData.spoiki=deger2;
    Serial.print(deger1);
    Serial.println(" Nabiz Değeri 1");
    Serial.print(deger2);
    Serial.println(" Spo2 Değeri 1");
        tsLastReport = millis();
    }
      esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
}



receiving code

#include "WiFi.h"
#include "esp_now.h"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

const uint8_t kalp[] PROGMEM = {
// 'kalp', 35x35px
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 
0x01, 0xc0, 0x00, 0x03, 0xfc, 0x07, 0xf0, 0x00, 0x07, 0xff, 0x0f, 0xfc, 0x00, 0x0f, 0xff, 0x3f, 
0xfe, 0x00, 0x0f, 0xff, 0xff, 0xfe, 0x00, 0x1f, 0xff, 0xff, 0xff, 0x00, 0x1f, 0xff, 0xff, 0xff, 
0x00, 0x1f, 0xfb, 0xfb, 0xff, 0x00, 0x1f, 0xf3, 0xf9, 0xff, 0x00, 0x1f, 0xf3, 0xf9, 0xff, 0x00, 
0x0f, 0xf1, 0xb1, 0xfe, 0x00, 0x0f, 0xf5, 0x94, 0xfe, 0x00, 0x07, 0xe5, 0x96, 0xfc, 0x00, 0x00, 
0x0d, 0x86, 0x00, 0x00, 0x01, 0xfc, 0x2f, 0xf0, 0x00, 0x00, 0xfe, 0x7f, 0xe0, 0x00, 0x00, 0x7e, 
0x7f, 0xc0, 0x00, 0x00, 0x3e, 0x7f, 0x80, 0x00, 0x00, 0x1f, 0xff, 0x00, 0x00, 0x00, 0x0f, 0xfe, 
0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x00, 
0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

typedef struct struct_message {
  int nabiz;
  int spo;
  int nabiziki;
  int spoiki;
} struct_message;

struct_message myData;

void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  memcpy(&myData, incomingData, sizeof(myData));
    //neopixelWrite(RGBLED, 100, 0, 0); // Burada neopixel kontrolü yapılıyor
    display.clearDisplay();
    //display.drawBitmap(50, 15, kalp, 35, 35, 1);
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(10, 10);
    display.print(myData.nabiz);
    display.setTextSize(2);
    display.setCursor(10, 40);
    display.print(myData.spo);
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(45, 10);
    display.print(myData.nabiziki);
    display.setTextSize(2);
    display.setCursor(45, 40);
    display.print(myData.spoiki);
    display.display();
    Serial.println("Nabiz2 ");
    Serial.print(myData.nabiz);
    Serial.print("spo2 ");
    Serial.print(myData.spo);
    Serial.print(" ");
    Serial.print("Nabiz2 ");
    Serial.print(myData.nabiziki);
    Serial.print("spo2 ");
    Serial.print(myData.spoiki);
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  WiFi.mode(WIFI_STA);
  
  // OLED ekranı başlatma
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 ekranı başlatılamadı"));
    for(;;);
  }


  if (esp_now_init() != ESP_OK) {
    Serial.println("ESP-NOW başlatılamadı");
    return;
  }
  esp_now_register_recv_cb(OnDataRecv);

}

void loop() {
  // main loop kodu buraya gelebilir
}

card i use
DENEYAP MINI V2 2PCS TRANSMITTER CARDS
DENEYAP 1A V2 1 RECEIVER CARD

Your topic does not indicate a problem with IDE 2.x and hence has been moved to a more suitable location on the forum.

I suggest that you post both tour transmitter and receiver code. Just in case, do not firget to use code tags as described in How to get the best out of this forum.

I have no experience with ESP-Now so can't really advise further.

Ok, thank you, I am adding the codes now, hopefully they will help.

can you post a example of the serial monitor output indicating the problem and what it should be (post as text not a screen image)

18:54:15.705 -> SPO 2 : 95
18:54:17.776 -> Nabiz 1: 0
18:54:17.776 -> SPO : 0
18:54:17.776 -> Nabiz 2: 45
18:54:17.776 -> SPO 2 : 95
18:54:19.755 -> Nabiz 1: 0
18:54:19.755 -> SPO : 0
18:54:19.755 -> Nabiz 2: 0
18:54:19.755 -> SPO 2 : 0
18

Look, there is always a zero between the data.

is that the output of the transmitter or receiver?
if receiver is the transmitter output OK?

can you give links to the modules

recommend you use packed attribute, e.g.

struct __attribute__((packed)) Message {
  int nabiz;
  int spo;
  int nabiziki;
  int spoiki;
} message;

The data of this transmitter transmits them to the receiver, pulse 1 and spo1 are transmitted from transmitter 1, pulse 2 and spo2 are transmitted from transmitter2.

Let me give you the link of the sensors, you have included the code as a package, what exactly does this provide and also some changes are needed after this, the ID gives an error, SENSOR MAX30100

I tried it and the result is the same, zero data is inserted in between.

Hi @efealibozkurt ,

Welcome to the forum..

Not sure where you got that serial output you posted, doesn't match any of the sketches you posted??

quick look at the transmitters, looks like you are broadcasting at loop speed..
kind of fast..
quick look at receiver code, you never check the len passed into the OnDataRecv, maybe len is less than sizeof(myData) sometimes, you are driving very fast??

I'm thinking you're just pushing the envelope here..

good luck.. ~q

Hello, I changed the code of the serial output, so it is different, but I don't quite understand what you mean, I also made the transmission in the loop when the sensor receives data, so the speed decreased, but it still gives zero data from time to time and I couldn't figure it out, I would be very happy if you could help me, Efe Ali Bozkurt

Reading a bit about espnow..

If there is a lot of ESP-NOW data to send, call esp_now_send() to send less than or equal to 250 bytes of data once a time. Note that too short interval between sending two ESP-NOW data may lead to disorder of sending callback function. So, it is recommended that sending the next ESP-NOW data after the sending callback function of the previous sending has returned.

api-reference/network/esp_now

maybe a bool flag that get's reset inside of the sending callback to make sure you don't send too fast..

~q

I would be very happy if you could make an example for me. It would be a good resource for me to understand the durable phenomenon.

If you watch enough Serial Monitor while developing for ESP-Now, you will eventually see a "foreign packet" -- a broadcast from some completely unrelated device. While it may not be your specific issue here, you need to guard against that.

  • check the length of the incoming data
    • if your data is a fixed size, ignore everything that doesn't match
    • definitely don't blindly copy the entire length of the incoming (you don't here) in case it is too long
  • employ some kind of signature or magic number to identify your stuff
  • is the message intended for you?
    • if you register your senders, you can ignore everyone else
    • the recent v3 of arduino-esp32 upgraded from v4 to v5 of ESP-IDF, and that changed the signature of the receive callback so the first argument is a struct that contains both the sender and receiver, so you can ignore broadcasts if you're not expecting them
    • while debugging, print the MAC of the sender

That might also isolate your problem.

Yes, what you say is logical, but the problem is that the 2 transmitters send without any problems, but they conflict with the receiver and the receiver shows 0 data. I need an example code to solve this.

if you have two or more devices which can transmit at any time to a receiver you can get collisions where the signals corrupt each other
one of the simplest ways to avoid collisions is for the receiver to poll each transmitter in turn for data

can you describe your project in more detail WHAT you want to achieve and not so much about how you try it.

So what are your 3 Nodes are doing and what do you want to to synchronize?