Distance Measuring Solution for COVID-19 using Bluetooth Low Energy

As the coronavirus pandemic continues, we’ve seen several social distancing, and contact tracing solution came in the market to stop the spread. Employers and businesses will want new devices to help keep social distancing when people return to work. In this case, Bluetooth technologies can be very useful.

When a Bluetooth device connects to another Bluetooth enabled device, it measures the signal strength as RSSI ( received signal strength indicator). The connection strength depends on the distance between the devices — The connection will be strong if two devices are nearby. As the device move apart, the connection weakens.

It is also possible to scan for nearby devices and read the RSSI value without establishing a connection, this makes it very suitable for looking after nearby devises as majority of people carries a smartphone with Bluetooth on.

BLE Measures Distance in 3 ways

Following are the three primary approaches to measure distance using BLE:

BLE RSSI (received signal strength indicator) Alone

This solution uses (Bluetooth Low Energy) BLE Received Signal Strength Indication (RSSI) to measure the distance between the receiver and the transmitter (scanner and advertising device) .

It is possible to increase accuracy by repeatedly scan the RSSI values and create an average over a fixed determined period.

Image for post

BLE with Ultra-wideband (UWB)

Another likely option is the combination of BLE with Ultra-wideband (UWB). UWB is a low energy radiofrequency technology that can transmit short-range, high bandwidth messages over the radio spectrum. UWB is best suited for location tracking, data collection and short-range indoor application. Combining UWB with RSSI helps get highly accurate measurements, but it has a higher BOM (bill of materials) cost due to the UWB chip.

BLE Based Proprietary Distance Measurement Technologies

BLE-based proprietary technologies can add distance measurement capabilities which makes it more accurate. It can combine Bluetooth LE data packets with constant tone frequency exchanges in order to generate the strong signals needed for more precise ranging. This technology can also be more accurate than RSSI alone and BLE with Ultra-wideband.

Developers can use smartphones Bluetooth technology that is already installed in the devices to perform contact tracing, but this approach has some problems related to privacy. Therefore, a BLE device that does not require any information from users is the right solution. For instance, BleuIO can be used to measure the distance without having to worry about privacy and security. The BleuIO is Bluetooth low energy solution that can be used to create new BLE 5.0 applications in the fastest and easiest way. Just use the AT Commands available on the device. Details about the AT commands will be found on getting started guide which will help anyone make a fast peripheral or central application (or both), on an incredibly low power platform without having to develop a single line of embedded code.

We have created a sample project on Get Bluetooth Device Distance Using BleuIO.

The device can be bought from https://www.bleuio.com/, and it will only cost $15.99.

Share this post on :

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 tutorial, we will learn about how to turn a Raspberry Pi into Bluetooth Beacon.

Requirements

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
Image for post

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). You can update the firmware from here. Afterwards it will close that port and open a new port for the Smart USB Dongle 2.0 application which is the one we’re interested in here. You can run:

lsusb

It should list a device with the ID: 2dcf:6001 when the bootloader is active but change to 2dcf:6002 after 10 seconds when the application is running.

NOTE: The device name may vary and may not be the same as in the picture above.

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
Image for post

Now try typing an AT-Command. For example

AT 

If you get an OK response that means the dongle is working.

To use these scripts you will need to have Python installed. Both Python2 and Python3 should work but the scripts are made with Python3 in mind. But there are comments where the script need to be edited to work with Python2. You 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 following sample python script to set up your own iBeacon.

import serial
import timeconnecting_to_dongle = 0
print("Connecting to dongle...")
# Trying to connect to dongle until connected. Make sure the port and baudrate is the same as your dongle.
# You can check in the device manager to see what port then right-click and choose properties then the Port Settings
# tab to see the other settings
while connecting_to_dongle == 0:
try:
console = serial.Serial(
port='COM14',
baudrate=57600,
parity="N",
stopbits=1,
bytesize=8,
timeout=0
)
if console.is_open.__bool__():
connecting_to_dongle = 1
except:
print("Dongle not connected. Please reconnect Dongle.")
time.sleep(5)
print("\n\nConnected to Dongle.\n")
print("\n Welcome to the iBeacon example!\n\n")
new_input = 1
while 1 and console.is_open.__bool__():
# get keyboard input once
if (new_input == 1):
# Python 2 users
# input = raw_input("Enter the UUID... ")
new_input = input("Enter the UUID (x) string with Major (j), Minor (n) and TX (t) (format:"
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxjjjjnnnntt): ")
time.sleep(0.1)
# sends the commands to the dongle. Important to send the \r as that is the return-key.
console.write(str.encode("AT+ADVDATAI="))
console.write(new_input.encode())
console.write('\r'.encode())
time.sleep(0.1)
console.write(str.encode("AT+ADVSTART=0;200;3000;0;"))
console.write('\r'.encode())
out = ''
# let's wait one second before reading output (let's give device time to answer)
time.sleep(1)
while console.inWaiting() > 0:
out += console.read(console.inWaiting()).decode()
else:
if not out.isspace():
# We make sure it doesn't print the same message over and over again by setting [out] to blankspace
# after printing once and check for blankspace before print again
print(">>" + out)
out = " "

Full source also available 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

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.

Image for post

Here you can see , your device has started advertising.

You can also use Eddystone script.
Source code available here.

Share this post on :

Turn your Computer into an iBeacon

iBeacon technology allows Mobile Apps to understand their position on a micro-local scale, and deliver content to users based on location. It is a Bluetooth Low Energy technology.

BLE Advertising uses a one-way communication method. Beacons that want to be discovered can Advertise self-contained packets of data in set intervals. Smartphones collect these packets, which can be used for various applications to trigger things like push messages, prompts or app actions.

Beacons ideal for indoor location tracking because a standard BLE has a broadcast range of up to 100 meters.

iBeacon are defined by the Apple company including following parameters: UUID, Major and Minor

You can build your own beacon by defining your own parameter values.

What is UUID?

UUID stands for Universally Unique Identifier. It contains 32 hexadecimal digits, split into 5 groups, like this:

5f2dd896-b886–4549-ae01-e41acd7a354a0203010400

The UUID is a standard identifying system which allows a ‘unique’ number to be generated for a beacon network.

The purpose of the UUID is to identify iBeacons in your network, from all other possible beacons in networks not in your control.

What are Major and Minor values?

Major and Minor values are numbers assigned to your iBeacons, in order to identify individual iBeacon within your UUID network.

Minor and Major are unsigned integer values between 0 and 65535.

The iBeacon standard requires both a Major and Minor value to be assigned.

Device Needed

  • A laptop with usb port.
  • A BlueIO

*BlueIO is Bluetooth® low energy solution that can be used to create new BLE 5.0 applications in the fastest and easiest way.

How to use

Connect the BleuIO to your computer. It opens a virtual serial port (COM port) that you can use to send commands to and from the Bluetooth USB Adapter.

Image for post

Control Bluetooth USB Adapter using predefined commands that you can find on the website. click here

After connecting, you can use the following sample python script to set up your own iBeacon.

To use this scripts you will need to have Python installed. Both Python2 and Python3 should work but the scripts are made with Python3 in mind. But there are comments where the script need to be edited to work with Python2. You 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

Following is a sample python script for iBeacon. You can also get the source file from Github page.

 import serial 

 import time 

 connecting_to_dongle = 0 

 print(“Connecting to dongle…”) 

 # Trying to connect to dongle until connected. Make sure the port and baudrate is the same as your dongle. 

 # You can check in the device manager to see what port then right-click and choose properties then the Port Settings 

 # tab to see the other settings 

 <strong>while</strong> connecting_to_dongle == 0: 

 <strong>try</strong>: 

 console = serial.Serial( 

 port=’COM14′, 

 baudrate=57600, 

 parity=”N”, 

 stopbits=1, 

 bytesize=8, 

 timeout=0 

 ) 

 <strong>if</strong> console.is_open.__bool__(): 

 connecting_to_dongle = 1 

 except: 

 print(“Dongle not connected. Please reconnect Dongle.”) 

 time.sleep(5) 

 print(“\n\nConnected to Dongle.\n”) 

 print(“\n Welcome to the iBeacon example!\n\n”) 

 new_input = 1 

 <strong>while</strong> 1 and console.is_open.__bool__(): 

 # get keyboard input once 

 <strong>if</strong> (new_input == 1): 

 # Python 2 users 

 # input = raw_input(“Enter the UUID… “) 

 new_input = input(“Enter the UUID (x) string with Major (j), Minor (n) and TX (t) (format:” 

 “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxjjjjnnnntt): “) 

 time.sleep(0.1) 

 # sends the commands to the dongle. Important to send the \r as that is the return-key. 

 console.write(str.encode(“AT+ADVDATAI=”)) 

 console.write(new_input.encode()) 

 console.write(‘\r’.encode()) 

 time.sleep(0.1) 

 console.write(str.encode(“AT+ADVSTART=0;200;3000;0;”)) 

 console.write(‘\r’.encode()) 

 out = ‘’ 

 # let’s wait one second before reading output (let’s give device time to answer) 

 time.sleep(1) 

 <strong>while</strong> console.inWaiting() > 0: 

 out += console.read(console.inWaiting()).decode() 

 <strong>else</strong>: 

 <strong>if</strong> not out.isspace(): 

 # We make sure it doesn’t print the same message over and over again by setting [out] to blankspace 

 # after printing once and check for blankspace before print again 

 print(“>>” + out) 

 out = “ “ 

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

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.

Image for post

Here you can see is your device has started advertising.

Now you can have your own iBeacon in no time. There are many other applications you can develop yourself. It’s a simple and excellent way to learn to program Bluetooth quickly.

Share this post on :