Skip to content

Instantly share code, notes, and snippets.

@sjc
Created January 12, 2014 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjc/8386438 to your computer and use it in GitHub Desktop.
Save sjc/8386438 to your computer and use it in GitHub Desktop.
Python script for starting (and configuring) and stopping a BlueZ Bluetooth LE process acting as an iBeacon
#!/usr/bin/python
import argparse
from subprocess import call
# set your default proximity UUID here for hasle-free invocation
uuid = ""
# set up what commandline arguments we accept and parse them
parser = argparse.ArgumentParser()
parser.add_argument("do", choices=[ "start", "stop" ])
parser.add_argument("-u", "--uuid", help="proximity UUID, a quoted string of 16 hex bytes", default=uuid)
parser.add_argument("-j", "--major", help="proximity UUID, a quoted string of 2 hex bytes", default="00 00")
parser.add_argument("-i", "--minor", help="proximity UUID, a quoted string of 2 hex bytes", default="00 00")
parser.add_argument("-d", "--device", help="the bluetooth device", default="hci0")
parser.add_argument("-s", "--strength", help="signal strength, a quoted string of 2 hex bytes", default="c5 00")
parser.add_argument("-v", "--verbose", help="print extending information", action="store_true", default=False)
args = parser.parse_args()
if args.do == "stop":
call(["sudo", "hciconfig", args.device, "noleadv"])
else:
call(["sudo", "hciconfig", args.device, "up"])
call(["sudo", "hciconfig", args.device, "noleadv"])
call(["sudo", "hciconfig", args.device, "leadv", "3"])
params = ["sudo", "hcitool", "-i", args.device, "cmd", "0x08", "0x0008", "1e", "02", "01", "1a", "1a", "ff", "4c", "00", "02", "15"]
params.extend(args.uuid.split(' '))
params.extend(args.major.split(' '))
params.extend(args.minor.split(' '))
params.extend(args.strength.split(' ')) #)
call(params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment