jk-bms_grafana
jk-bms_grafana copied to clipboard
total Current A works only for Discharge, u need to add one more case
Have look into the JK BMS description for current A: x84 x84
I used this code who did it right to get the correct values for current charge and discharge. I put the sign 1/-1 like in the LCD display. (But up to u.): SIinterJK
I changed your code line 118 for current as follows:
# total Current A
cbatt = data[63:65] # check discharge or charge
print (cbatt)
if cbatt[0] & 0x80:
sign = 1
chmode = "Charge"
else:
sign = -1
chmode = "Discharge"
cbattr = ''.join(format(x, '02x') for x in cbatt)
cbatth = cbattr[-3:]
# print (cbatth)
cbattd = sign * int(cbatth,16)
current_total = cbattd/100
print ("Current Battery = ", "{:.2f}".format(cbattd/100),"A", chmode)
The reason I did not go further with the current (and left it essentially as an exercise to the reader like you) is that there are several different versions of the BMS that format this current data slightly different. I've not had the time to make a generic implementation for all versions...