- 积分
- 194
- 金钱
- 166
- 威望
- 0
- 贡献
- 0
- HASS币
- 0
注册会员
- 积分
- 194
- 金钱
- 166
- HASS币
- 0
|
发表于 2023-11-26 16:47:30
|
显示全部楼层
原来是楼主大大啊。 失敬失敬。 我详细说下。 H文件里面 你定义了电流、功率等的系数。 我在哪里加了2个变量。 WATT总功率,CF总电量。
bl0906.h 添加的部分。
static const float BL0906_WATT = 16*1.097*1.097*(20000+20000+20000+20000+20000)/(40.41259*((5.1+5.1)*1000/2000)*1*100*1*1000);//总功率转换*16
static const float BL0906_CF =16*4194304*0.032768*16/(3600000*16*(40.4125*((5.1+5.1)*1000/2000)*1*100*1*1000/(1.097*1.097*(20000+20000+20000+20000+20000))));//总电量转换*16
// 乘以该值以转换为实际 总电量值 (kWh)
float sum_energy_reference_ = BL0906_CF;
// 乘以该值以转换为实际 总功率值(W)
float sum_power_reference_ = BL0906_WATT;
bl0906.cpp 修改的部分 power_reference_ 改成 sum_power_reference_
read_data(BL0906_WATT_SUM, sum_power_reference_, power_sensor_sum_ );//功率。通道总和
read_data(BL0906_CF_SUM_CNT, sum_energy_reference_, energy_sensor_sum_ ); //电量。通道总和
读取部分做了修改:
//读取 总功率
if (reference == sum_power_reference_){
this-> write_byte(BL0906_READ_COMMAND);
this-> write_byte(address);
if (this-> read_array((uint8_t *) &buffer, sizeof(buffer)-1)) {
if (bl0906_checksum(address,&buffer)==buffer.checksum) {
data_s24.l = buffer.l;
data_s24.m = buffer.m;
data_s24.h = buffer.h;
value = (float) to_int32_t(data_s24) * reference;
if (sensor_ != nullptr) {
sensor_->publish_state(value);
}
}
} else {
ESP_LOGW(TAG, "Junk on wire. Throwing away partial power message");
while (read() >= 0)
;
}
}
//读取电压、电流、电量、总电量
if (reference == voltage_reference_ || reference == current_reference_ || reference == energy_reference_ || reference == sum_energy_reference_) {
this-> write_byte(BL0906_READ_COMMAND);
this-> write_byte(address);
if (this-> read_array((uint8_t *) &buffer, sizeof(buffer)-1)) {
//ESP_LOGW(TAG, "checksum= 0x%02X", bl0906_checksum(BL0906_V_RMS,&buffer));
if (bl0906_checksum(address,&buffer)==buffer.checksum) {
data_u24.l = buffer.l;
data_u24.m = buffer.m;
data_u24.h = buffer.h;
value = (float) to_uint32_t(data_u24) * reference;
if (sensor_ != nullptr) {
sensor_->publish_state(value);
}
}
} else {
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message");
while (read() >= 0)
;
}
}
|
|