File tree Expand file tree Collapse file tree 2 files changed +112
-0
lines changed Expand file tree Collapse file tree 2 files changed +112
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* 1.0.0 VERSION */
2
+
3
+ #include " ddpzem004t.h"
4
+
5
+ DDPzem004t::DDPzem004t (int led)
6
+ {
7
+ this ->_led = led;
8
+ }
9
+
10
+ void DDPzem004t::init (PZEM004T *pzem, IPAddress ip)
11
+ {
12
+ pzem->setAddress (ip);
13
+ }
14
+
15
+ float DDPzem004t::getVoltage (PZEM004T *pzem, IPAddress ip)
16
+ {
17
+ int i = 0 ;
18
+ float r = -1.0 ;
19
+ do
20
+ {
21
+ r = pzem->voltage (ip);
22
+ wdt_reset ();
23
+ i++;
24
+ } while (i < MAX_ATTEMPTS && r < 0.0 );
25
+ return r;
26
+ }
27
+
28
+ float DDPzem004t::getCurrent (PZEM004T *pzem, IPAddress ip)
29
+ {
30
+ int i = 0 ;
31
+ float r = -1.0 ;
32
+ do
33
+ {
34
+ r = pzem->current (ip);
35
+ wdt_reset ();
36
+ i++;
37
+ } while (i < MAX_ATTEMPTS && r < 0.0 );
38
+ return r;
39
+ }
40
+
41
+ float DDPzem004t::getPower (PZEM004T *pzem, IPAddress ip)
42
+ {
43
+ int i = 0 ;
44
+ float r = -1.0 ;
45
+ do
46
+ {
47
+ r = pzem->power (ip);
48
+ wdt_reset ();
49
+ i++;
50
+ } while (i < MAX_ATTEMPTS && r < 0.0 );
51
+ return r;
52
+ }
53
+
54
+ float DDPzem004t::getEnergy (PZEM004T *pzem, IPAddress ip)
55
+ {
56
+ int i = 0 ;
57
+ float r = -1.0 ;
58
+ do
59
+ {
60
+ r = pzem->energy (ip);
61
+ wdt_reset ();
62
+ i++;
63
+ } while (i < MAX_ATTEMPTS && r < 0.0 );
64
+ return r;
65
+ }
66
+
67
+ DDPZEM004TVal DDPzem004t::getValues (PZEM004T *pzem, IPAddress ip)
68
+ {
69
+ DDPZEM004TVal ret;
70
+ ret.voltage = getVoltage (pzem, ip);
71
+ ret.current = getCurrent (pzem, ip);
72
+ ret.power = getPower (pzem, ip);
73
+ ret.energy = getEnergy (pzem, ip);
74
+ ret.success = ret.voltage >= 0.0 && ret.voltage >= 0.0 && ret.voltage >= 0.0 && ret.voltage >= 0.0 ;
75
+ return ret;
76
+ }
Original file line number Diff line number Diff line change
1
+ /* 1.0.0 VERSION */
2
+
3
+ #ifndef ddpzem004t_h
4
+ #define ddpzem004t_h
5
+
6
+ #include < SoftwareSerial.h> // Arduino IDE <1.6.6
7
+ #include < PZEM004T.h>
8
+
9
+ #define MAX_ATTEMPTS 1
10
+
11
+ struct DDPZEM004TVal
12
+ {
13
+ float current = 0.0 ;
14
+ float voltage = 0.0 ;
15
+ float power = 0.0 ;
16
+ float energy = 0.0 ;
17
+ bool success;
18
+ const char *errorMsg;
19
+ };
20
+
21
+ class DDPzem004t
22
+ {
23
+ private:
24
+ int _led;
25
+ float getVoltage (PZEM004T *, IPAddress);
26
+ float getCurrent (PZEM004T *, IPAddress);
27
+ float getPower (PZEM004T *, IPAddress);
28
+ float getEnergy (PZEM004T *, IPAddress);
29
+
30
+ public:
31
+ DDPzem004t (int );
32
+ DDPZEM004TVal getValues (PZEM004T *, IPAddress);
33
+ void init (PZEM004T *, IPAddress);
34
+ };
35
+
36
+ #endif
You can’t perform that action at this time.
0 commit comments