Hello,
I have a problem when I used blynk(the old version) last night. Before last night, at noon, I can measure every data and show it in every graph. But when I change the device to measure the data, it just like the blynk has stopped working, just like it didn’t accept any information (in the superchart)
P.S. I’m only Thai student, doing the project and running the code as given by teacher, so I don’t exactly know how to fix the code though and sorry for my bad English grammar at all.
P.S.2 here is the code and the photo of the blynk when measure the device in the other time period section. ( The live section can work normally)
Thank you for your help.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Time.h>
#include <PZEM004Tv30.h>
#include <SoftwareSerial.h>
#include "DHT.h"
#define DHTPIN D2
#define DHTTYPE DHT22
#if defined(ESP32)
#error "Software Serial is not supported on the ESP32"
#endif
#if !defined(PZEM_RX_PIN) && !defined(PZEM_TX_PIN)
#define PZEM_RX_PIN D3
#define PZEM_TX_PIN D4
#endif
SoftwareSerial pzemSWSerial(PZEM_RX_PIN, PZEM_TX_PIN);
PZEM004Tv30 pzem(pzemSWSerial);
DHT dht(DHTPIN, DHTTYPE);
WiFiClient client;
WiFiServer server(80);
int timezone = 7 * 3600; // ตั้งค่า timezone
int dst = 0; // ตั้งค่า daylight saving time
int SignalStrength;
String DAY;
String DATE1,DATE2;
String TIME;
float V,I,P,E,f,PF;
String weekDays[7] ={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
String months[12] ={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
String sec[60] ={"00", "01", "02", "03", "04", "05", "06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"};
String mini[60] ={"00", "01", "02", "03", "04", "05", "06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"};
String hou[24] ={"00", "01", "02", "03", "04", "05", "06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"};
String myIP;
float h,t;
char ssid[] = "ruethai2518";
char pass[] = "stang3012";
char auth[] = "jAVk6afL321RcB3wDPHBrkvh0Fyi7cGd";
void setup()
{
Serial.begin(115200);
dht.begin();
Serial.println();
WiFi.mode(WIFI_STA);
WiFi.begin("ruethai2518","stang3012"); // ต้องใส่ชื่อ wifi และ password
while (WiFi.status() != WL_CONNECTED) //รอจนกว่าจะเชื่อมต่อสำเร็จ
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.print("Server IP Address : ");
myIP = ipToString( WiFi.localIP() );
Serial.println( WiFi.localIP());
configTime(timezone, dst, "pool.ntp.org", "time.nist.gov"); // ดึงเวลาจากserver
Blynk.begin(auth, ssid, pass, "oasiskit.com",8080);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("Connecting To : ");
Serial.println(WiFi.SSID());
Serial.print("IP Address : ");
Serial.println(myIP);
Serial.print("Signal Strength : ");
Serial.print(WiFi.RSSI());
Serial.println(" dBm");
time_t now;
time(&now);
struct tm *p_tm = localtime(&now);
TIME = String(hou[(p_tm->tm_hour)]) + ":" + String(mini[(p_tm->tm_min)]) + ":" + String(sec[(p_tm->tm_sec)]);
DATE1 = String(p_tm->tm_mday) + "/" + String((p_tm->tm_mon)+1) + "/" + String(p_tm->tm_year+1900);
DATE2 = String(p_tm->tm_mday) + " " + String(months[(p_tm->tm_mon)]) + " " + String(p_tm->tm_year+1900);
Serial.print("Date : ");
Serial.println(DATE1);
Serial.print("Date : ");
Serial.println(DATE2);
Serial.print("Day : ");
DAY = weekDays[(p_tm->tm_wday)];
Serial.println(DAY);
Serial.print("Time : ");
Serial.println(TIME);
Serial.print("Humidity : ");
Serial.println(h);
Serial.print("Temperature : ");
Serial.println(t);
Serial.println();
Web();
Serial.print("Custom Address:");
Serial.println(pzem.readAddress(), HEX);
// Read the data from the sensor
float V = pzem.voltage();
float I = pzem.current();
float P = pzem.power();
float E = pzem.energy();
float f = pzem.frequency();
float PF = pzem.pf();
// Check if the data is valid
if(isnan(V)){
Serial.println("Error reading voltage");
} else if (isnan(I)) {
Serial.println("Error reading current");
} else if (isnan(P)) {
Serial.println("Error reading power");
} else if (isnan(E)) {
Serial.println("Error reading energy");
} else if (isnan(f)) {
Serial.println("Error reading frequency");
} else if (isnan(PF)) {
Serial.println("Error reading power factor");
} else {
// Print the values to the Serial console
Serial.print("Voltage: "); Serial.print(V); Serial.println("V");
Serial.print("Current: "); Serial.print(I); Serial.println("A");
Serial.print("Power: "); Serial.print(P); Serial.println("W");
Serial.print("Energy: "); Serial.print(E,3); Serial.println("kWh");
Serial.print("Frequency: "); Serial.print(f, 1); Serial.println("Hz");
Serial.print("PF: "); Serial.println(PF);
}
Blynk.run();
Blynk.virtualWrite(V0,DAY);
Blynk.virtualWrite(V1,TIME);
Blynk.virtualWrite(V2,DATE1);
Blynk.virtualWrite(V3,DATE2);
Blynk.virtualWrite(V4,h);
Blynk.virtualWrite(V5,t);
Blynk.virtualWrite(V6,V);
Blynk.virtualWrite(V7,I);
Blynk.virtualWrite(V8,P);
Blynk.virtualWrite(V9,E);
Blynk.virtualWrite(V10,f);
Blynk.virtualWrite(V11,PF);
delay(1000);
}
String ipToString(IPAddress ip)
{
String s="";
for (int i=0; i<4; i++)
s += i ? "." + String(ip[i]) : String(ip[i]);
return s;
}
void Web()
{
client = server.available();
float h = dht.readHumidity();
float t = dht.readTemperature();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE html>");
client.println("<head>\n<meta charset='UTF-8'>");
client.println("<title>A Development of IoT for Energy Management System</title>");
client.println("</head>\n<body>");
client.println("<H3>");
client.println("A Development of IoT for Energy Management System</BR>");
client.println("Department of Electrical Engineering, KMUTT</BR>");
client.println("<H3>Power and Energy Measurement</H3>");
client.println("<pre>");
client.println("</B>");
client.println("WiFi Network Name : " + String(ssid));
client.print("Signal Strength : ");
client.print(WiFi.RSSI());
client.println("dB ");
client.println("IP Address: "+ String(myIP));
client.print("Humidity: " +String(h));
client.println(" %");
client.print("Temperature: " +String(t));
client.println(" C");
client.println("</B>");
client.println(DAY);
client.println(DATE1);
client.println(DATE2);
client.println(TIME);
client.println(h);
client.println(t);
client.println(V);
client.println(I);
client.println(P);
client.println(E);
client.println(f);
client.println(PF);
client.println( );
client.println("<H3>Our Data Communicate Through NodeMCU V3</H3>");
client.println("</pre>");
client.println("</body>\n</html>");
}