Blynk ไม่แสดงค่าเลยครับ
#define BLYNK_TEMPLATE_ID "TMPL6smioabU_"
#define BLYNK_TEMPLATE_NAME "testesp32"
#define BLYNK_AUTH_TOKEN "zg2vIwQfznV4d2-uQFTKUiiImjga23mp"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define RX2 16
#define TX2 17
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <PZEM004Tv30.h>
#include <HardwareSerial.h>
PZEM004Tv30 pzem(&Serial2);
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "sirimaporn10_2G";
char pass[] = "09052545p";
BlynkTimer timer;
void setup()
{
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RX2, TX2);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
timer.run();
float voltage = pzem.voltage();
if (voltage != NAN) {
Serial.print("Voltage: "); Serial.print(voltage); Serial.println("V");
} else {
Serial.println("Error reading voltage");
Blynk.virtualWrite(V0,voltage);
}
float current = pzem.current();
if (current != NAN) {
Serial.print("Current: "); Serial.print(current); Serial.println("A");
} else {
Serial.println("Error reading current");
Blynk.virtualWrite(V1, current);
}
float power = pzem.power();
if (current != NAN) {
Serial.print("Power: "); Serial.print(power); Serial.println("W");
} else {
Serial.println("Error reading power");
Blynk.virtualWrite(V2, power);
}
float energy = pzem.energy();
if (current != NAN) {
Serial.print("Energy: "); Serial.print(energy, 3); Serial.println("kWh");
} else {
Serial.println("Error reading energy");
Blynk.virtualWrite(V4, energy);
}
float frequency = pzem.frequency();
if (current != NAN) {
Serial.print("Frequency: "); Serial.print(frequency, 1); Serial.println("Hz");
} else {
Serial.println("Error reading frequency");
Blynk.virtualWrite(V5, frequency);
}
float pf = pzem.pf();
if (current != NAN) {
Serial.print("PF: "); Serial.println(pf);
} else {
Serial.println("Error reading power factor");
Blynk.virtualWrite(V6, pf);
}
Serial.println();
delay(1500);
}