From 882ed16347f7e8eae048ca922b3cde63658cc6d0 Mon Sep 17 00:00:00 2001 From: aoe1 Date: Fri, 1 Apr 2022 13:02:43 +0200 Subject: [PATCH] Patched BL09xx to measure positive and negative power Removed the abs() from the power so as to measure power flow from/to grid --- tasmota/xnrg_14_bl09xx.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tasmota/xnrg_14_bl09xx.ino b/tasmota/xnrg_14_bl09xx.ino index 14228a812..2a5f5e00a 100644 --- a/tasmota/xnrg_14_bl09xx.ino +++ b/tasmota/xnrg_14_bl09xx.ino @@ -84,9 +84,9 @@ const uint8_t bl09xx_init[5][4] = { }; struct BL09XX { - uint32_t voltage = 0; - uint32_t current[2] = { 0, }; - uint32_t power[2] = { 0, }; + int32_t voltage = 0; + int32_t current[2] = { 0, }; + int32_t power[2] = { 0, }; float temperature; uint16_t tps1 = 0; uint8_t *rx_buffer = nullptr; @@ -129,12 +129,12 @@ bool Bl09XXDecode3940(void) { Bl09XX.voltage = Bl09XX.rx_buffer[12] << 16 | Bl09XX.rx_buffer[11] << 8 | Bl09XX.rx_buffer[10]; // V_RMS unsigned Bl09XX.current[0] = Bl09XX.rx_buffer[6] << 16 | Bl09XX.rx_buffer[5] << 8 | Bl09XX.rx_buffer[4]; // IA_RMS unsigned int32_t tmp = Bl09XX.rx_buffer[18] << 24 | Bl09XX.rx_buffer[17] << 16 | Bl09XX.rx_buffer[16] << 8; // WATT_A signed - Bl09XX.power[0] = abs(tmp >> 8); // WATT_A unsigned + Bl09XX.power[0] = (tmp >> 8); // WATT_A unsigned if (Energy.phase_count > 1) { Bl09XX.current[1] = Bl09XX.rx_buffer[9] << 16 | Bl09XX.rx_buffer[8] << 8 | Bl09XX.rx_buffer[7]; // IB_RMS unsigned tmp = Bl09XX.rx_buffer[21] << 24 | Bl09XX.rx_buffer[20] << 16 | Bl09XX.rx_buffer[19] << 8; // WATT_B signed - Bl09XX.power[1] = abs(tmp >> 8); // WATT_B unsigned + Bl09XX.power[1] = (tmp >> 8); // WATT_B unsigned } #ifdef DEBUG_BL09XX @@ -172,7 +172,7 @@ bool Bl09XXDecode42(void) { Bl09XX.voltage = Bl09XX.rx_buffer[6] << 16 | Bl09XX.rx_buffer[5] << 8 | Bl09XX.rx_buffer[4]; // V_RMS unsigned Bl09XX.current[0] = Bl09XX.rx_buffer[3] << 16 | Bl09XX.rx_buffer[2] << 8 | Bl09XX.rx_buffer[1]; // IA_RMS unsigned int32_t tmp = Bl09XX.rx_buffer[12] << 24 | Bl09XX.rx_buffer[11] << 16 | Bl09XX.rx_buffer[10] << 8; // WATT_A signed - Bl09XX.power[0] = abs(tmp >> 8); // WATT_A unsigned + Bl09XX.power[0] = (tmp >> 8); // WATT_A unsigned #ifdef DEBUG_BL09XX AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("BL9: U %d, I %d, P %d"), @@ -427,4 +427,4 @@ bool Xnrg14(uint8_t function) { } #endif // USE_BL09XX -#endif // USE_ENERGY_SENSOR \ No newline at end of file +#endif // USE_ENERGY_SENSOR