Eddystone Beacon
Introduction
Eddystone is a Bluetooth Low Energy beacon profile released by Google. This is an example of how you can setup the Smart USB Dongle 2.0 to advertise an URL as an Eddystone beacon.
Copy the following script and save it as eddystone_example.py on your local directory. You can also download the source code from our 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
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 Eddystone 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 Eddystone url hex string: ")
new_input = input("Enter the Eddystone url hex string: ")
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+ADVDATA=03:03:aa:fe "))
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 = " "
Then go to the directory you saved the script and open a command propt. Then run the script by typing:
python eddystone_example.py
The script will now ask you for a eddystone url hex string.
I will now show you how to prepare one.
Eddystone url hex string
Let's say we want to send http://google.com
The url hex string will then looks like this: 0d:16:aa:fe:10:00:03:67:6f:6f:67:6c:65:07
0d - Length of the following string in hex. 0D is 13 and as you see there is 13 bits after this one.
It is important that this correspondes with your length otherwise it will not run.
Keep in mind that you have a maximum of 17 bytes worth of space for your url.
Hex | Description |
---|---|
16 | Service Data data type value (No need to change this) |
aa | 16-bit Eddystone UUID (No need to change this) |
fe | 16-bit Eddystone UUID (No need to change this) |
10 | Frame Type = URL (No need to change this) |
Hex | Description |
---|---|
00 | TX Power. |
03 | https:// (Eddystone has a list of 1 byte codes for popular prefixes and sufixes) |
67 | hex for 'g' |
6f | hex for 'o' |
6f | hex for 'o' |
67 | hex for 'g' |
6c | hex for 'l' |
65 | hex for 'e' |
07 | .com (Eddystone has a list of 1 byte codes for popular prefixes and sufixes) |
Here is two helpful sites that can help you autogenerate an eddystone hex url string:
https://www.mkompf.com/tech/eddystoneurl.html
https://yencarnacion.github.io/eddystone-url-calculator/
Just keep in mind that you will still need to put a colon (:) between every byte when you put it in the script for it to work.
Supported prefix list
Hex | Expansion |
---|---|
00 | http://www. |
01 | https://www. |
02 | http:// |
03 | https:// |
Supported sufix list
Hex | Expansion |
---|---|
00 | .com/ |
01 | .org/ |
02 | .edu/ |
03 | .net/ |
04 | .info/ |
05 | .biz/ |
06 | .gov/ |
07 | .com |
08 | .org |
09 | .edu |
0a | .net |
0b | .info |
0c | .biz |
0d | .gov |
0e to 20 | Reserved for Future Use |
7F to FF | Reserved for Future Use |
Full source also available on GitHub.