saving Nodemcu Serial.read() values to mysql database

Hello All,

My task is I have to send Serial data available in Arduino Mega (serial1 port) to Nodemcu (serial). Then from Nodemcu to MySql based database

Arduino Mega Code

String str;
 void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(115200);
Serial1.begin(115200);
 }

void loop() {
   int sensorValue = analogRead(A0);
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.println(voltage);

  str =String(voltage);
  Serial.println(str);
  Serial1.println(str);
delay(1000);
}

Nodemcu Code

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

String readString;

const char* ssid     = "xxx";
const char* password = "xxxx";

const char* host= "xxxxx";
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
      delay(500);
      Serial.print(".");
    }
    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    Serial.print("Netmask: ");
    Serial.println(WiFi.subnetMask());
    Serial.print("Gateway: ");
    Serial.println(WiFi.gatewayIP());
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}

void loop() { // run over and over
  Serread();
  postdata2();
}




void Serread(){
  while (Serial.available()) {
    delay(2);
    char c = Serial.write(Serial.read());  //gets one byte from serial buffer
    readString += c; //makes the String readString
    // delay(2); //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String
    readString="";
   
  }
}



void postdata2(){

  

 
   HTTPClient http;    //Declare object of class HTTPClient
   String url = "xxxxx"; ////Post url, now it is just url ,have to make it secure//
   
   

   http.begin(url);      //Specify request destination and start sending //
   http.addHeader("Content-Type", "text/plain");  //Specify content-type header // here we can give json also have to test it //
 
   int httpCode = http.POST("Message from ESP8266");   //Send the request
   String payload = http.getString();                  //Get the response payload, which we custom made in php to get a response//
 
   Serial.println(httpCode);   //Print HTTP return code anything not 200 is an error //
   Serial.println(payload);  
   Serial.println(readString);  
   Serial.print("url:");
   Serial.println(url);//Print request response payload //
 
   http.end();  //Close connection//
   delay(2000);
}

But when I observe in serial monitor,readString in Void postcode2 section is not getting printed in Serial monitor…

CAn anybody help me to resolve this

Why are you casting the voltage to a String before sending it ?

Take a look at Serial input basics - updated for ideas on how to sensibly transfer data over a s serial link