#define BLYNK_TEMPLATE_ID "TMPL3vsr78rfR"
#define BLYNK_TEMPLATE_NAME "IIoT"
char auth[] = "aOAkDsg5kI_6R-SgE7xxrayVn2wMrjtg"; // Your Blynk Auth Token
#include<BlynkSimpleEsp32.h>
#define RX 16
#define TX 17
#define LED_PIN 2 // LED pin
#define Btemp V0
#define Bpot V1
#define Bhum V2
#define Bled V3
// Variable to store LED state
bool ledState = false;
void setup() {
Serial.begin(9600);
Blynk.begin(auth, "Wokwi-GUEST", "");
// Serial2.begin(9600, SERIAL_8N1, RX, TX); // RX on GPIO 16, TX on GPIO 17
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
Serial.println("Initializing...");
delay(1000);
}
void loop() {
Blynk.run();
// if (Serial2.available()) {
// String data = Serial2.readStringUntil('\n'); // Read until newline
// Serial.println(data); // Print to Serial Monitor
// // Check for "Pot:", "Temp:", and "hum:" prefixes
// if (data.startsWith("Pot:"))
// {
// String potValue = data.substring(4); // Get the value after "Pot:"
// Blynk.virtualWrite(Bpot, potValue.toInt()); // Update Blynk with potentiometer value
// }
// else if (data.startsWith("Temp:"))
// {
// String tempValue = data.substring(5); // Get the value after "Temp:"
// Blynk.virtualWrite(Btemp, tempValue.toInt()); // Update Blynk with temperature value
// }
// else if (data.startsWith("hum:"))
// {
// String humidityValue = data.substring(4); // Get the value after "hum:"
// Blynk.virtualWrite(Bhum, humidityValue.toFloat()); // Update Blynk with humidity value
// }
// }
if (Serial.available()) {
String data = Serial.readStringUntil('\n'); // Read until newline
// Check for "Pot:", "Temp:", and "hum:" prefixes
if (data.startsWith("Pot:"))
{
String potValue = data.substring(4); // Get the value after "Pot:"
int pot = potValue.toInt();
Blynk.virtualWrite(Bpot, pot); // Update Blynk with potentiometer value
}
else if (data.startsWith("Temp:"))
{
String tempValue = data.substring(5); // Get the value after "Temp:"
int temp = tempValue.toInt();
Blynk.virtualWrite(Btemp, temp); // Update Blynk with temperature value
}
else if (data.startsWith("hum:"))
{
String humidityValue = data.substring(4); // Get the value after "hum:"
int hum = humidityValue.toInt();
Blynk.virtualWrite(Bhum, hum); // Update Blynk with humidity value
}
}
digitalWrite(LED_PIN, ledState ? HIGH : LOW);
}
// Blynk function to receive switch state
BLYNK_WRITE(Bled) {
ledState = param.asInt(); // Get the value from the switch
}