I'm working on communicating between the two NodeMCU basing on the serial communication protocol. I've used SoftwareSerial and ArduinoJson library for my program according to some sources on the Internet. The problem is at the stability of the reading value from Serial. As far as what I saw on the COM monitor, it was either lack of data or appeared some odd letter. I want the two Node to be able to send and receive data from each other but the instability has stopped me in the first direction. Anyone's help will be appreciated. I'm trying to apply UART because of its simplicity and speed but the suggestion of another solution with other protocols would be great. The code of the transmitting node and the receiving node was attached below:
The sending program
#include <ArduinoJson.h>
SoftwareSerial s(D5,D6);
byte C1;
void setup() {
pinMode(D0,OUTPUT);
s.begin(115200);
}
void loop() {
//Sending code
StaticJsonBuffer<1000> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["Temp"] = 100;
if(s.available()>0)
{
root.printTo(s);
}
The receiving program
#include <SoftwareSerial.h>
SoftwareSerial s(D6,D5);
#include <ArduinoJson.h>
void setup() {
// Initialize Serial port
Serial.begin(115200);
pinMode(D0,OUTPUT);
s.begin(115200);
while (!Serial) continue;
}
void loop() {
//Receiving code
StaticJsonBuffer<1000> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(s);
if (root == JsonObject::invalid())
return;
root.prettyPrintTo(Serial);
Serial.print("Data 1 ");
Serial.println("");
int data1=root["Temp"];
if(data1==100)
digitalWrite(D0,HIGH);
else
digitalWrite(D0,LOW);
delay(100);
}