Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print more errors #568

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions components/jk_bms_ble/jk_bms_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ static const char *const ERRORS[ERRORS_SIZE] = {
"Charge short circuit", // 1000 0000 0000 0000
};

static const uint8_t ERRORS2_SIZE = 16;
static const char *const ERRORS2[ERRORS_SIZE] = {
"Charge MOS", // 0000 0001 0000 0000
"Discharge MOS", // 0000 0010 0000 0000
"GPS Disconnected", // 0000 0100 0000 0000
"Modify password in time", // 0000 1000 0000 0000
"Discharge On failed", // 0001 0000 0000 0000
"Battery overtemperature", // 0010 0000 0000 0000
"Temperature sensor anomaly", // 0100 0000 0000 0000
"PLC module anomaly", // 1000 0000 0000 0000
"Reserved", // 0000 0000 0000 0001
"Reserved", // 0000 0000 0000 0010
"Reserved", // 0000 0000 0000 0100
"Reserved", // 0000 0000 0000 1000
"Reserved", // 0000 0000 0001 0000
"Reserved", // 0000 0000 0010 0000
"Reserved", // 0000 0000 0100 0000
"Reserved", // 0000 0000 1000 0000
};

uint8_t crc(const uint8_t data[], const uint16_t len) {
uint8_t crc = 0;
for (uint16_t i = 0; i < len; i++) {
Expand Down Expand Up @@ -453,6 +473,8 @@ void JkBmsBle::decode_jk02_cell_info_(const std::vector<uint8_t> &data) {
uint16_t raw_errors_bitmask = (uint16_t(data[134 + offset]) << 8) | (uint16_t(data[134 + 1 + offset]) << 0);
this->publish_state_(this->errors_bitmask_sensor_, (float) raw_errors_bitmask);
this->publish_state_(this->errors_text_sensor_, this->error_bits_to_string_(raw_errors_bitmask));
ESP_LOGI(TAG, "Errors2: %s (%d)", this->error2_bits_to_string_(jk_get_16bit(136 + offset)).c_str(),
jk_get_16bit(136 + offset));
} else {
this->publish_state_(this->power_tube_temperature_sensor_, (float) ((int16_t) jk_get_16bit(134 + offset)) * 0.1f);
}
Expand Down Expand Up @@ -1551,6 +1573,26 @@ std::string JkBmsBle::error_bits_to_string_(const uint16_t mask) {
return errors_list;
}

std::string JkBmsBle::error2_bits_to_string_(const uint16_t mask) {
bool first = true;
std::string errors_list = "";

if (mask) {
for (int i = 0; i < ERRORS2_SIZE; i++) {
if (mask & (1 << i)) {
if (first) {
first = false;
} else {
errors_list.append(";");
}
errors_list.append(ERRORS2[i]);
}
}
}

return errors_list;
}

} // namespace jk_bms_ble
} // namespace esphome

Expand Down
1 change: 1 addition & 0 deletions components/jk_bms_ble/jk_bms_ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class JkBmsBle : public esphome::ble_client::BLEClientNode, public PollingCompon
void reset_online_status_tracker_();
void track_online_status_();
std::string error_bits_to_string_(uint16_t bitmask);
std::string error2_bits_to_string_(uint16_t bitmask);

std::string format_total_runtime_(const uint32_t value) {
int seconds = (int) value;
Expand Down
Loading