Can I connect two esp8266 on one project

I have two esp8266 wherein each has their own sensor attached. I created a monitoring device wherein the two of them are connected in one blynk template. My issue is that I have the same credentials and only changed V0,V1,V2 and V3 these are the only changes in my code. Why is it that only 1 works while the other is not sending the data to the blynk app? tyia.
1st mcu code

#define BLYNK_TEMPLATE_ID "TMPL64qpH6bPb"
#define BLYNK_TEMPLATE_NAME "mq137"
#define BLYNK_AUTH_TOKEN "zeFfyjNsRBwxi2LXwTTR2ZQ2njAa9F8p"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleEsp8266.h>

// Blynk credentials and Wi-Fi credentials
char auth[] = "zeFfyjNsRBwxi2LXwTTR2ZQ2njAa9F8p"; // Replace with your Blynk Auth Token
char ssid[] = "qwe"; // Replace with your Wi-Fi SSID NadelaWifi , qwe
char pass[] = "nayeonnnie"; // Replace with your Wi-Fi Password s$AaaY__MMmYy___N@M3!!!, nayeonnnie

SoftwareSerial nodemcuSerial(D7, D8); // RX, TX pins on NodeMCU

BlynkTimer timer;

void sendDataToBlynk(float ammoniaPpm, float co2Ppm) {
  Blynk.virtualWrite(V0, ammoniaPpm); // Send the ammonia ppm value to V0 in Blynk
  Blynk.virtualWrite(V1, co2Ppm); // Send the CO2 ppm value to V1 in Blynk
}

void readSerialData() {
  while (nodemcuSerial.available()) {
    String data = nodemcuSerial.readStringUntil('\n');
    int separatorIndex = data.indexOf(',');
    if (separatorIndex != -1) {
      String ammoniaStr = data.substring(0, separatorIndex);
      String co2Str = data.substring(separatorIndex + 1);

      float ammoniaPpm = ammoniaStr.toFloat();
      float co2Ppm = co2Str.toFloat();

      sendDataToBlynk(ammoniaPpm, co2Ppm); // Send data to Blynk

      Serial.print("Received Ammonia: ");
      Serial.print(ammoniaPpm);
      Serial.print(" ppm, CO2: ");
      Serial.println(co2Ppm);
      Serial.println(" ppm");
    }
  }
}

void setup() {
  Serial.begin(115200); // Initialize Serial for debugging
  Blynk.begin(auth, ssid, pass); // Initialize Blynk
  nodemcuSerial.begin(115200); // Initialize SoftwareSerial

  timer.setInterval(1000L, readSerialData); // Set up a timer to read data
}

void loop() {
  Blynk.run(); // Run Blynk
  timer.run(); // Run the timer
}

2nd mcu code

#define BLYNK_TEMPLATE_ID "TMPL64qpH6bPb"
#define BLYNK_TEMPLATE_NAME "mq137"
#define BLYNK_AUTH_TOKEN "zeFfyjNsRBwxi2LXwTTR2ZQ2njAa9F8p"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleEsp8266.h>

// Blynk credentials and Wi-Fi credentials
char auth[] = "zeFfyjNsRBwxi2LXwTTR2ZQ2njAa9F8p"; // Replace with your Blynk Auth Token
char ssid[] = "qwe"; // Replace with your Wi-Fi SSID NadelaWifi , qwe
char pass[] = "nayeonnnie"; // Replace with your Wi-Fi Password s$AaaY__MMmYy___N@M3!!!, nayeonnnie

SoftwareSerial nodemcuSerial(D7, D8); // RX, TX pins on NodeMCU

BlynkTimer timer;

void sendDataToBlynk(float ammoniaPpm, float co2Ppm) {
  Blynk.virtualWrite(V2, ammoniaPpm); // Send the ammonia ppm value to V0 in Blynk
  Blynk.virtualWrite(V3, co2Ppm); // Send the CO2 ppm value to V1 in Blynk
}

void readSerialData() {
  while (nodemcuSerial.available()) {
    String data = nodemcuSerial.readStringUntil('\n');
    int separatorIndex = data.indexOf(',');
    if (separatorIndex != -1) {
      String ammoniaStr = data.substring(0, separatorIndex);
      String co2Str = data.substring(separatorIndex + 1);

      float ammoniaPpm = ammoniaStr.toFloat();
      float co2Ppm = co2Str.toFloat();

      sendDataToBlynk(ammoniaPpm, co2Ppm); // Send data to Blynk

      Serial.print("Received Ammonia: ");
      Serial.print(ammoniaPpm);
      Serial.print(" ppm, CO2: ");
      Serial.println(co2Ppm);
      Serial.println(" ppm");
    }
  }
}

void setup() {
  Serial.begin(115200); // Initialize Serial for debugging
  Blynk.begin(auth, ssid, pass); // Initialize Blynk
  nodemcuSerial.begin(115200); // Initialize SoftwareSerial

  timer.setInterval(1000L, readSerialData); // Set up a timer to read data
}

void loop() {
  Blynk.run(); // Run Blynk
  timer.run(); // Run the timer
}

Each device needs its own unique Auth token.
If you have multiple devices sharing the same Auth token then when the second device connects to the Blynk server the server will disconnect the first device.

You need to create a second device, which uses the same template, which will give you a second Auth token.

Pete.

1 Like

Oh okay sir I understand. Thanks


From what I understand from the pic if i have 1 sensor connected to each nodemcu only 1 will work right? I need to create another template so that my project will work?

Incorrect.
Both devices will appear in your devices list, and if they are both based on the same template then they will both share the same dashboard layout.
When you view device A the dashboard for device A will display data from device A.
Switching to device B will show device B data.

If you need data from both devices in the same dashboard then you’ll need to send data from one device to another, using either Automations or the HTTP(S) API.

Pete.

Ahhh I see sir. thanks for the help as always