add a bluetooth logging script
This commit is contained in:
34
scripts/log_data.py
Normal file
34
scripts/log_data.py
Normal 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()
|
Reference in New Issue
Block a user