Turn the BBC micro:bit into a Physical Web Beacon and Change the URL Link Dynamically

Imagine if you can advertise different links with Physical Web each day to your customers visiting your shop and get them engaged and updated with your new products and promotions. Every Mondays you advertise product A, every Tuesdays you advertise product B and so on and so forth.

There is a simple way to update the URL link of Physical Web in a dynamic way. In other words, you don’t need to update the micro:bit firmware every time you want to update the link. What you need to do is to insert a new link and click ‘advertise’ on the webpage.

There are two apps that we need to write: HTML Web Bluetooth app and micro:bit firmware.

HTML Web Bluetooth app

HTML Web Bluetooth app

We will build the Web Bluetooth HTML app that will interact with micro:bit to advertise the link. User will be able to enter the link on the webpage that they wish to advertise. To communicate and send the information to micro:bit, we will activate and use the Bluetooth Event service from the micro:bit:

EVENTSERVICE_SERVICE_UUID: e95d93af-251d-470a-a062-fa1922dfa9a8
MICROBITEVENT_CHARACTERISTIC_UUID: e95d9775-251d-470a-a062-fa1922dfa9a8
CLIENTEVENT_CHARACTERISTIC_UUID: e95d5404-251d-470a-a062-fa1922dfa9a8
CLIENTREQUIREMENTS_CHARACTERISTIC_UUID: e95d23c4-251d-470a-a062-fa1922dfa9a8

Here is the code to connect to micro:bit and establish the Bluetooth Event services:

Create an event ID 8888d (22B8h) for the micro:bit firmware app to listen on the event value coming from this event ID. See the function initEvent() in the above code.

Get the entered link URL and convert it to shorten URL with Google URL Shortener API. Replace “Google_URL_Shortener_API” with your API key and send it to micro:bit with sendCommand() function.

For example URL link “https://www.uber.com/en-SG/” will be shorten to https://goo.gl/eaB6Ur, and then it will be sent to micro:bit with the following format:

“h”: 0xb8 0x22 0x68 0x00
"t": 0xb8 0x22 0x74 0x00
"t": 0xb8 0x22 0x74 0x00
"p": 0xb8 0x22 0x70 0x00
"s": 0xb8 0x22 0x73 0x00
":": 0xb8 0x22 0x3a 0x00
"/": 0xb8 0x22 0x2f 0x00
"/": 0xb8 0x22 0x2f 0x00
"g": 0xb8 0x22 0x67 0x00
"o": 0xb8 0x22 0x6f 0x00
"o": 0xb8 0x22 0x6f 0x00
".": 0xb8 0x22 0x2e 0x00
"g": 0xb8 0x22 0x67 0x00
"l": 0xb8 0x22 0x6c 0x00
"/": 0xb8 0x22 0x2f 0x00
"e": 0xb8 0x22 0x65 0x00
"a": 0xb8 0x22 0x61 0x00
"B": 0xb8 0x22 0x42 0x00
"6": 0xb8 0x22 0x36 0x00
"U": 0xb8 0x22 0x55 0x00
"r": 0xb8 0x22 0x72 0x00
"~": 0xb8 0x22 0x7e 0x00

If you notice, at the end of sequence, there is “~”, this is to indicate that is the end of the sequence. We will use this information on the firmware code.

micro:bit Firmware

The firmware code will monitor the incoming values from the event ID (8888d) sent by the web bluetooth app. Once all the event values have been received, it will advertise the link in the Eddystone-URL format.


Also create the config.json with the following values:


Compile the firmware code with Yotta compiler and copy the .hex file onto micro:bit.

Compile the firwmare with Yotta

Ready to Test

Go to the following link to test it yourself:

You can find the source codes and the .hex file on my Git repo: https://github.com/ferrygun/micro-bit-beacon/

Just let me know if you have any questions or comments.