-
Notifications
You must be signed in to change notification settings - Fork 26
/
espdm.h
74 lines (55 loc) · 3.16 KB
/
espdm.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "esphome.h"
#if defined(ESP32)
#include "mbedtls/gcm.h"
#endif
static const char* ESPDM_VERSION = "0.9.0";
static const char* TAG = "espdm";
namespace esphome
{
namespace espdm
{
class DlmsMeter : public Component, public uart::UARTDevice
{
public:
DlmsMeter(uart::UARTComponent *parent);
void setup() override;
void loop() override;
void set_voltage_sensors(sensor::Sensor *voltage_l1, sensor::Sensor *voltage_l2, sensor::Sensor *voltage_l3);
void set_current_sensors(sensor::Sensor *current_l1, sensor::Sensor *current_l2, sensor::Sensor *current_l3);
void set_active_power_sensors(sensor::Sensor *active_power_plus, sensor::Sensor *active_power_minus);
void set_active_energy_sensors(sensor::Sensor *active_energy_plus, sensor::Sensor *active_energy_minus);
void set_reactive_energy_sensors(sensor::Sensor *reactive_energy_plus, sensor::Sensor *reactive_energy_minus);
void set_timestamp_sensor(text_sensor::TextSensor *timestamp);
void enable_mqtt(mqtt::MQTTClientComponent *mqtt_client, const char *topic);
void set_key(uint8_t key[], size_t keyLength);
private:
std::vector<uint8_t> receiveBuffer; // Stores the packet currently being received
unsigned long lastRead = 0; // Timestamp when data was last read
int readTimeout = 100; // Time to wait after last byte before considering data complete
uint8_t key[16]; // Stores the decryption key
size_t keyLength; // Stores the decryption key length (usually 16 bytes)
const char *topic; // Stores the MQTT topic
#if defined(ESP32)
mbedtls_gcm_context aes; // AES context used for decryption
#endif
sensor::Sensor *voltage_l1 = NULL; // Voltage L1
sensor::Sensor *voltage_l2 = NULL; // Voltage L2
sensor::Sensor *voltage_l3 = NULL; // Voltage L3
sensor::Sensor *current_l1 = NULL; // Current L1
sensor::Sensor *current_l2 = NULL; // Current L2
sensor::Sensor *current_l3 = NULL; // Current L3
sensor::Sensor *active_power_plus = NULL; // Active power taken from grid
sensor::Sensor *active_power_minus = NULL; // Active power put into grid
sensor::Sensor *active_energy_plus = NULL; // Active energy taken from grid
sensor::Sensor *active_energy_minus = NULL; // Active energy put into grid
sensor::Sensor *reactive_energy_plus = NULL; // Reactive energy taken from grid
sensor::Sensor *reactive_energy_minus = NULL; // Reactive energy put into grid
text_sensor::TextSensor *timestamp = NULL; // Text sensor for the timestamp value
mqtt::MQTTClientComponent *mqtt_client = NULL;
uint16_t swap_uint16(uint16_t val);
uint32_t swap_uint32(uint32_t val);
void log_packet(std::vector<uint8_t> data);
void abort();
};
}
}