add a bluetooth logging script
Some checks failed
Build / build (ubuntu-22.04) (push) Failing after 2m9s
Documentation / build (push) Successful in 27s

This commit is contained in:
2024-07-05 01:32:48 -06:00
parent e42be00205
commit 321fadf77e

34
scripts/log_data.py Normal file
View File

@ -0,0 +1,34 @@
import asyncio
import struct
import numpy as np
from bleak import BleakClient
from matplotlib import pyplot as plt
address = "65:72:31:D7:E2:12"
MODEL_NBR_UUID = "2A24"
batt = []
async def main(address):
async with BleakClient(address) as client:
model_number = await client.read_gatt_char(MODEL_NBR_UUID)
print("Model Number: {0}".format("".join(map(chr, model_number))))
while True:
# batt.append(ord(await client.read_gatt_char("2A19")))
batt.append(struct.unpack("b", (await client.read_gatt_char("2A19")))[0])
print(batt[-1])
try:
asyncio.run(main(address))
except KeyboardInterrupt:
changed = np.diff(batt) != 0
print(
f"{np.sum(changed)} changes (seconds) in {len(changed)} samples ({len(changed) / np.sum(changed)} samples per second)"
)
plt.plot(batt)
plt.show()
plt.show()