Arduino Softwareserial communication with nodemcu

Hi everyone.
I would like to ask you to check my code.

The code is used to communicate arduino nano with nde mcu. Arduino Nano sent every 1 sec a data packet in json format from temperature sensors.

I have a problem with intercepting this data in node mcu.

Please give me some suggestions.

I would be very grateful for help


#define BLYNK_TEMPLATE_ID "xxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxx"




#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SoftwareSerial.h>
#include <ArduinoJson.h>

BlynkTimer timer;


SoftwareSerial nodemcu(D6, D5);



#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);









char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "FunBox2-3335";
char pass[] = "12345678";

float temp_bojler = 0;
float temp_piec = 0;
int tempgora = 0;
int settemp = 0;



#define heater 2 //pin wyjściowy sterowania grzałki
#define pompa_piec 4 //pin wyjściowy sterowania pompy pieca
#define pompa_bojler 0
 boolean piecpali;



BLYNK_WRITE(V5)     // dane z suwaka ustawiajÄ…cego temperaturÄ™


{
  settemp = param.asInt();
}



BLYNK_WRITE(V14)   // dane przychodzÄ…ce z czujnika temperatury na gĂłrze


{
  tempgora = param.asInt();
}



void setup()

{

  pinMode(heater, OUTPUT); // Initialise digital pin 2 as an output pin
  pinMode(pompa_piec, OUTPUT);
  pinMode(pompa_bojler, OUTPUT);
  piecpali = false;

  
  timer.setInterval(1000L, tempcontroll);
  timer.setInterval(1000L, ds18b20);
  timer.setInterval(1000L, event);

  Serial.begin(9600);
  nodemcu.begin(9600);
  
  
  Serial.println("Max6675 test");
  sensors.begin();
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

BLYNK_WRITE(V13) // dane przychodzÄ…ce z przycisku sterujÄ…cego bojlerem
{
  if (param.asInt() == 1)
  {
    // wykonaj to jesli parametr =1
    digitalWrite(heater, LOW); // ustaw port heater na stan LOW

  }
  else
  {
    // wykonaj jesli parametr =0
    digitalWrite(heater, HIGH); // ustaw heater na HIGH


  }
}








BLYNK_WRITE(V7) // Przycisk sterujÄ…cy pompÄ… pieca
{
  if (param.asInt() == 1)
  {
    // wykonaj jesli parametr =1
    digitalWrite(pompa_piec, LOW); // ustaw stan portu pompa_piec na LOW


  }
  else
  {
    // wykonaj jesli parametr = 0
    digitalWrite(pompa_piec, HIGH); // ustaw stan portu pompa_piec na HIGH
  }

}

void tempcontroll() {        //ustawianie temperatury na gĂłrze


  if (settemp >= tempgora)
  {
    digitalWrite(pompa_piec, LOW);
    Serial.println("ON");
    Blynk.virtualWrite(V3, 1);
  }

  else
  {
    digitalWrite(pompa_piec, HIGH);
    Serial.println("OFF");
    Blynk.virtualWrite(V3, 0);
  }


}





void ds18b20()      //mierzenie temperatury bojlera i wody w centralnym

{

  sensors.requestTemperatures();
  // Polls the sensors.
  temp_bojler = sensors.getTempCByIndex(0);// Stores temperature. Change to getTempCByIndex(0) for celcius.
  temp_piec = sensors.getTempCByIndex(1);
  sensors.requestTemperatures();
  Serial.println(temp_piec);
  Serial.println(temp_bojler);
 

}



void event() {      //zdarzenia


  if (temp_piec > 50)
  {
    Blynk.logEvent("temperatura_pieca_50");
  }

  else 
  {


    
  }


}




void loop() {


  if (nodemcu.available()) {
   
   
  StaticJsonBuffer<1000> jsonBuffer;
  JsonObject& data = jsonBuffer.parseObject(nodemcu);
  

 Serial.println("JSON Object Received");
  Serial.println("Temp1");
  float temp1 = data ["temp_spalin1"];
  Blynk.virtualWrite(V15, temp1);
  Serial.println(temp1);
  Serial.println("Temp2");
  float temp2 = data ["temp_spalin2"];
  Blynk.virtualWrite(V16, temp2);
  Serial.println(temp2);
  delay(500);
  }

  
  tempcontroll();
  ds18b20();
  event();


  if (temp_piec > 70)
  { 
    digitalWrite(pompa_bojler, LOW);
    piecpali = true;
  }
  else

  {
    digitalWrite(pompa_bojler, HIGH);
    piecpali = false;
  }


  Blynk.virtualWrite(V0, temp_bojler);         // Send temperature to Blynk app virtual pin 1.
  Blynk.virtualWrite(V1, temp_piec);

  Blynk.run();
  timer.run();

}

@Prospect81 Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard, do not use Blockquotes as you are at the moment.

Pete.

Please let us see your serial monitor.

Thanks

When you post serial output please don’t do it as a screenshot.

Copy the text by either highlighting it with the mouse and using CTRL-C to copy, or use CTRL-A to select all of the text then use CTRL-C to copy.

Paste it into your post with triple backticks at the beginning and end, the same as with code.

I’d suggest clearing your serial monitor then rebooting your device and letting it run for a short while then posting the result. What we see at boot-up is usually more useful than what you’ve shown in your screenshot.

I have to ask why are you using this method of reading data with the Nano then sending it to the NodeMCU?
Why not do everything using the NodeMCU, or if you don’t have enough pins, with an ESP32?

Pete.

The ds18b20 library was in conflict with the thermocouple library. There were also not enough ports to support two thermocouples.

Ae you talking about with a NodeMCU?
If so, why not use an ESP32 instead?

Pete.

I made this project on a nodemcu

And a Nano.
Why the two devices? It makes life so difficult for you.
Why not one single device, like an ESP32?

Pete.

1 Like

I couldn’t build code to support two sensors based on max6675 and ds18b20 library.

Well I think that’s the issue you should be addressing, not trying to transfer data from a Nano to a NodeMCU via serial.

Pete.

Ok, thanks Pete.