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
}