I've been searching for hours for a simple (yes, simple) ESP serial communication. Haven't found anythink
But: i must send a char from the first ESP, to the second ESP. So, only one way sending (no need to send anythink back). One has to send only, and the second has to receive only.
The char which has to be sended, don't have a certain length. So: it could be 3 letters, but also 20 letters.
The most common way to do what you want,is to use Serial.print,or Serial.write to,transmit the text block.
You would either want to set up a protocol to indicate how much text is being sent, or if it’s plain text, a simple CR to terminate each message.
On the receiving end, monitor Serial.available until something arrived,mths readvcharacters until you protocol is satisfied,it uoufind a terminator (e,g, CR), then process the message, and start over again looking for another complete message.
// ESP8266 SoftwareSerial
// https://circuits4you.com/2016/12/14/software-serial-esp8266/
#include <SoftwareSerial.h>
// pins Rx GPIO14 (D5) and Tx GPIO 12 (D6)
SoftwareSerial swSer(D5, D6);//14, 12);
void setup() {
Serial.begin(115200); //Initialize hardware serial with baudrate of 115200
swSer.begin(9600); //Initialize software serial with baudrate of 115200
Serial.println("\nESP8266 Software serial test started");
}
void loop() {
while (swSer.available() > 0) { //wait for data at software serial
Serial.write(swSer.read()); //Send data recived from software serial to hardware serial
}
while (Serial.available() > 0) { //wait for data at hardware serial
swSer.write(Serial.read()); //send data recived from hardware serial to software serial
}
}