Created
September 16, 2018 18:22
-
-
Save dkarchmer/c1dbe040ab7e9c1c8d814beef3c9dc6c to your computer and use it in GitHub Desktop.
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
import argparse | |
import time | |
import sys | |
from iotile.core.hw import HardwareManager | |
def build_parser(): | |
parser = argparse.ArgumentParser(description="Print broadcast readings from a specific device") | |
parser.add_argument('-d', '--dev', type=lambda x: int(x, 0), help="Optional, the UUID of the device you want to see broadcasts from (0x21 for example)") | |
parser.add_argument('-i', '--interval', type=float, default=1.0, help="The minimum interval in seconds between two reported readings (only applies when -d is given), defaults to 1s") | |
parser.add_argument('-p', '--port', default="bled112", help="The port to use, defaults to bled112") | |
return parser | |
def main(): | |
parser = build_parser() | |
args = parser.parse_args() | |
with HardwareManager(port=args.port) as hw: | |
hw.enable_broadcasting() | |
while True: | |
found_reading = False | |
for report in hw.iter_broadcast_reports(blocking=False): | |
print(report) | |
if args.dev is not None and report.origin != args.dev: | |
continue | |
if not (args.dev and found_reading): | |
reading = report.visible_readings[0] | |
print("%04X: %d" % (reading.stream, reading.value)) | |
found_reading = True | |
time.sleep(args.interval) | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment