-
-
Save MartinSadovy/994085df49b100110e3150a626d1258e to your computer and use it in GitHub Desktop.
Init script for iBeacon
This file contains hidden or 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/sh | |
### BEGIN INIT INFO | |
# Provides: blebeacon | |
# Required-Start: $bluetooth | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# X-Interactive: true | |
# Short-Description: Start/stop Bluetooth iBeacon | |
### END INIT INFO | |
# Init script for starting an iBeacon | |
# | |
# Thanks to http://developer.radiusnetworks.com/2013/10/09/how-to-make-an-ibeacon-out-of-a-raspberry-pi.html | |
# | |
# Author Gabriel Birke <[email protected]> | |
BLUETOOTH_DEVICE=hci0 | |
UUID="62 0E 34 5D 69 62 43 8F 99 45 59 DD B4 83 0C 18" | |
MAJOR="00 00" | |
MINOR="00 00" | |
POWER="c5" | |
BYTE_SEQ=$(wget http://192.168.3.20:81/ble.php --timeout=2 --tries=1 -qO-) | |
if [ "$BYTE_SEQ" == "" ]; then | |
BYTE_SEQ="1e 02 01 1a 1a ff 4c 00 02 15 $UUID $MAJOR $MINOR $POWER 00"; | |
fi | |
HCITOOL=/usr/bin/hcitool | |
HCICONFIG=/bin/hciconfig | |
LOG=/dev/null | |
start() { | |
sleep 10 | |
$HCICONFIG $BLUETOOTH_DEVICE up | |
$HCICONFIG $BLUETOOTH_DEVICE noleadv | |
$HCITOOL -i $BLUETOOTH_DEVICE cmd 0x08 0x0008 $BYTE_SEQ > $LOG | |
$HCICONFIG $BLUETOOTH_DEVICE leadv 3 | |
echo "A" | |
} | |
stop() { | |
$HCICONFIG $BLUETOOTH_DEVICE noleadv | |
$HCICONFIG $BLUETOOTH_DEVICE down | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart}" | |
esac |
This file contains hidden or 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
cat blebeacon.sh > /etc/init.d/blebeacon | |
chmod 0755 /etc/init.d/blebeacon | |
update-rc.d blebeacon defaults |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment