ESP32 Serial communication issue

Hello

I'm trying to build a project there is one ESP32 collecting data from some different sensors and mcus through ESP-NOW

then I want to send the collected data to another esp32 which will send it via wifi to webserver

the issue is the serial comm. while testing is really slow and it dropped readings

I monitor the data like in attachment

and here are the sender and receiver code :

// Sending/Receiving example

HardwareSerial Sender(2);   // Define a Serial port instance called 'Sender' using serial port 1

#define Sender_Txd_pin 17
#define Sender_Rxd_pin 16

void setup() {
  //Serial.begin(Baud Rate, Data Protocol, Txd pin, Rxd pin);
  Serial.begin(115200);                                             // Define and start serial monitor
  Sender.begin(115200, SERIAL_8N1, Sender_Txd_pin, Sender_Rxd_pin); // Define and start Sender serial port
}

int i = 0;
void loop() {
  float sensor_temperature = i++;                               // Set an example value
  Serial.print("Sending ....: ");
  Serial.println(sensor_temperature);
  Sender.print(sensor_temperature);                                // Send it to Sender serial port
  delay(1000);
}
// Sending/Receiving example

HardwareSerial Receiver(2); // Define a Serial port instance called 'Receiver' using serial port 2

#define Receiver_Txd_pin 17
#define Receiver_Rxd_pin 16

void setup() {
  //Serial.begin(Baud Rate, Data Protocol, Txd pin, Rxd pin);
  Serial.begin(115200);                                                   // Define and start serial monitor
  Receiver.begin(115200, SERIAL_8N1, Receiver_Txd_pin, Receiver_Rxd_pin); // Define and start Receiver serial port
}

void loop() {
 while (Receiver.available()) {                         // Wait for the Receiver to get the characters
    float received_temperature = Receiver.parseFloat(); // Display the Receivers characters
    Serial.println(received_temperature);               // Display the result on the serial monitor
  };
  delay(500);
}

You should read about the serial thing on a post on this site.

Basically you have one ESP32 sending stuff and another esp32 getting stuff but in a 'blind' way.

Consider sending a sentence instead.

Such as this "<" could be the beginning of a sentence.
This ">" could be the end of your sentence.

So you data stream could look like <235867674.939485767>.

If you receive a "< then start collecting serial data.
If you receive a ">" then the end of the serial data has been reached.
Your parser then can determine the exact sentence sent and not catch partial sentences.

Take a look at Serial input basics - updated

An example of receiving and assembling received serial sentences for an ESP32

void fReceiveSerial_LIDAR( void * parameters  )
{
  bool BeginSentence = false;
  char OneChar;
  char *str;
  str = (char *)ps_calloc(300, sizeof(char) ); // put str buffer into PSRAM
  // log_i("Free PSRAM before String: %d", ESP.getFreePsram());
  for ( ;; )
  {
    EventBits_t xbit = xEventGroupWaitBits (eg, evtReceiveSerial_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY);
    if ( LIDARSerial.available() >= 1 )
    {
      while ( LIDARSerial.available() )
      {
        OneChar = LIDARSerial.read();
        if ( BeginSentence )
        {
          if ( OneChar == '>')
          {
            if ( xSemaphoreTake( sema_ParseLIDAR_ReceivedSerial, xSemaphoreTicksToWait10 ) == pdTRUE )
            {
               xQueueOverwrite( xQ_LIDAR_Display_INFO, ( void * ) &str );
              xEventGroupSetBits( eg, evtParseLIDAR_ReceivedSerial );
              //
            }
            BeginSentence = false;
            break;
          }
          strncat( str, &OneChar, 1 );
        }
        else
        {
          if ( OneChar == '<' )
          {
            strcpy( str, ""); // clear string buffer
            BeginSentence = true; // found beginning of sentence
          }
        }
      } //  while ( LIDARSerial.available() )
    } //if ( LIDARSerial.available() >= 1 )
    xSemaphoreGive( sema_ReceiveSerial_LIDAR );
    //        log_i( "fReceiveSerial_LIDAR " );
    //        log_i(uxTaskGetStackHighWaterMark( NULL ));
  }
  free(str);
  vTaskDelete( NULL );
} //void fParseSerial( void * parameters  )

The above code does not parse the serial received.

Thank you for your help

You are wlcome.