esp code :
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_TEMPLATE_ID "TM*******c"
#define BLYNK_TEMPLATE_NAME "***********"
#define BLYNK_AUTH_TOKEN "*************"
const char* ssid = "D-Link";
const char* password = "********";
char auth[] = "********g";
BlynkTimer timer;
void setup() {
Serial.begin(9600); // Start serial communication
delay(1000); // Delay to let the serial settle
Serial.println("Starting...");
// Connect to WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
// Initialize Blynk
Blynk.begin(auth, ssid, password);
Serial.println("Blynk initialized");
// Setup a function to send data to Blynk every second
timer.setInterval(1000L, sendSensorData);
}
void loop() {
Blynk.run(); // Run Blynk
timer.run(); // Run the timer
}
void sendSensorData() {
if (Serial.available() > 0) {
String data = Serial.readStringUntil('\n');
Serial.println("Received data: " + data);
// Split the data into separate values
int colonIndex = data.indexOf(':');
if (colonIndex != -1) {
String dataType = data.substring(0, colonIndex);
String sensorValueStr = data.substring(colonIndex + 1);
float sensorValue = sensorValueStr.toFloat();
// Send the sensor value to the corresponding virtual pin on Blynk
if (dataType == "D") {
Blynk.virtualWrite(V0, sensorValue); // Distance
} else if (dataType == "AQ") {
Blynk.virtualWrite(V1, sensorValue); // Air Quality
} else if (dataType == "WL") {
Blynk.virtualWrite(V2, sensorValue); // Water Level
} else if (dataType == "FD") {
Blynk.virtualWrite(V3, sensorValue); // Flame Detected
} else if (dataType == "LI") {
Blynk.virtualWrite(V4, sensorValue); // Light Intensity
} else if (dataType == "T") {
Blynk.virtualWrite(V5, sensorValue); // Temperature
} else if (dataType == "H") {
Blynk.virtualWrite(V6, sensorValue); // Humidity
}
}
}
}
@haitembbs 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.
I would also recommend that you edit the title of your topic to make it much shorter, and spend some time explaining within your post what your issue/question is.
Pete.
What exactly is your question?
Also, why are you doing this…
Pete.