diff --git a/solar_ble.py b/solar_ble.py index 4403fef..15337d4 100755 --- a/solar_ble.py +++ b/solar_ble.py @@ -161,6 +161,12 @@ CMD_ = b"\xff\x78\x00\x00\x00\x01" STATUS = {} +def parse_temperature(bin): + if bin & 0x80: + return (bin & 0x7F) * -1 + return bin & 0x7F + + # GET_BATTERY_STATE def parse_battery_state(data: bytes) -> dict: res = dict( @@ -175,13 +181,15 @@ def parse_battery_state(data: bytes) -> dict: "load_current", "load_power", ), - struct.unpack("!HHHbbHHH", data), + struct.unpack("!HHHBBHHH", data), ) ) res["battery_voltage"] /= 10 res["battery_current"] /= 100 res["load_voltage"] /= 10 res["load_current"] /= 100 + res["_internal_temperature?"] = parse_temperature(res["_internal_temperature?"]) + res["battery_temperature"] = parse_temperature(res["battery_temperature"]) STATUS.update(res) log(str(res)) @@ -246,7 +254,7 @@ def parse_packet(data): def readMemory(fh: RawIOBase, address: int, words: int = 1): - log(f"Reading {words} words from 0x{address:04X}") + # log(f"Reading {words} words from 0x{address:04X}") write(fh, construct_request(address, words=words)) header = fh.read(3) if header and len(header) == 3: