Bluetooth-based Beacon technology pure dry goods tailored to their own exclusive Beacon

We don't have a Beacon in the form of AltBeacon yet, but there are a lot of Bluetooth development boards in hand. The Bluetooth development board is a smart bluetooth-enabled microcontroller (MCU) that has a built-in Bluetooth protocol stack inside. Because the development board generally has a wealth of peripheral interfaces and leads, the development board is usually used to build a prototype of the product. The compiled firmware can be directly burned into the development board, or even directly into the product function display, or simply For testing or learning. I decided to create a Beacon app with a few development boards I have on hand, and then test the Android Museum Guide app.

I am using the Bluegiga DKBluetooth Low Energy Development Kit and the Intel Edison Development Board. The Bluegiga development board is programmed using the BGScript scripting language. Intel Edison runs Linux, and programming languages ​​have multiple options. I am used to using Node.js driven by the JavaScript framework so that I can find the applicable Smart Bluetooth feature pack or library file.

Bluegiga turned into AltBeacon

Bluegiga's BGScript scripting language is easy to understand and comes with a rich library of features provided by the Bluegiga framework. Creating a Bluegiga application with BGScript involves creating a script file and other project configuration files with a text editor. With the software update tool in the Bluegiga SDK, the compiled firmware can be burned directly onto the development board via USB.

Scripts include variable and array declarations, event handler callback functions. Callbacks are an important part of the programming model, and calling the standard Bluegiga function will trigger the relevant callback function. Similarly, the framework can also call the event handler in response to a situation outside of the script.

Implementing Beacon on any platform involves collaborating with the Generic Access Profile (GAP), requiring the setting of broadcast packet content and configuration of broadcast parameters.

The elements of the Bluegiga AltBeacon implementation are as follows:

Start with a variable declaration.

Figure 1 – Array declaration

Figure 11 – Array declaration

The broadcast settings can be done in the Bluegiga standard event handler "system_boot", and the system will call "system_boot" after the board is powered up or reset. I first set up an array containing Flags fields. The Flags field consists of a number of bits. From each bit, you can see how Bluetooth Smart and/or Bluetooth BR/EDR are supported.

The fields that may be included in the broadcast packet are called ADV data types, which are clearly defined in Part A (Data Type Specification) of the Bluetooth Core Specification Addendum. The standard structure for broadcast data types, including a single-byte length field (its value does not include the bytes occupied by the length field itself), and a single-byte data type field. Data type values ​​are defined in the GAP numbering document.

Here is the first part of the initial process code:

Figure 2 – Define flags broadcast type in the system_boot event handler

Figure 12 – Define flags broadcast type in the system_boot event handler

In the first article of this series, I introduced the AltBeacon form and explained the data encoded in the GAP manufacturer-specific data broadcast field. I filled in the last 20 bytes of the same array.

Figure 3 – Defining AltBeacon Data in Manufacturer-Specific Data Fields

Figure 13 – Defining AltBeacon Data in Manufacturer-Specific Data Fields

Then set the name for the Beacon device, which can be displayed in the scan results returned by the Central device (mainly smartphone). Its value is another broadcast type, so I set it up in its own data. As you can see, the specified local name is AltBeacon.

Figure 4 – Creating a local name for the scan response

Figure 14 – Creating a local name for the scan response

Configuring broadcast parameters includes calling some of Bluegiga's features and arrays.

Figure 5 – Configuring GAP Broadcast

Figure 15 - Configuring GAP Broadcast

This way, my Bluegiga custom AltBeacon is ready.

Figure 6 – AltBeacon on DKBLE

Figure 16 – AltBeacon on DKBLE

Another option: AltBeacon on Intel Edison

Node.js is a modular design with a variety of modules to choose from. For Node.js, modules are similar to libraries. The "Bleno" module provides many functions for applications that serve as Bluetooth GAP peripherals, such as the definition and implementation of GATT profiles. It is open source and was created by Sandeep Mistry. SandeepMistry also created the Noble module, which can be used to create software for GAP Central Mode devices. Both Bleno and Noble are on github.

Bleno's standard distribution does not support the AltBeacon form, but it does support iBeacon. So I copied the Noble github repository and rewrote Bleno so that I could generate a GAP broadcast in the form of AltBeacon. Let me introduce to you how to rewrite.

I added new features to the standard bleno.js source file, and then I started the broadcast based on a set of established parameters for the node.js application. The new feature code looks like this:

Figure 7 – New features in bleno/lib/bleno.js

Figure 17 – New features in bleno/lib/bleno.js

This code basically fills in the necessary AltBeacon data into the buffer and then calls the other functions added to the Linuxbindings.js source file. Bleno can work with the BlueZ Bluetooth protocol stack on Linux. When performing functions on a Linux-based platform, Bleno's functionality for multiple applications is ultimately mapped to calls for BlueZ functionality. I had to make some changes to the Linux-related part of Bleno to support AltBeacon.

Figure 8 – New features in bleno/lib/linux/bindings.js

Figure 18 – New features in bleno/lib/linux/bindings.js

Figure 9 – New features in bleno/lib/linux/hci-ble.js

Figure 19 – New features in bleno/lib/linux/hci-ble.js

What these features do is prepare a buffer similar to the Bluegiga development board that contains all the necessary broadcast data, then pass it to and through the Bleno API layer, and finally to the BlueZ Host Controller Interface (HCI).

AltBeacon Node.js app

Bleno has been modified to support AltBeacon, and the rest is to create a node.js application using the new bleno module, and then start broadcasting using the AltBeacon form. The entire application is the 7 lines of code in the figure below.

Figure 10 – AltBeacon node.js application

Figure 20 – AltBeacon node.js application

To run the AltBeacon APP, I used Putty to establish a terminal session with Intel Edison via SSH or telnet, and then run node app.js from the command line.

Figure 11 – Putty establishes a terminal dialogue

Figure 21 – Putty establishes a terminal dialogue

Trasmission Pole

Trasmission Pole,Painted Steel Pole,Transmission Lines Steel Pole,Power Distribution Steel Pole

Jiangsu Baojuhe Science and Technology Co.,Ltd. , https://www.galvanizedsteelpole.com

Posted on