From 3c1c3ed4324d5b8315de93dfb7a0645bb1138dd5 Mon Sep 17 00:00:00 2001 From: matt Date: Wed, 14 Oct 2026 06:51:04 -0700 Subject: [PATCH] remove tre from scanner.py, add test routine --- api/app.py | 4 ++-- api/ble.py | 17 ++++++++--------- api/scanner.py | 8 ++------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/api/app.py b/api/app.py index 7994364..1710d51 100644 --- a/api/app.py +++ b/api/app.py @@ -27,8 +27,8 @@ def ble_scan_job(): run_counter = run_counter + 1 """Runs in the background, calls the async scanner.""" update_cache() - #if run_counter > 9: - # run_command + if run_counter > 9: + run_counter = 0 # --- API ------------------------------------------------------------- diff --git a/api/ble.py b/api/ble.py index 8e44a74..30a924a 100644 --- a/api/ble.py +++ b/api/ble.py @@ -32,11 +32,10 @@ from bleak import BleakClient, BleakScanner MI_SERVICE_UUID = "ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6" TEMP_CHAR_UUID = "ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6" -SCAN_TIMEOUT = 5.0 # seconds to scan for each MAC -CONNECT_TIMEOUT = 10.0 -READ_TIMEOUT = 2.0 -SERVICE_DISCOVERY_TIMEOUT = 5.0 -_lock = asyncio.Lock() +SCAN_TIMEOUT = 10.0 # seconds to scan for each MAC +CONNECT_TIMEOUT = 20.0 +READ_TIMEOUT = 5.0 +SERVICE_DISCOVERY_TIMEOUT = 10.0 # --------------------------------------------------------------------------- # # Logging @@ -192,10 +191,9 @@ def read_data_sync(mac: str) -> Optional[SensorReading]: # --------------------------------------------------------------------------- # -# Original helper functions - unchanged +# Original helper functions # --------------------------------------------------------------------------- # def sensor_data_query(mac_list: List[str]) -> List[dict]: - """Legacy function; returns a list of dicts like the original code.""" result = [] for mac in mac_list: try: @@ -212,7 +210,6 @@ def sensor_data_query(mac_list: List[str]) -> List[dict]: def test(test_count = 0) -> None: - """Legacy test harness - identical to your original script.""" # first test scanner test_loop_count = 0 found_macs = scan_macs() @@ -226,7 +223,9 @@ def test(test_count = 0) -> None: "A4:C1:38:24:15:B0", "A4:C1:38:D7:8D:26", ] - + print("Testing concurrent scan...") + multi_test_results = read_multiple(mac_list) + print(json.dumps(multi_test_results, indent=2)) print("Starting BLE test...") print(" Scanning MACs:") for mac in mac_list: diff --git a/api/scanner.py b/api/scanner.py index d381ac4..a19aec5 100644 --- a/api/scanner.py +++ b/api/scanner.py @@ -71,7 +71,6 @@ load_state() r = redis.Redis(host=bind_ip, port=redis_port) def update_redis(data): - # push data to redis # Publish to the Redis channel that the WS server is listening on r.publish('temp_hum', json.dumps(data)) if debug_output: @@ -89,11 +88,8 @@ def update_cache() -> None: # now that we have MACs, let's get sensor data print("Updating sensor data...") sensor_data = None - try: - sensor_data = sensor_data_query(new_macs) - # print(sensor_data) - except Exception as e: - print(f"Aww fuck, no data :( - {e}") + sensor_data = sensor_data_query(new_macs) + # print(sensor_data) # now we update the data in the sensor objects print("Sensor data collected:") for sensor_datum in sensor_data: