-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPZEM.ino
51 lines (36 loc) · 945 Bytes
/
PZEM.ino
1
2
3
4
5
6
7
8
9
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
#include <PZEM004T.h>
PZEM004T* pzem;
IPAddress ip_pzem(192,168,1,1);
// Energy monitor.
// https://github.com/vortigont/pzem-edl/blob/main/docs/PZEM-004T-V3.0-Datasheet-User-Manual.pdf
void pzem_setup()
{
Serial.println("Setup PZEM004T");
while(!Serial1) { }
pzem = new PZEM004T(&Serial1);
pzem->setAddress(ip_pzem);
Serial.println("PZEM004T OK");
}
// PZEM_loop
void energy_monitor()
{
v = pzem->voltage(ip_pzem);
if (v < 0.0) {
Serial.println("nema komunikacije ili 230V napajanja!!!");
}
Serial.print(v);
Serial.print("V; ");
struja = pzem->current(ip_pzem);
if(struja >= 0.0) {
Serial.print(struja);Serial.print("A; ");
}
p = pzem->power(ip_pzem);
if(p >= 0.0) {
Serial.print(p);Serial.print("W; ");
}
e = pzem->energy(ip_pzem);
if(e >= 0.0) {
Serial.print(e);Serial.print("Wh; ");
}
Serial.println();
}