13 static const char *
const TAG =
"dsmr";
92 ESP_LOGW(TAG,
"Timeout while reading data for telegram");
102 ESP_LOGV(TAG,
"Start requesting data from P1 port");
105 ESP_LOGV(TAG,
"Start reading data from P1 port");
115 ESP_LOGV(TAG,
"Stop requesting data from P1 port");
118 ESP_LOGV(TAG,
"Stop reading data from P1 port");
138 const char c = this->
read();
142 ESP_LOGV(TAG,
"Header of telegram found");
152 ESP_LOGE(TAG,
"Error: telegram larger than buffer (%d bytes)", this->
max_telegram_len_);
162 if (previous_char ==
'\n' || previous_char ==
'\r') {
176 ESP_LOGV(TAG,
"Footer of telegram found");
192 const char c = this->
read();
196 if ((uint8_t) c != 0xDB) {
199 ESP_LOGV(TAG,
"Start byte 0xDB of encrypted telegram found");
207 ESP_LOGE(TAG,
"Error: encrypted telegram larger than buffer (%d bytes)", this->
max_telegram_len_);
226 ESP_LOGV(TAG,
"End of encrypted telegram found");
229 GCM<AES128> *gcmaes128{
new GCM<AES128>()};
233 for (
int i = 10; i < 14; i++)
235 constexpr uint16_t iv_size{12};
237 gcmaes128->decrypt(reinterpret_cast<uint8_t *>(this->
telegram_),
245 ESP_LOGV(TAG,
"Decrypted telegram size: %d bytes", this->
bytes_read_);
246 ESP_LOGVV(TAG,
"Decrypted telegram: %s", this->
telegram_);
257 ESP_LOGV(TAG,
"Trying to parse telegram");
260 ::dsmr::ParseResult<void> res =
266 ESP_LOGE(TAG,
"%s", err_str.c_str());
281 ESP_LOGCONFIG(TAG,
"DSMR:");
283 ESP_LOGCONFIG(TAG,
" Receive timeout: %.1fs", this->
receive_timeout_ / 1e3f);
291 #define DSMR_LOG_SENSOR(s) LOG_SENSOR(" ", #s, this->s_##s##_); 294 #define DSMR_LOG_TEXT_SENSOR(s) LOG_TEXT_SENSOR(" ", #s, this->s_##s##_); 295 DSMR_TEXT_SENSOR_LIST(DSMR_LOG_TEXT_SENSOR, )
299 if (decryption_key.length() == 0) {
300 ESP_LOGI(TAG,
"Disabling decryption");
309 if (decryption_key.length() != 32) {
310 ESP_LOGE(TAG,
"Error, decryption key must be 32 character long");
315 ESP_LOGI(TAG,
"Decryption key is set");
317 ESP_LOGV(TAG,
"Using decryption key: %s", decryption_key.c_str());
320 for (
int i = 0; i < 16; i++) {
321 strncpy(temp, &(decryption_key.c_str()[i * 2]), 2);
333 #endif // USE_ARDUINO virtual void digital_write(bool value)=0
::dsmr::ParsedData< DSMR_TEXT_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA) DSMR_BOTH DSMR_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA)> MyData
bool available_within_timeout_()
Wait for UART data to become available within the read timeout.
text_sensor::TextSensor * s_telegram_
void dump_config() override
uint32_t receive_timeout_
bool receive_timeout_reached_()
std::vector< uint8_t > decryption_key_
size_t get_rx_buffer_size()
size_t crypt_telegram_len_
void publish_state(const std::string &state)
uint32_t IRAM_ATTR HOT millis()
void publish_sensors(MyData &data)
void receive_encrypted_telegram_()
DSMR_SENSOR_LIST(DSMR_SET_SENSOR,) DSMR_TEXT_SENSOR_LIST(DSMR_SET_TEXT_SENSOR
void status_clear_warning()
uint32_t request_interval_
void set_decryption_key(const std::string &decryption_key)
bool ready_to_request_data_()
void start_requesting_data_()
bool request_interval_reached_()
uint32_t last_request_time_
Implementation of SPI Controller mode.
void stop_requesting_data_()
uint8_t * crypt_telegram_
void IRAM_ATTR HOT delay(uint32_t ms)