Last active
October 21, 2019 20:59
-
-
Save atx/7d5e2415dc4925c3b3ee776bd7f14571 to your computer and use it in GitHub Desktop.
Hacky way of displaying headset battery level by sniffing the raw bluetooth traffic and dumping it to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import argparse | |
import pathlib | |
import pyshark | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-o", "--output", type=lambda s: pathlib.Path(s).expanduser(), required=True) | |
parser.add_argument("-i", "--interface", default="bluetooth0") | |
args = parser.parse_args() | |
# TODO: MAC address filtering | |
shark = pyshark.LiveCapture( | |
interface=args.interface, | |
display_filter='bthsp.at_cmd == "+XEVENT" and bthsp.parameter == "BATTERY"' | |
) | |
for packet in shark.sniff_continuously(): | |
field = packet.bthsp.parameter.fields[1] | |
# TODO: Maybe make this atomic? | |
args.output.write_text(field.show) | |
print("RX:", packet.bthsp.data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment