diff --git a/api/ble.py b/api/ble.py index 1500f21..60ecd01 100644 --- a/api/ble.py +++ b/api/ble.py @@ -221,9 +221,11 @@ def read_data_sync(mac: str) -> Optional[SensorReading]: # Other helper functions # --------------------------------------------------------------------------- # def reset_adapter(): + log.info("Restting BT Adapter...") subprocess.run(["sudo", "rfkill", "block", "bluetooth"], check=True) subprocess.run(["sudo", "rfkill", "unblock", "bluetooth"], check=True) time.sleep(5) + log.info("Reset complete. ") def sensor_data_query(mac_list: List[str]) -> List[dict]: reset_adapter() @@ -235,6 +237,7 @@ def sensor_data_query(mac_list: List[str]) -> List[dict]: print(f"Error reading BLE data - {e}") this_result = None if "org.freedesktop.DBus.Error.AccessDenied" in e: + reset_adapter() return result if this_result: result.append( @@ -315,4 +318,5 @@ if __name__ == "__main__": try: test(test_count) except Exception as e: - print(f"Test failed brah - {e}") \ No newline at end of file + print(f"Test failed brah - {e}") + reset_adapter()