As explained by goddland_16. Using Software Serial library will solve the issue. Code is given below. By Initializing other digital pin as communication pin, Interupption between Tx and Rx and to ESP8266 is seperated.
Arduino UNO / Nano Code :
/*
* bismillah hir rahman nir raheem
* UNO/Nano = Pin 7 & Pin 8
* Note: Uno and ESP8266 cross connection
*/
#include <SoftwareSerial.h>
SoftwareSerial ArduinoUno(7,8);
String f;
void setup() {
Serial.begin(9600);
ArduinoUno.begin(115200);
}
void loop() {
float i = (random(100) + 1);
float j = (random(100) + 1);
f = String('H') + String(i) + String('T') + String(j);
ArduinoUno.println(f);
delay(2000);
}
ESP8266 Code :
/*
* bismillah hir rahman nir raheem
* ESP8266 = Pin D7 & Pin D8
* Note: Uno and ESP8266 cross connection
*/
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
SoftwareSerial NodeMCU(D7,D8);
void setup() {
Serial.begin(9600);
NodeMCU.begin(115200);
pinMode(D7,INPUT);
pinMode(D8,OUTPUT);
}
void loop() {
String content = "";
char character;
while (NodeMCU.available()) {
character = NodeMCU.read();
content.concat(character);
}
if (content != "") {
Serial.println(content);
}
Serial.println("Temperature");
Serial.println(content.substring(1, 6));
Serial.println("Humidity");
Serial.println(content.substring(7, 12));
delay(2000);
}