蓝牙BLE室内定位

最近在做一个基于蓝牙的室内定位的项目,学习了一些蓝牙BLE方面的知识,总结和分享蓝牙方面的学习。

1.蓝牙的现状及发展趋势。

目前蓝牙版本为4.0,支持低功耗蓝牙BLE,且android4.2之后都支持BLE,蓝牙的发展非常迅猛,在物联网与穿戴设备中有非常广阔的应用。功耗非常低,唯一感觉不足的是目前还不能像Zigbee一样支持组网。

2.方案

现在非常多的公司都推出了蓝牙芯片,比较主流的有TICC2540NordicNRF58812等,CC2540出现得比较早,为51内核的MCU,协议栈为Z-tack轻量化协议栈,NordicNRF58812comtex-M0内核,协议栈以固件BIN的形式给出,都不开源。

从我的理解来,Nordic的方案会比较容易上手,功耗各方面也相对CC2540来说有优势。但TICC2540出来的比较早,各方面的教程及技术支持比Nordic的好。

3.软件安装

NRF58812开发需要keil MDK,最好是安装5版本以后的,新版本的器件支持都以pack方式安装,需要到Nordic官网下载pack及例程。还需要安装nrfgo studio用了下载协议栈及程序。手机端可以安装nRF Master control来监控调试。

4.定位方案

定位项目蓝牙模块作为已知节点发送广播,手机或者其他节点接收广播信息,可以从广播信息中提取已知节点的位置信息,通过信号强度来计算距离,通过三角定位算法来计算位置来实现定位。

5.定位实现

因为蓝牙只需要广播信息,不需要连接,所以程序只需实现蓝牙NFR58812的广播就可以,可以参考Nordic官方例程的beacon工程,实现现广播相对来说非常简单,只需要封装一下需要发送的内容,失能广播就可以实现广播。

static uint8_t m_beacon_info[APP_BEACON_INFO_LENGTH] =                  /**< Information advertised by the Beacon. */

{

    APP_DEVICE_TYPE,     // Manufacturer specific information. Specifies the device type in this 

                         // implementation. 

    APP_ADV_DATA_LENGTH, // Manufacturer specific information. Specifies the length of the 

                         // manufacturer specific data in this implementation.

    APP_BEACON_UUID,     // 128 bit UUID value. 

    APP_MAJOR_VALUE,     // Major arbitrary value that can be used to distinguish between Beacons. 

    APP_MINOR_VALUE,     // Minor arbitrary value that can be used to distinguish between Beacons. 

    APP_MEASURED_RSSI,    // Manufacturer specific information. The Beacon's measured TX power in 

                         // this implementation. 

0xfe

// LOCATION_X,

// LOCATION_Y

};

#define APP_BEACON_INFO_LENGTH          0x18                              /**< Total length of information advertised by the Beacon. */

#define APP_ADV_DATA_LENGTH             0x16                              /**< Length of manufacturer specific data in the advertisement. */

#define APP_DEVICE_TYPE                 0x02                              /**< 0x02 refers to Beacon. */

#define APP_MEASURED_RSSI               0xC3                              /**< The Beacon's measured RSSI at 1 meter distance in dBm. */

#define APP_COMPANY_IDENTIFIER          0x0059                            /**< Company identifier for Nordic Semiconductor ASA. as per www.bluetooth.org. */

#define APP_MAJOR_VALUE                 0x01, 0x02                        /**< Major value used to identify Beacons. */ 

#define APP_MINOR_VALUE                 0x03, 0x04                        /**< Minor value used to identify Beacons. */ 

#define APP_BEACON_UUID                 0x01, 0x12, 0x23, 0x34, \

                                        0x45, 0x56, 0x67, 0x78, \

                                        0x89, 0x9a, 0xab, 0xbc, \

                                        0xcd, 0xde, 0xef, 0xf0            /**< Proprietary UUID for Beacon. */

这个为蓝牙的广播信息帧,蓝牙的广播帧最大只支持31字节的广播包,可以通过自己需要来更改,如果广播内容不想让别人获取,还可以加密广播内容。

下载到模块上,就可以通过nRF Master control来观察到广播信息及信号强度。

今天更新到这里,后续在更新android的蓝牙扫描广播帧方面知识及蓝牙连接方面的作为service的内容。

猜你喜欢

转载自blog.csdn.net/dengcanjun6/article/details/45605231