Turn a Raspberry Pi Into Bluetooth Beacon
by bleuio in Circuits > Gadgets
1001 Views, 2 Favorites, 0 Comments
Turn a Raspberry Pi Into Bluetooth Beacon
Bluetooth is one of the innovative technology to transfer data wirelessly, build home automation systems, control other devices etc.
In this instructables, I will try to turn a Raspberry Pi into Bluetooth Beacon.
Requirements
- Raspberry Pi
- BleuIO (A Bluetooth low energy USB Dongle)
- A Mobile Phone with Bluetooth and an App such as BLE Scanner, LightBlue or DSPS from Dialog Semiconductor.
Connect the Dongle
Connect the BleuIO dongle to your Raspberry Pi.
To identify which device name the dongle is connected to, you will need to run:
ls /dev
You might need to do it twice, once before you connect the dongle and once after to be able to identify which one is the device name. When starting up, the dongle will open up a COM port for the bootloader for 10 seconds to allow you to update the firmware (or flash your own application).
Afterwards it will close that port and open a new port for the BleuIO application which is the one we’re interested in here. You can run:
lsusb
Serial Communication
You will need a serial communication program to communicate with the dongle. For this tutorial we will be using Minicom. You can get Minicom by running:
sudo apt-get install minicom
Now, to start using the dongle run the following command if, for example, your dongle is connected to the device name ttyACM0:
minicom -b 9600 -o -D /dev/ttyACM0
Now try typing an AT-Command. For example
AT
If you get an OK response that means the dongle is working.
Run Python Script
We have a python script ready to help turn this Raspberry Pi into Bluetooth Beacon.
To use these scripts you will need to have Python installed.
ou will also need to install the module pySerial. The easiest way to install it is through pip (which you should already have after installing Python) by running:
Python2:
pip install pyserial
Python3:
python3 -m pip install pyserial
After connecting, you can use the example sample python script to set up your own iBeacon.
the source code can be found on GitHub.
Save this script into a file called ibeacon.py or you can name anything you like.
Now open the file using a command prompt by typing
python ibeacon.py
Scan Your Device
When you start the Python script, you should be able to see your iBeacon using a scanner App designed for Bluetooth Low Energy (BLE).
Examples of scanner App can be BLE Scanner from Bluepixel Technologies.
Here you can see , your device has started advertising.
You can also use Eddystone script.Source code available here.