Raspberry Pi iBeacon in under 30 seconds

Moderator: leecollings

Post Reply
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Raspberry Pi iBeacon in under 30 seconds

Post 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.

:)
Last edited by ben53252642 on Sunday 07 August 2016 18:46, edited 2 times in total.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post 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.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
User avatar
gizmocuz
Posts: 2541
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post by gizmocuz »

What would you like todo with an iBeacon?
Quality outlives Quantity!
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post 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.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post 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.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
User avatar
gizmocuz
Posts: 2541
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post 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 ?
Quality outlives Quantity!
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post 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
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
patoo77
Posts: 297
Joined: Thursday 17 July 2014 18:20
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Paris, France
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post 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
User avatar
gizmocuz
Posts: 2541
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post by gizmocuz »

Or the IFTTT, with a geo location
Quality outlives Quantity!
MrGee
Posts: 10
Joined: Thursday 04 September 2014 16:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5837
Location: NL
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post 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
User avatar
gizmocuz
Posts: 2541
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post 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 ;)
Quality outlives Quantity!
pvm
Posts: 550
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: 4.10538
Location: NL
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post by pvm »

I implemented the scenario using a Fibaro eye detecting motion and delayed turn off (and some blockly).
Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
User avatar
gizmocuz
Posts: 2541
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post by gizmocuz »

Yep, that's what i said in my second reply "Could a PIR not also do the trick ?"
Quality outlives Quantity!
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Raspberry Pi iBeacon in under 30 seconds

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest