Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
PIBeacon/PIBeacon.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
31 lines (23 sloc)
774 Bytes
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
#!/bin/bash | |
set -e | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
if [[ $# -ne 3 ]]; then | |
echo "Incorrect number of arguments" | |
exit 1 | |
fi | |
UUID=$(python3 -c "import uuid; hexstring=uuid.UUID(\"$1\").hex.upper(); print(' '.join([hexstring[i:i+2] for i in range(0, len(hexstring), 2)]))") | |
MAJOR=$(printf '%x' $2) | |
MINOR=$(printf '%x' $3) | |
# Ensure that the bluetooth adapter is running | |
if [[ ! $(hciconfig hci0 | grep "UP RUNNING") ]]; then | |
hciconfig hci0 up | |
fi | |
# Enable non connectable undirected advertising | |
hciconfig hci0 leadv 3 | |
# Disable scanning | |
hciconfig hci0 noscan | |
# Initialise the beacon with the given uuid, major and minor | |
hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 $UUID 00 $MAJOR 00 $MINOR C8 00 |