diff --git a/driver/chargerybms.py b/driver/chargerybms.py index 730e0be..c140aaf 100644 --- a/driver/chargerybms.py +++ b/driver/chargerybms.py @@ -37,12 +37,16 @@ driver = { parser = argparse.ArgumentParser(description = 'Chargery BMS driver') parser.add_argument('--version', action='version', version='%(prog)s v' + str(driver['version']) + ' (' + driver['serial'] + ')') +parser.add_argument('--debug', action="store_true", help='enable debug logging') parser.add_argument('--test', action="store_true", help='test some stored examples network packets') parser.add_argument('--victron', action="store_true", help='enable Victron DBUS support for VenusOS') requiredArguments = parser.add_argument_group('required arguments') requiredArguments.add_argument('-d', '--device', help='serial device for data (eg /dev/ttyUSB0)', required=True) args = parser.parse_args() +if args.debug: # switch to debug level + logging.setLevel(logging.DEBUG) + serial_port = serial.Serial(args.device, 115200, timeout=1) serial_port.flushInput() @@ -240,7 +244,7 @@ PACKET_LENGTH_STATUS_IMPEDANCES = [24, 40, 56] MIN_CELL_VOLTAGE = 1.0 -MIN_CELL_IMPEDANCE = 0.1 +MIN_CELL_IMPEDANCE = 0.0 BMS_STATUS = { 'bms' : { @@ -545,6 +549,12 @@ BMS_TEST_PACKETS = { } +# define special unicode characters here +SPECIAL_DISPLAY_SYMBOLS = { + 'degree' : u'\u00b0', + 'ohm' : u'\u03A9' +} + def debug_packet(packet): print for packet_byte in packet: @@ -671,9 +681,9 @@ def parse_packet(packet): # current temperatures BMS_STATUS['bms']['temperature']['sensor_t1']['value'] = get_temperature_value(ord(packet[9]), ord(packet[10])) - BMS_STATUS['bms']['temperature']['sensor_t1']['text'] = str(BMS_STATUS['bms']['temperature']['sensor_t1']['value']) + "C" + BMS_STATUS['bms']['temperature']['sensor_t1']['text'] = str(BMS_STATUS['bms']['temperature']['sensor_t1']['value']) + SPECIAL_DISPLAY_SYMBOLS['degree'] + "C" BMS_STATUS['bms']['temperature']['sensor_t2']['value'] = get_temperature_value(ord(packet[11]), ord(packet[12])) - BMS_STATUS['bms']['temperature']['sensor_t2']['text'] = str(BMS_STATUS['bms']['temperature']['sensor_t2']['value']) + "C" + BMS_STATUS['bms']['temperature']['sensor_t2']['text'] = str(BMS_STATUS['bms']['temperature']['sensor_t2']['value']) + SPECIAL_DISPLAY_SYMBOLS['degree'] + "C" if args.victron: dbusservice["/Info/Temp/Sensor1"] = BMS_STATUS['bms']['temperature']['sensor_t1']['text'] @@ -954,53 +964,53 @@ def parse_packet(packet): # get min/max voltages to calculate the diff cell_voltages = [] - if (BMS_STATUS['voltages']['cell1_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell1_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell1_voltage']['value']) - if (BMS_STATUS['voltages']['cell2_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell2_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell2_voltage']['value']) - if (BMS_STATUS['voltages']['cell3_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell3_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell3_voltage']['value']) - if (BMS_STATUS['voltages']['cell4_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell4_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell4_voltage']['value']) - if (BMS_STATUS['voltages']['cell5_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell5_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell5_voltage']['value']) - if (BMS_STATUS['voltages']['cell6_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell6_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell6_voltage']['value']) - if (BMS_STATUS['voltages']['cell7_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell7_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell7_voltage']['value']) - if (BMS_STATUS['voltages']['cell8_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell8_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell8_voltage']['value']) - if (BMS_STATUS['voltages']['cell9_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell9_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell9_voltage']['value']) - if (BMS_STATUS['voltages']['cell10_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell10_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell10_voltage']['value']) - if (BMS_STATUS['voltages']['cell11_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell11_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell11_voltage']['value']) - if (BMS_STATUS['voltages']['cell12_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell12_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell12_voltage']['value']) - if (BMS_STATUS['voltages']['cell13_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell13_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell13_voltage']['value']) - if (BMS_STATUS['voltages']['cell14_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell14_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell14_voltage']['value']) - if (BMS_STATUS['voltages']['cell15_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell15_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell15_voltage']['value']) - if (BMS_STATUS['voltages']['cell16_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell16_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell16_voltage']['value']) - if (BMS_STATUS['voltages']['cell17_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell17_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell17_voltage']['value']) - if (BMS_STATUS['voltages']['cell18_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell18_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell18_voltage']['value']) - if (BMS_STATUS['voltages']['cell19_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell19_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell19_voltage']['value']) - if (BMS_STATUS['voltages']['cell20_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell20_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell20_voltage']['value']) - if (BMS_STATUS['voltages']['cell21_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell21_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell21_voltage']['value']) - if (BMS_STATUS['voltages']['cell22_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell22_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell22_voltage']['value']) - if (BMS_STATUS['voltages']['cell23_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell23_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell23_voltage']['value']) - if (BMS_STATUS['voltages']['cell24_voltage']['value'] > MIN_CELL_VOLTAGE): + if (BMS_STATUS['voltages']['cell24_voltage']['value'] >= MIN_CELL_VOLTAGE): cell_voltages.append(BMS_STATUS['voltages']['cell24_voltage']['value']) BMS_STATUS['voltages']['agg_voltages']['sum']['value'] = sum(cell_voltages) @@ -1247,49 +1257,49 @@ def parse_packet(packet): # cell impedances BMS8 BMS_STATUS['impedances']['cell1_impedance']['value'] = get_cell_impedance(ord(packet[7]), ord(packet[8])) - BMS_STATUS['impedances']['cell1_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell1_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell1_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell1_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell1"] = BMS_STATUS['impedances']['cell1_impedance']['text'] dbusservice["/Raw/Impedances/Cell1"] = BMS_STATUS['impedances']['cell1_impedance']['value'] BMS_STATUS['impedances']['cell2_impedance']['value'] = get_cell_impedance(ord(packet[9]), ord(packet[10])) - BMS_STATUS['impedances']['cell2_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell2_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell2_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell2_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell2"] = BMS_STATUS['impedances']['cell2_impedance']['text'] dbusservice["/Raw/Impedances/Cell2"] = BMS_STATUS['impedances']['cell2_impedance']['value'] BMS_STATUS['impedances']['cell3_impedance']['value'] = get_cell_impedance(ord(packet[11]), ord(packet[12])) - BMS_STATUS['impedances']['cell3_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell3_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell3_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell3_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell3"] = BMS_STATUS['impedances']['cell3_impedance']['text'] dbusservice["/Raw/Impedances/Cell3"] = BMS_STATUS['impedances']['cell3_impedance']['value'] BMS_STATUS['impedances']['cell4_impedance']['value'] = get_cell_impedance(ord(packet[13]), ord(packet[14])) - BMS_STATUS['impedances']['cell4_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell4_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell4_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell4_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell4"] = BMS_STATUS['impedances']['cell4_impedance']['text'] dbusservice["/Raw/Impedances/Cell4"] = BMS_STATUS['impedances']['cell4_impedance']['value'] BMS_STATUS['impedances']['cell5_impedance']['value'] = get_cell_impedance(ord(packet[15]), ord(packet[16])) - BMS_STATUS['impedances']['cell5_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell5_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell5_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell5_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell5"] = BMS_STATUS['impedances']['cell5_impedance']['text'] dbusservice["/Raw/Impedances/Cell5"] = BMS_STATUS['impedances']['cell5_impedance']['value'] BMS_STATUS['impedances']['cell6_impedance']['value'] = get_cell_impedance(ord(packet[17]), ord(packet[18])) - BMS_STATUS['impedances']['cell6_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell6_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell6_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell6_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell6"] = BMS_STATUS['impedances']['cell6_impedance']['text'] dbusservice["/Raw/Impedances/Cell6"] = BMS_STATUS['impedances']['cell6_impedance']['value'] BMS_STATUS['impedances']['cell7_impedance']['value'] = get_cell_impedance(ord(packet[19]), ord(packet[20])) - BMS_STATUS['impedances']['cell7_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell7_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell7_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell7_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell7"] = BMS_STATUS['impedances']['cell7_impedance']['text'] dbusservice["/Raw/Impedances/Cell7"] = BMS_STATUS['impedances']['cell7_impedance']['value'] BMS_STATUS['impedances']['cell8_impedance']['value'] = get_cell_impedance(ord(packet[21]), ord(packet[22])) - BMS_STATUS['impedances']['cell8_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell8_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell8_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell8_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell8"] = BMS_STATUS['impedances']['cell8_impedance']['text'] dbusservice["/Raw/Impedances/Cell8"] = BMS_STATUS['impedances']['cell8_impedance']['value'] @@ -1300,49 +1310,49 @@ def parse_packet(packet): # cell impedances BMS8 BMS_STATUS['impedances']['cell9_impedance']['value'] = get_cell_impedance(ord(packet[23]), ord(packet[24])) - BMS_STATUS['impedances']['cell9_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell9_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell9_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell9_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell9"] = BMS_STATUS['impedances']['cell9_impedance']['text'] dbusservice["/Raw/Impedances/Cell9"] = BMS_STATUS['impedances']['cell9_impedance']['value'] BMS_STATUS['impedances']['cell10_impedance']['value'] = get_cell_impedance(ord(packet[25]), ord(packet[26])) - BMS_STATUS['impedances']['cell10_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell10_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell10_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell10_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell10"] = BMS_STATUS['impedances']['cell10_impedance']['text'] dbusservice["/Raw/Impedances/Cell10"] = BMS_STATUS['impedances']['cell10_impedance']['value'] BMS_STATUS['impedances']['cell11_impedance']['value'] = get_cell_impedance(ord(packet[27]), ord(packet[28])) - BMS_STATUS['impedances']['cell11_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell11_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell11_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell11_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell11"] = BMS_STATUS['impedances']['cell11_impedance']['text'] dbusservice["/Raw/Impedances/Cell11"] = BMS_STATUS['impedances']['cell11_impedance']['value'] BMS_STATUS['impedances']['cell12_impedance']['value'] = get_cell_impedance(ord(packet[29]), ord(packet[30])) - BMS_STATUS['impedances']['cell12_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell12_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell12_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell12_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell12"] = BMS_STATUS['impedances']['cell12_impedance']['text'] dbusservice["/Raw/Impedances/Cell12"] = BMS_STATUS['impedances']['cell12_impedance']['value'] BMS_STATUS['impedances']['cell13_impedance']['value'] = get_cell_impedance(ord(packet[31]), ord(packet[32])) - BMS_STATUS['impedances']['cell13_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell13_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell13_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell13_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell13"] = BMS_STATUS['impedances']['cell13_impedance']['text'] dbusservice["/Raw/Impedances/Cell13"] = BMS_STATUS['impedances']['cell13_impedance']['value'] BMS_STATUS['impedances']['cell14_impedance']['value'] = get_cell_impedance(ord(packet[33]), ord(packet[34])) - BMS_STATUS['impedances']['cell14_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell14_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell14_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell14_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell14"] = BMS_STATUS['impedances']['cell14_impedance']['text'] dbusservice["/Raw/Impedances/Cell14"] = BMS_STATUS['impedances']['cell14_impedance']['value'] BMS_STATUS['impedances']['cell15_impedance']['value'] = get_cell_impedance(ord(packet[35]), ord(packet[36])) - BMS_STATUS['impedances']['cell15_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell15_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell15_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell15_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell15"] = BMS_STATUS['impedances']['cell15_impedance']['text'] dbusservice["/Raw/Impedances/Cell15"] = BMS_STATUS['impedances']['cell15_impedance']['value'] BMS_STATUS['impedances']['cell16_impedance']['value'] = get_cell_impedance(ord(packet[37]), ord(packet[38])) - BMS_STATUS['impedances']['cell16_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell16_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell16_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell16_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell16"] = BMS_STATUS['impedances']['cell16_impedance']['text'] dbusservice["/Raw/Impedances/Cell16"] = BMS_STATUS['impedances']['cell16_impedance']['value'] @@ -1351,49 +1361,49 @@ def parse_packet(packet): if (packet_length == PACKET_LENGTH_STATUS_IMPEDANCES[2]): # packet from BMS24 BMS_STATUS['impedances']['cell17_impedance']['value'] = get_cell_impedance(ord(packet[39]), ord(packet[40])) - BMS_STATUS['impedances']['cell17_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell17_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell17_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell17_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell17"] = BMS_STATUS['impedances']['cell17_impedance']['text'] dbusservice["/Raw/Impedances/Cell17"] = BMS_STATUS['impedances']['cell17_impedance']['value'] BMS_STATUS['impedances']['cell18_impedance']['value'] = get_cell_impedance(ord(packet[41]), ord(packet[42])) - BMS_STATUS['impedances']['cell18_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell18_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell18_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell18_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell18"] = BMS_STATUS['impedances']['cell18_impedance']['text'] dbusservice["/Raw/Impedances/Cell18"] = BMS_STATUS['impedances']['cell18_impedance']['value'] BMS_STATUS['impedances']['cell19_impedance']['value'] = get_cell_impedance(ord(packet[43]), ord(packet[44])) - BMS_STATUS['impedances']['cell19_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell19_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell19_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell19_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell19"] = BMS_STATUS['impedances']['cell19_impedance']['text'] dbusservice["/Raw/Impedances/Cell19"] = BMS_STATUS['impedances']['cell19_impedance']['value'] BMS_STATUS['impedances']['cell20_impedance']['value'] = get_cell_impedance(ord(packet[45]), ord(packet[46])) - BMS_STATUS['impedances']['cell20_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell20_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell20_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell20_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell20"] = BMS_STATUS['impedances']['cell20_impedance']['text'] dbusservice["/Raw/Impedances/Cell20"] = BMS_STATUS['impedances']['cell20_impedance']['value'] BMS_STATUS['impedances']['cell21_impedance']['value'] = get_cell_impedance(ord(packet[47]), ord(packet[48])) - BMS_STATUS['impedances']['cell21_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell21_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell21_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell21_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell21"] = BMS_STATUS['impedances']['cell21_impedance']['text'] dbusservice["/Raw/Impedances/Cell21"] = BMS_STATUS['impedances']['cell21_impedance']['value'] BMS_STATUS['impedances']['cell22_impedance']['value'] = get_cell_impedance(ord(packet[49]), ord(packet[50])) - BMS_STATUS['impedances']['cell22_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell22_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell22_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell22_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell22"] = BMS_STATUS['impedances']['cell22_impedance']['text'] dbusservice["/Raw/Impedances/Cell22"] = BMS_STATUS['impedances']['cell22_impedance']['value'] BMS_STATUS['impedances']['cell23_impedance']['value'] = get_cell_impedance(ord(packet[51]), ord(packet[52])) - BMS_STATUS['impedances']['cell23_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell23_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell23_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell23_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell23"] = BMS_STATUS['impedances']['cell23_impedance']['text'] dbusservice["/Raw/Impedances/Cell23"] = BMS_STATUS['impedances']['cell23_impedance']['value'] BMS_STATUS['impedances']['cell24_impedance']['value'] = get_cell_impedance(ord(packet[53]), ord(packet[54])) - BMS_STATUS['impedances']['cell24_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell24_impedance']['value']) + "mOhm" + BMS_STATUS['impedances']['cell24_impedance']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['cell24_impedance']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Cell24"] = BMS_STATUS['impedances']['cell24_impedance']['text'] dbusservice["/Raw/Impedances/Cell24"] = BMS_STATUS['impedances']['cell24_impedance']['value'] @@ -1402,63 +1412,63 @@ def parse_packet(packet): # get min/max impedances to calculate the diff cell_impedances = [] - if (BMS_STATUS['impedances']['cell1_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell1_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell1_impedance']['value']) - if (BMS_STATUS['impedances']['cell2_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell2_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell2_impedance']['value']) - if (BMS_STATUS['impedances']['cell3_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell3_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell3_impedance']['value']) - if (BMS_STATUS['impedances']['cell4_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell4_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell4_impedance']['value']) - if (BMS_STATUS['impedances']['cell5_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell5_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell5_impedance']['value']) - if (BMS_STATUS['impedances']['cell6_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell6_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell6_impedance']['value']) - if (BMS_STATUS['impedances']['cell7_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell7_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell7_impedance']['value']) - if (BMS_STATUS['impedances']['cell8_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell8_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell8_impedance']['value']) - if (BMS_STATUS['impedances']['cell9_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell9_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell9_impedance']['value']) - if (BMS_STATUS['impedances']['cell10_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell10_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell10_impedance']['value']) - if (BMS_STATUS['impedances']['cell11_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell11_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell11_impedance']['value']) - if (BMS_STATUS['impedances']['cell12_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell12_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell12_impedance']['value']) - if (BMS_STATUS['impedances']['cell13_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell13_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell13_impedance']['value']) - if (BMS_STATUS['impedances']['cell14_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell14_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell14_impedance']['value']) - if (BMS_STATUS['impedances']['cell15_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell15_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell15_impedance']['value']) - if (BMS_STATUS['impedances']['cell16_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell16_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell16_impedance']['value']) - if (BMS_STATUS['impedances']['cell17_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell17_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell17_impedance']['value']) - if (BMS_STATUS['impedances']['cell18_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell18_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell18_impedance']['value']) - if (BMS_STATUS['impedances']['cell19_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell19_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell19_impedance']['value']) - if (BMS_STATUS['impedances']['cell20_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell20_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell20_impedance']['value']) - if (BMS_STATUS['impedances']['cell21_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell21_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell21_impedance']['value']) - if (BMS_STATUS['impedances']['cell22_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell22_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell22_impedance']['value']) - if (BMS_STATUS['impedances']['cell23_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell23_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell23_impedance']['value']) - if (BMS_STATUS['impedances']['cell24_impedance']['value'] > MIN_CELL_IMPEDANCE): + if (BMS_STATUS['impedances']['cell24_impedance']['value'] >= MIN_CELL_IMPEDANCE): cell_impedances.append(BMS_STATUS['impedances']['cell24_impedance']['value']) BMS_STATUS['impedances']['agg_impedances']['sum']['value'] = sum(cell_impedances) - BMS_STATUS['impedances']['agg_impedances']['sum']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['agg_impedances']['sum']['value']) + "mOhm" + BMS_STATUS['impedances']['agg_impedances']['sum']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['agg_impedances']['sum']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] BMS_STATUS['impedances']['agg_impedances']['max']['value'] = max(cell_impedances) - BMS_STATUS['impedances']['agg_impedances']['max']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['agg_impedances']['max']['value']) + "mOhm" + BMS_STATUS['impedances']['agg_impedances']['max']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['agg_impedances']['max']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] BMS_STATUS['impedances']['agg_impedances']['min']['value'] = min(cell_impedances) - BMS_STATUS['impedances']['agg_impedances']['min']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['agg_impedances']['min']['value']) + "mOhm" + BMS_STATUS['impedances']['agg_impedances']['min']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['agg_impedances']['min']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] BMS_STATUS['impedances']['agg_impedances']['diff']['value'] = BMS_STATUS['impedances']['agg_impedances']['max']['value'] - BMS_STATUS['impedances']['agg_impedances']['min']['value'] - BMS_STATUS['impedances']['agg_impedances']['diff']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['agg_impedances']['diff']['value']) + "mOhm" + BMS_STATUS['impedances']['agg_impedances']['diff']['text'] = "{:.1f}".format(BMS_STATUS['impedances']['agg_impedances']['diff']['value']) + "m" + SPECIAL_DISPLAY_SYMBOLS['ohm'] if args.victron: dbusservice["/Impedances/Sum"] = BMS_STATUS['impedances']['agg_impedances']['sum']['text'] @@ -1599,6 +1609,14 @@ if args.test: for item in BMS_TEST_PACKETS.items(): handle_serial_data(str(item[1])); + # if we registered in testing to dbus, wait until the script is exitted with keyboard interruption + if args.victron: + logging.info("Waiting for keyboard interruption...") + while True: + time.sleep(1) + + + else: if args.victron: gobject.timeout_add(1000, handle_serial_data)