yash012
Posts: 12
Joined: Thu Mar 09, 2017 12:08 pm

ibeacon detection

Fri Mar 10, 2017 5:18 am

Hi i'm new here i am working on a project , i need to detect a ibeacon on Raspberry pi 3 .
it is detected and i can see the MAC address well in Terminal using Bluetooth scan on command but i want to do that in python ,
i used this:

Code: Select all

nearby_devices = bluetooth.discover_devices(lookup_names = True)
but in output it only shows other Bluetooth device, ibeacon is not detected.
can anyone help me on this.

PiGraham
Posts: 3671
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: ibeacon detection

Fri Mar 10, 2017 6:29 am

This is new to me, but interesting. I found this page.
https://en.wikipedia.org/wiki/IBeacon#Technical_details

I seems an ibeacon is not like a regular BT device. Its not pairable.
That page lists an hcitool command that you try.

yash012
Posts: 12
Joined: Thu Mar 09, 2017 12:08 pm

Re: ibeacon detection

Fri Mar 10, 2017 11:03 am

thanks but it is not very useful as i need to detect ibeacon using python in Raspberry pi.

User avatar
topguy
Posts: 5967
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: ibeacon detection

Fri Mar 10, 2017 11:41 am

In the Bluetooth standard, and in the chipsets, scanning for classic bluetooth devices and BLE devices ( which a beacon is ) is two different things.

Find a Python module with BLE support or use a different method if the module you are using claims to have BLE support.

PiGraham
Posts: 3671
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: ibeacon detection

Fri Mar 10, 2017 11:48 am

yash012 wrote:thanks but it is not very useful as i need to detect ibeacon using python in Raspberry pi.
It tells you what you have to do, what commands you have to send to scan for beacons. You can do all that from Python with system or process calls, or you can look for a Python module that handles those messages. Either way, if you read that page you should know more about what you have to do than you did before.

Even if you only used that info to check that your system can see beacons from command line you have a win. It's a very useful test of the hardware / system config.

User avatar
Paul Webster
Posts: 812
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
Contact: Twitter

Re: ibeacon detection

Fri Mar 10, 2017 1:09 pm

You could try this - from 2014 (so check around for updates and alternative routes) ... it includes doing it from Python
http://www.switchdoc.com/2014/08/ibeaco ... er-python/

yash012
Posts: 12
Joined: Thu Mar 09, 2017 12:08 pm

Re: ibeacon detection

Sat Mar 11, 2017 6:49 am

PiGraham wrote:
yash012 wrote:thanks but it is not very useful as i need to detect ibeacon using python in Raspberry pi.
It tells you what you have to do, what commands you have to send to scan for beacons. You can do all that from Python with system or process calls, or you can look for a Python module that handles those messages. Either way, if you read that page you should know more about what you have to do than you did before.

Even if you only used that info to check that your system can see beacons from command line you have a win. It's a very useful test of the hardware / system config.
Thanks you are right about that i did got a lot of information about ibeacon , i am able to do that in terminal using command i just now need to figure out a way to do that in Python.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: ibeacon detection

Sat Mar 11, 2017 11:55 am


yash012
Posts: 12
Joined: Thu Mar 09, 2017 12:08 pm

Re: ibeacon detection

Sun Mar 12, 2017 5:40 pm

Thank you very much this is very much helpful.

yash012
Posts: 12
Joined: Thu Mar 09, 2017 12:08 pm

Re: ibeacon detection

Tue Mar 14, 2017 12:13 pm

i used the bluepy for detection of BLE devices , the command

Code: Select all

sudo hcitool lescan
works very well but whenever i tried to call that in python using

Code: Select all

BLE = subprocess.getoutput('sudo hcitool lescan')
it always shows me
Set scan parameters failed: Input/output error
, i tried restarting Bluetooth, but problem still remains.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: ibeacon detection

Tue Mar 14, 2017 2:10 pm

Even if using subprocess correctly, that is

Code: Select all

ble = subprocess. check_output(['sudo', 'hcitool', 'lescan'])
you'll run into the fact that lescan runs indefinitely, and that line will never return.

PiGraham
Posts: 3671
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: ibeacon detection

Tue Mar 14, 2017 2:19 pm

This may help
After spending a few hours working this out, I came up with this solution. The problem with hcitool lescan is that it doesn't return until it receives a SIGINT, so we send it one with Python:

Code: Select all

    bashCommand = "hcitool lescan"
    process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
    time.sleep(3)
    os.kill(process.pid, signal.SIGINT)
    output = process.communicate()[0].
This for me returned a string containing all of the mac addresses found, after a 3 second search
http://stackoverflow.com/questions/2687 ... -to-a-file

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: ibeacon detection

Tue Mar 14, 2017 2:31 pm

Thanks for that, PiGraham. Crude, but effective.

yash012
Posts: 12
Joined: Thu Mar 09, 2017 12:08 pm

Re: ibeacon detection

Wed Mar 15, 2017 5:09 am

Thanks this is good, it seems that this would work very well.

yash012
Posts: 12
Joined: Thu Mar 09, 2017 12:08 pm

Re: ibeacon detection

Thu Mar 16, 2017 11:03 am

i have been trying to figure out this issue but nothing seems to work , it seems that

Code: Select all

hcitool lescan
only works in terminal , it seems that it keeps running until interrupted cltr+c , well

Code: Select all

 timeout 10s hcitool lescan
helps there in the terminal but it does not work when i try to call it in python.i tried all the suggestions in the link http://stackoverflow.com/questions/2687 ... -to-a-file i also tried bluez which is very convenient for use in Terminal but in that also after passing $ bluetoothctl , terminal goes from [email protected]:~$ to [bluetooth]#.

PiGraham
Posts: 3671
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: ibeacon detection

Thu Mar 16, 2017 1:58 pm

yash012 wrote:i have been trying to figure out this issue but nothing seems to work , it seems that

Code: Select all

hcitool lescan
only works in terminal , it seems that it keeps running until interrupted cltr+c
That's what

Code: Select all

os.kill(process.pid, signal.SIGINT)
does, sends Ctrl-C to the process (Ctrl-C sends SIGINT).

yash012
Posts: 12
Joined: Thu Mar 09, 2017 12:08 pm

Re: ibeacon detection

Thu Mar 16, 2017 4:15 pm

PiGraham wrote:
yash012 wrote:i have been trying to figure out this issue but nothing seems to work , it seems that

Code: Select all

hcitool lescan
only works in terminal , it seems that it keeps running until interrupted cltr+c
That's what

Code: Select all

os.kill(process.pid, signal.SIGINT)
does, sends Ctrl-C to the process (Ctrl-C sends SIGINT).
i learned that but it did't seem to work , there must be something i am missing i will keep working on it.Thank you all for the suggestions i would like to say that i have started working on Raspberry pi recently, there is so for me to learn , this forum has been very helpful for me.

Return to “General discussion”