diff --git a/solar_ble.py b/solar_ble.py index 2232ae6..4e264fe 100755 --- a/solar_ble.py +++ b/solar_ble.py @@ -252,8 +252,8 @@ def construct_request(address, words=1, action=ACTION_READ, marker=0xFF): return struct.pack("!BBHH", marker, action, address, words) -def log(message: object): - print(datetime.datetime.utcnow().isoformat(" "), message) +def log(*message: object): + print(datetime.datetime.utcnow().isoformat(" "), *message) sys.stdout.flush() @@ -346,13 +346,19 @@ if __name__ == "__main__": # CMD_GET_BATTERY_STATE + CMD_GET_PANEL_STATUS res = readMemory(dev, 0x0100, 11) if res: - d = parse_battery_state(res) - log(d) + try: + d = parse_battery_state(res) + log(d) + except struct.error: + log("0x0100 Unpack error:", res) if per_current_hist(now): res = readMemory(dev, 0x010B, 21) if res: - d = parse_historical_entry(res) - log(d) + try: + d = parse_historical_entry(res) + log(d) + except struct.error: + log("0x010B Unpack error:", res) # print(".") time.sleep(1)