mirofromdiro / JK-firmware-code

9 stars 6 forks source link

Setting password #1

Closed rgr-1 closed 4 months ago

rgr-1 commented 5 months ago

The settings password for JK-BMS can be constructed as: "your time dependent code"+"crc8.ROHC(serilar of inverter)"

With this I am able to "unlock" settings of both mine jk-bms PB2A16S20P.. Sure anyone else who may connect to them will be able as well. I will not bother you with my ranting about "JK security" or rather absence of it :)

You may add this to your code generator to save people from unnecessary interaction with JK.

Below is the js code I played with in Node-Red:

// it uses easy-crc from https://github.com/emn178/js-crc

let byte_array = [
    0x01, 0x04, 0x03, 0x02, 0x08, 0x06, 0x07, 0x05,
    0x04, 0x01, 0x03, 0x02, 0x05, 0x08, 0x07, 0x06,
    0x08, 0x02, 0x01, 0x03, 0x05, 0x04, 0x07, 0x06,
    0x06, 0x02, 0x03, 0x04, 0x01, 0x07, 0x05, 0x08,
    0x07, 0x01, 0x02, 0x03, 0x05, 0x06, 0x04, 0x08,
    0x05, 0x02, 0x03, 0x04, 0x01, 0x08, 0x07, 0x06,
    0x02, 0x03, 0x04, 0x01, 0x05, 0x08, 0x06, 0x07,
    0x03, 0x04, 0x01, 0x02, 0x07, 0x08, 0x05, 0x06,
    0x05, 0x06, 0x01, 0x02, 0x07, 0x08, 0x03, 0x04,
    0x06, 0x07, 0x01, 0x02, 0x05, 0x08, 0x03, 0x04
];

// ---------------------
//let d = new Date("2024-06-06T08:00:00")
let d = new Date()

//let serial = '40110490041'
let serial = '40110490823'

let code = getCode(d)
let pswd_addon = getPasswordPart(serial)

// settings password = "force code" + "crc8.rohc from serial"
let res = {
    "code": code,
    "pswd": code + pswd_addon 
}

msg.payload = res
return msg;

// Test case 1: 
// time: 2024.06.06_08:25:00  -> 24060606
// serial: 40110490041
// code: 02400666
// pssw: 0240066635
//
// Test case 2:
// serial: 40110490823
// pswd_addon: 3c
//

function getPasswordPart(serial) {
    let checksum = easyCrc.crc8('ROHC', serial);
    let s = checksum.toString(16)
    return s
}

function getCode(date_time = new Date()) {
    var d = date_time.toISOString().slice(2, 10).replace(/-/g, "") + date_time.getUTCHours().toString().padStart(2, '0');
    var qs = d.split('').reduce((a, b) => a + parseInt(b), 0);
    var m = qs % 10;
    var r = "";
    for (var i = 0; i < 8; i++) {
        var index = i + m * 8;
        var c = byte_array[index];
        r += d[c - 1];
    }
    return r;
}
mirofromdiro commented 4 months ago

Thanks for the good work! I added the settings password calculation in commit 686da23.

Could you please test?

rgr-1 commented 4 months ago

Works perfectly with mine 2 JK-BMSs The only comment - maybe it make sense to add "This code is valid for XXm YYs" sentence to this as well.

Or maybe make it similar to what I got from jk.. which triggered me to have a closer look on it :)

image image