diff --git a/tasmota/tasmota_template_ESP32.h b/tasmota/tasmota_template_ESP32.h index 7d47b0409..aea45ea6a 100644 --- a/tasmota/tasmota_template_ESP32.h +++ b/tasmota/tasmota_template_ESP32.h @@ -127,7 +127,8 @@ enum UserSelectablePins { GPIO_WEBCAM_PSRCS, GPIO_BOILER_OT_RX, GPIO_BOILER_OT_TX, // OpenTherm Boiler TX pin GPIO_WINDMETER_SPEED, // WindMeter speed counter pin - GPIO_KEY1_TC, // Touch pin as button + GPIO_KEY1_TC, // Touch pin as button + GPIO_BL0940_RX, // BL0940 serial interface GPIO_SENSOR_END }; enum ProgramSelectablePins { @@ -216,7 +217,8 @@ const char kSensorNames[] PROGMEM = D_GPIO_WEBCAM_HSD "|" D_GPIO_WEBCAM_PSRCS "|" D_SENSOR_BOILER_OT_RX "|" D_SENSOR_BOILER_OT_TX "|" - D_SENSOR_WINDMETER_SPEED "|" D_SENSOR_BUTTON "_tc" + D_SENSOR_WINDMETER_SPEED "|" D_SENSOR_BUTTON "_tc|" + D_SENSOR_BL0940_RX ; const char kSensorNamesFixed[] PROGMEM = @@ -403,6 +405,9 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_LE01MR_TX), // F7F LE-01MR energy meter tx pin AGPIO(GPIO_LE01MR_RX), // F7F LE-01MR energy meter rx pin #endif // IFDEF:USE_LE01MR +#ifdef USE_BL0940 + AGPIO(GPIO_BL0940_RX), // BL0940 Serial interface +#endif #endif // USE_ENERGY_SENSOR // Serial diff --git a/tasmota/xnrg_14_bl0940.ino b/tasmota/xnrg_14_bl0940.ino index 99a738e81..cd9fcb884 100644 --- a/tasmota/xnrg_14_bl0940.ino +++ b/tasmota/xnrg_14_bl0940.ino @@ -29,7 +29,9 @@ #define XNRG_14 14 -#define BL0940_PULSES_NOT_INITIALIZED -1 +#define BL0940_PREF 1430 +#define BL0940_UREF 33000 +#define BL0940_IREF 2750 #define BL0940_BUFFER_SIZE 36 @@ -42,6 +44,7 @@ #define BL0940_READ_COMMAND 0x50 // 0x58 according to documentation #define BL0940_FULL_PACKET 0xAA + #define BL0940_PACKET_HEADER 0x55 // 0x58 according to documentation #include @@ -53,13 +56,11 @@ struct BL0940 { long current = 0; long power = 0; long power_cycle_first = 0; - long cf_pulses = 0; - long cf_pulses_last_time = BL0940_PULSES_NOT_INITIALIZED; +// long cf_pulses = 0; float temperature; int byte_counter = 0; uint8_t *rx_buffer = nullptr; - uint8_t power_invalid = 0; bool received = false; } Bl0940; @@ -85,7 +86,7 @@ void Bl0940Received(void) { Bl0940.voltage = Bl0940.rx_buffer[12] << 16 | Bl0940.rx_buffer[11] << 8 | Bl0940.rx_buffer[10]; Bl0940.current = Bl0940.rx_buffer[6] << 16 | Bl0940.rx_buffer[5] << 8 | Bl0940.rx_buffer[4]; Bl0940.power = Bl0940.rx_buffer[18] << 16 | Bl0940.rx_buffer[17] << 8 | Bl0940.rx_buffer[16]; - Bl0940.cf_pulses = Bl0940.rx_buffer[24] << 16 | Bl0940.rx_buffer[23] << 8 | Bl0940.rx_buffer[22]; +// Bl0940.cf_pulses = Bl0940.rx_buffer[24] << 16 | Bl0940.rx_buffer[23] << 8 | Bl0940.rx_buffer[22]; uint16_t tps1 = Bl0940.rx_buffer[29] << 8 | Bl0940.rx_buffer[28]; Bl0940.temperature = ((170.0f/448.0f)*(((float)tps1/2.0f)-32.0f))-45.0f; @@ -171,9 +172,9 @@ void Bl0940SnsInit(void) { ClaimSerial(); } if (HLW_UREF_PULSE == Settings.energy_voltage_calibration) { - Settings.energy_voltage_calibration = 33003; - Settings.energy_current_calibration = 2243; - Settings.energy_power_calibration = 1414; + Settings.energy_voltage_calibration = BL0940_UREF; + Settings.energy_current_calibration = BL0940_IREF; + Settings.energy_power_calibration = BL0940_PREF; } for (uint32_t i = 0; i < 5; i++) {