This commit is contained in:
David Rice
2026-06-17 14:41:43 +02:00
parent fdbbc98088
commit 1aa81e6758
7 changed files with 146 additions and 41 deletions

View File

@@ -30,14 +30,16 @@ IMX8_IP = "10.32.34.103"
IMX8_URL = f"http://{IMX8_IP}:5000"
BLE_MAC = "B0:D2:78:5C:20:07"
BLE_CHAR = "0000fff2-0000-1000-8000-00805f9b34fb"
BLE_CHAR = "0000fff2-0000-1000-8000-00805f9b34fb"
BLE_WAKE_CHAR = "0000fff1-0000-1000-8000-00805f9b34fb"
BLE_WAKE_CMD = bytes([0xD5, 0xFC, 0x11, 0x0D]) # from Meterbox logcat
# ── Test sequence — edit as required ─────────────────────────────────────────
_FREQS = [100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000,
8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000]
TEST_STEPS = [
{"freq": freq, "vol": round(vol / 10, 1), "duration": 5.0}
{"freq": freq, "vol": round(vol / 10, 1), "duration": 10.0}
for freq in _FREQS
for vol in range(0, 11) # 0% → 100% in 10% steps
]
@@ -76,11 +78,26 @@ def _http_stop() -> dict:
# ── Main test runner ──────────────────────────────────────────────────────────
async def run_test():
readings: list[float] = []
_buf = bytearray()
def on_notify(_sender, data: bytearray):
db = _parse_db(data)
if db is not None:
readings.append(db)
nonlocal _buf
_buf.extend(data)
# reassemble: packets are always 11 bytes starting with D5 F0
while len(_buf) >= 11:
idx = bytes(_buf).find(b'\xd5\xf0')
if idx == -1:
_buf.clear()
break
if idx > 0:
del _buf[:idx] # discard garbage before header
if len(_buf) < 11:
break
packet = bytes(_buf[:11])
del _buf[:11]
db = _parse_db(packet)
if db is not None:
readings.append(db)
print(f"Connecting to BLE {BLE_MAC}")
async with BleakClient(BLE_MAC, timeout=15.0) as client:
@@ -91,8 +108,12 @@ async def run_test():
props = ','.join(ch.properties)
print(f" CHAR {ch.uuid} [{props}]")
# Wake-up sequence: write D5 FC 11 0D before subscribing (from Meterbox logcat)
await client.write_gatt_char(BLE_WAKE_CHAR, BLE_WAKE_CMD, response=True)
print(f"Wake-up sent: {BLE_WAKE_CMD.hex(' ')}")
await client.start_notify(BLE_CHAR, on_notify)
print(f"\nSubscribed to {BLE_CHAR}\n")
print(f"Subscribed to {BLE_CHAR}\n")
with CSV_FILE.open('w', newline='') as f:
writer = csv.writer(f)