Page 1 of 1

Raspberry Pi iBeacon in under 30 seconds

Posted: Sunday 07 August 2016 13:40
by ben53252642
Hi Folks,

I spent about 10 hours figuring out how to do this and put together a simple 30 second guide to setting up an iBeacon (which runs automatically on boot) on Raspberry Pi (although this should work for other Linux systems as well)

Here goes:

nano /etc/init.d/ibeacon

Paste the contents of this:

Code: Select all

#!/bin/bash
### BEGIN INIT INFO
# Provides: ibeacon
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 5
# Default-Stop:
# Description: ibeacon
### END INIT INFO

case "$1" in
'start')
        bluetoothadapter="hci0"
        ogf="0x08"
        ocf="0x0008"
        ibeaconprefix="1e 02 01 1a 1a ff 4c 00 02 15"
        uuid="5A 4B CF CE 17 4E 4B AC A8 14 09 2E 77 F6 B7 E5"
        major="00 08"
        minor="00 05"
        power="C8 00"
        /bin/echo "Starting iBeacon..."
        sleep 5
        /bin/hciconfig "$bluetoothadapter" up
        /bin/hciconfig "$bluetoothadapter" noleadv
        /bin/hciconfig "$bluetoothadapter" noscan
        /bin/hciconfig "$bluetoothadapter" pscan
        /bin/hciconfig "$bluetoothadapter" leadv 3
        /usr/bin/hcitool -i "$bluetoothadapter" cmd $ogf $ocf $ibeaconprefix $uuid $major $minor $power
        ;;
'stop')
        /bin/echo "Stopping iBeacon..."
        /bin/hciconfig "$bluetoothadapter" noleadv
        /bin/hciconfig "$bluetoothadapter" down
        ;;
*)
        echo "Usage: $0 { start | stop }"
        ;;
esac
exit 0
Run these two commands:
chmod 755 /etc/init.d/ibeacon
update-rc.d ibeacon defaults

Reboot the Raspberry Pi and you should have a broadcasting iBeacon within about 30 seconds of it booting up.

I use an iPhone app called Dartle to see if its broadcasting.

iPhone app Pilot for Domoticz can make use of iBeacons.

Please note that changing the UUID in my experience seems to result in the iPhone not detecting the iBeacon, only certain UUID's appear to be accepted. To make it unique you can change the minor and major numbers.

:)

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Sunday 07 August 2016 13:53
by ben53252642
Gizmocus if you see this, I'm wondering how difficult it would be to add a broadcast an iBeacon tick box within Domoticz hardware?

The code to start an iBeacon can be reduced to a single line.

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Sunday 07 August 2016 14:11
by gizmocuz
What would you like todo with an iBeacon?

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Sunday 07 August 2016 14:21
by ben53252642
Pilot app for Domoticz has the ability to turn devices on and off if it comes in range of an iBeacon.

Personally I prefer the l2ping method for detecting if my phone is in range but I figured since I found out how to do it, may as well post it.

iBeacon is useful cause iPhones specifically listen for them and it's possible to judge the iPhones distance from the beacon.

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Sunday 07 August 2016 14:44
by ben53252642
Actually you know what would be really cool?

A dedicated "I'm home" iPhone app, that turns on a single Domoticz device the second it spots an iBeacon.

It could do that via calling a HTTP url making it compatible with virtually every home automation system.

If iBeacon detected = httpget this URL

Another option instead of the l2ping method.

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Sunday 07 August 2016 16:05
by gizmocuz
Sounds nice indeed... but can you differentiate rooms ? like rooms next to each other ? with a wall from 10cm in between ?
Could a PIR not also do the trick ?

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Sunday 07 August 2016 16:41
by ben53252642
Gizmocus the iPhone can detect down to about 30cm its distance from the beacon, its very accurate.

I have setup more than one at a time for testing around my apartment, although it's best to use a different UUID for a seperate iBeacon.

Here is a list of UUID's

https://github.com/seboslaw/iBeacon-UUID-Repository

Actually Gizmocus you just gave me another idea...

I see no reason why this iPhone app couldn't allow more than 1 HTTPGET url if it detects x iBeacon UUID. :D

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Tuesday 09 August 2016 17:58
by patoo77
ben53252642 wrote:Actually you know what would be really cool?

A dedicated "I'm home" iPhone app, that turns on a single Domoticz device the second it spots an iBeacon.

It could do that via calling a HTTP url making it compatible with virtually every home automation system.

If iBeacon detected = httpget this URL

Another option instead of the l2ping method.
Isn't it what Pilot is already doing?
If you have any request to improve the way I implemented it, I'd be more than happy to help ;)
Let me know

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Tuesday 09 August 2016 18:14
by gizmocuz
Or the IFTTT, with a geo location

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Thursday 18 August 2016 13:48
by MrGee
gizmocuz wrote:Or the IFTTT, with a geo location
iBeacons are more accurate & localized
you could for example have one in the living room and another in the kitchen
It would then be possible to automatically lower the light in the kitchen when you walk (with your phone) to the living-room

I actually plan to do something similar in the bedroom for an automatic "night mode"
ben53252642 wrote:Hi Folks,
Please note that changing the UUID in my experience seems to result in the iPhone not detecting the iBeacon, only certain UUID's appear to be accepted. To make it unique you can change the minor and major numbers.

:)

Thanks Ben, this looks awesome
do you know how to change the transmitting power?
this to make sure the iBeacons are not overlapping (each other or rooms)
I noticed power="C8 00" in the script must be some HEX code

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Thursday 18 August 2016 16:11
by gizmocuz
It would then be possible to automatically lower the light in the kitchen when you walk (with your phone) to the living-room
doesn't that mean it needs to constantly be in communication ? Sending real-time info ?
If yes, that would cost a lot of battery ;)

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Sunday 21 August 2016 10:21
by pvm
I implemented the scenario using a Fibaro eye detecting motion and delayed turn off (and some blockly).

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Sunday 21 August 2016 10:34
by gizmocuz
Yep, that's what i said in my second reply "Could a PIR not also do the trick ?"

Re: Raspberry Pi iBeacon in under 30 seconds

Posted: Friday 26 August 2016 22:18
by simon_rb
Just used this and worked flawlessly on my Pi3! Thanks

Could be handy if iBeacon could be added to hardware as it could switch on/off switch when your home/away. Would cut out the middle man app.