Skip to content

Commit

Permalink
Make "RCV Time" and "RFV Time" controllable (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored Jul 29, 2024
1 parent 6498e40 commit 65607af
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 175 deletions.
203 changes: 203 additions & 0 deletions components/jk_bms_ble/jk_bms_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,18 +1183,221 @@ void JkBmsBle::decode_device_info_(const std::vector<uint8_t> &data) {
// 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
// 0x65

// JK02_32S response example:
//
// 0x55 0xAA 0xEB 0x90 0x03 0xC9 0x4A 0x4B 0x5F 0x50 0x42 0x32 0x41 0x31 0x36 0x53 0x31 0x35 0x50 0x00 0x00 0x00 0x31
// 0x34 0x2E 0x58 0x41 0x00 0x00 0x00 0x31 0x34 0x2E 0x32 0x30 0x00 0x00 0x00 0x54 0xE6 0x01 0x00 0x9C 0x00 0x00 0x00
// 0x4A 0x4B 0x5F 0x50 0x42 0x32 0x41 0x31 0x36 0x53 0x31 0x35 0x50 0x00 0x00 0x00 0x31 0x32 0x33 0x34 0x00 0x00 0x00
// 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x32 0x33 0x31 0x31 0x31 0x38 0x00 0x00 0x33 0x30 0x39 0x32 0x35 0x37
// 0x32 0x31 0x33 0x34 0x00 0x30 0x30 0x30 0x30 0x00 0x49 0x6E 0x70 0x75 0x74 0x20 0x55 0x73 0x65 0x72 0x64 0x61 0x74
// 0x61 0x00 0x00 0x31 0x32 0x33 0x34 0x35 0x37 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x49 0x6E 0x70 0x75
// 0x74 0x20 0x55 0x73 0x65 0x72 0x64 0x61 0x74 0x61 0x00 0x00 0xFE 0xFF 0xFF 0xFF 0xAF 0xE9 0x01 0x02 0x00 0x00 0x00
// 0x00 0x90 0x1F 0x00 0x00 0x00 0x00 0xC0 0xD8 0xE7 0xFE 0x1F 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
// 0x01 0x04 0xCF 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xDF 0x07 0x00 0x00 0x00
// 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0xCF 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
// 0x00 0x00 0x00 0x00 0x00 0x0B 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x09 0x00 0x00 0x00 0x0B 0x00 0x00
// 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x51 0x00 0x00 0x0A 0x50 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
// 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFE 0x9F 0xE9 0xFE 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00
// 0x1B

// Byte Len Payload Content Coeff. Unit Example value
// 0 4 0x55 0xAA 0xEB 0x90 Header
// 4 1 0x03 Frame type
// 5 1 0xC9 Frame counter
// 6 16 0x4A 0x4B 0x5F 0x50 0x42 0x32 0x41 0x31 0x36 0x53 0x31 0x35 0x50 0x00 0x00 0x00
ESP_LOGI(TAG, " Vendor ID: %s", std::string(data.begin() + 6, data.begin() + 6 + 16).c_str());

// 22 8 0x31 0x34 0x2E 0x58 0x41 0x00 0x00 0x00
ESP_LOGI(TAG, " Hardware version: %s", std::string(data.begin() + 22, data.begin() + 22 + 8).c_str());

// 30 8 0x31 0x34 0x2E 0x32 0x30 0x00 0x00 0x00
ESP_LOGI(TAG, " Software version: %s", std::string(data.begin() + 30, data.begin() + 30 + 8).c_str());

// 38 4 0x54 0xE6 0x01 0x00
ESP_LOGI(TAG, " Uptime: %d s", jk_get_32bit(38));

// 42 4 0x9C 0x00 0x00 0x00
ESP_LOGI(TAG, " Power on count: %d", jk_get_32bit(42));

// 46 16 0x4A 0x4B 0x5F 0x50 0x42 0x32 0x41 0x31 0x36 0x53 0x31 0x35 0x50 0x00 0x00 0x00
ESP_LOGI(TAG, " Device name: %s", std::string(data.begin() + 46, data.begin() + 46 + 16).c_str());

// 62 16 0x31 0x32 0x33 0x34 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
ESP_LOGI(TAG, " Device passcode: %s", std::string(data.begin() + 62, data.begin() + 62 + 16).c_str());

// 78 8 0x32 0x33 0x31 0x31 0x31 0x38 0x00 0x00
ESP_LOGI(TAG, " Manufacturing date: %s", std::string(data.begin() + 78, data.begin() + 78 + 8).c_str());

// 86 8 0x33 0x30 0x39 0x32 0x35 0x37 0x32 0x31 0x33 0x34 0x00
ESP_LOGI(TAG, " Serial number: %s", std::string(data.begin() + 86, data.begin() + 86 + 11).c_str());

// 97 5 0x30 0x30 0x30 0x30 0x00
ESP_LOGI(TAG, " Passcode: %s", std::string(data.begin() + 97, data.begin() + 97 + 5).c_str());

// 102 16 0x49 0x6E 0x70 0x75 0x74 0x20 0x55 0x73 0x65 0x72 0x64 0x61 0x74 0x61 0x00 0x00
ESP_LOGI(TAG, " User data: %s", std::string(data.begin() + 102, data.begin() + 102 + 16).c_str());

// 118 16 0x31 0x32 0x33 0x34 0x35 0x37 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
ESP_LOGI(TAG, " Setup passcode: %s", std::string(data.begin() + 118, data.begin() + 118 + 16).c_str());

if (this->protocol_version_ != PROTOCOL_VERSION_JK02_32S)
return;

// 134 0x49
// 135 0x6E
// 136 0x70
// 137 0x75
// 138 0x74
// 139 0x20
// 140 0x55
// 141 0x73
// 142 0x65
// 143 0x72
// 144 0x64
// 145 0x61
// 146 0x74
// 147 0x61
// 148 0x00
// 149 0x00
// 150 0xFE
// 151 0xFF
// 152 0xFF
// 153 0xFF
// 154 0xAF
// 155 0xE9
// 156 0x01
// 157 0x02
// 158 0x00
// 159 0x00
// 160 0x00
// 161 0x00
// 162 0x90
// 163 0x1F
// 164 0x00
// 165 0x00
// 166 0x00
// 167 0x00
// 168 0xC0
// 169 0xD8
// 170 0xE7
// 171 0xFE
// 172 0x1F
// 173 0x00
// 174 0x00
// 175 0x01
// 176 0x00
// 177 0x00
// 178 0x00
// 179 0x00
// 180 0x00
// 181 0x00
// 182 0x00
// 183 0x00
// 184 0x01 UART1M Protocol number
ESP_LOGI(TAG, " UART1 Protocol: %d", data[184]);
// 185 0x04 CANM Protocol number
ESP_LOGI(TAG, " CAN Protocol: %d", data[185]);
// 186 0xCF
// 187 0x03
// 188 0x00
// 189 0x00
// 190 0x00
// 191 0x00
// 192 0x00
// 193 0x00
// 194 0x00
// 195 0x00
// 196 0x00
// 197 0x00
// 198 0x00
// 199 0x00
// 200 0x00
// 201 0x00
// 202 0xDF
// 203 0x07
// 204 0x00
// 205 0x00
// 206 0x00
// 207 0x00
// 208 0x00
// 209 0x00
// 210 0x00
// 211 0x00
// 212 0x00
// 213 0x00
// 214 0x00
// 215 0x00
// 216 0x00
// 217 0x00
// 218 0x01 UART2M Protocol number
ESP_LOGI(TAG, " UART2 Protocol: %d", data[218]);
// 219 0xCF UART2M Protocol enable
// 220 0x03
// 221 0x00
// 222 0x00
// 223 0x00
// 224 0x00
// 225 0x00
// 226 0x00
// 227 0x00
// 228 0x00
// 229 0x00
// 230 0x00
// 231 0x00
// 232 0x00
// 233 0x00
// 234 0x00 LCD buzzer trigger
// 235 0x0B DRY1 Trigger
// 236 0x00 DRY2 Trigger
// 237 0x01 UART protocol library version
// 238 0x00 0x00 0x00 0x00 LCD Buzzer Trigger Value
// 242 0x00 0x00 0x00 0x00 LCD Buzzer Release Value
// 246 0x09 0x00 0x00 0x00 DRY1 Trigger Value
// 250 0x0B 0x00 0x00 0x00 DRY1 Release Value
// 254 0x00 0x00 0x00 0x00 DRY2 Trigger Value
// 258 0x00 0x00 0x00 0x00 DRY2 Release Value
// 262 0x80 0x51 0x00 0x00 Data Stored Period

// 266 0x0A RCV Time 0.1h
ESP_LOGI(TAG, " RCV Time: %.1f h", (float) data[266] * 0.1f);
this->publish_state_(this->cell_request_charge_voltage_number_, (float) data[266] * 0.1f);

// 267 0x50 RFV Time 0.1h
ESP_LOGI(TAG, " RFV Time: %.1f h", (float) data[267] * 0.1f);
this->publish_state_(this->cell_request_float_voltage_number_, (float) data[267] * 0.1f);

// 268 0x01 CAN protocol library version
// 269 0x00 Reserved
// 270 0x00
// 271 0x00
// 272 0x00
// 273 0x00
// 274 0x00
// 275 0x00
// 276 0x00
// 277 0x00
// 278 0x00
// 279 0x00
// 280 0x00
// 281 0x00
// 282 0x00
// 283 0x00
// 284 0x00
// 285 0x00
// 286 0x00
// 287 0xFE
// 288 0x9F
// 289 0xE9
// 290 0xFE
// 291 0x03
// 292 0x00
// 293 0x00
// 294 0x00
// 295 0x00
// 296 0x00
// 297 0x00
// 298 0x00
// 299 0x1B CRC
}

bool JkBmsBle::write_register(uint8_t address, uint32_t value, uint8_t length) {
Expand Down
8 changes: 8 additions & 0 deletions components/jk_bms_ble/jk_bms_ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class JkBmsBle : public esphome::ble_client::BLEClientNode, public PollingCompon
void set_cell_request_float_voltage_number(number::Number *cell_request_float_voltage_number) {
cell_request_float_voltage_number_ = cell_request_float_voltage_number;
}
void set_cell_request_charge_voltage_time_number(number::Number *cell_request_charge_voltage_time_number) {
cell_request_charge_voltage_time_number_ = cell_request_charge_voltage_time_number;
}
void set_cell_request_float_voltage_time_number(number::Number *cell_request_float_voltage_time_number) {
cell_request_float_voltage_time_number_ = cell_request_float_voltage_time_number;
}
void set_cell_count_number(number::Number *cell_count_number) { cell_count_number_ = cell_count_number; }
void set_total_battery_capacity_number(number::Number *total_battery_capacity_number) {
total_battery_capacity_number_ = total_battery_capacity_number;
Expand Down Expand Up @@ -287,6 +293,8 @@ class JkBmsBle : public esphome::ble_client::BLEClientNode, public PollingCompon
number::Number *cell_soc0_voltage_number_;
number::Number *cell_request_charge_voltage_number_;
number::Number *cell_request_float_voltage_number_;
number::Number *cell_request_charge_voltage_time_number_;
number::Number *cell_request_float_voltage_time_number_;
number::Number *cell_count_number_;
number::Number *total_battery_capacity_number_;
number::Number *cell_voltage_overvoltage_protection_number_;
Expand Down
Loading

0 comments on commit 65607af

Please sign in to comment.