如何搜索蓝牙4.0和ble区别 BLE 设备

Android学习(3)
& & & & 今天开始写博客来记录我的工作学习成长,作为一个初学者,近期的一个工作是通过Android蓝牙4.0来实现与蓝牙设备的数据交换,下面就通过代码和文字来解释一下整个过程。
& & & & 首先我要说明的是,我再项目中使用了一个开源库,我觉得不错,所有代码都是在该库基础上实现的,地址:/litesuits/android-lite-bluetoothLE
下面进入正题
1,检查设备是否支持蓝牙4.0,和打开蓝牙
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
& & & & & & Toast.makeText(this, &设备不支持BLE&, Toast.LENGTH_SHORT).show();
& & & & & & finish();
// Ensures Bluetooth is enabled on the device. &If Bluetooth is not currently enabled,
& & & & // fire an intent to display a dialog asking the user to grant permission to enable it.
& & & & if (!mBluetoothAdapter.isEnabled()) {
& & & & & & if (!mBluetoothAdapter.isEnabled()) {
& & & & & & & & Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
& & & & & & & & startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
& & & & & & }
2,搜索蓝牙4.0设备,该方法是搜索蓝牙设备SCAN_PERIOD事件,通过回调函数new PeriodScanCallback来处理结果,分为超时和找到蓝牙设备,自己可以在回调函数中作相应处理
& & * scan devices for a while
& &private void scanDevicesPeriod() {
& & mScanning =
& & this.startBluetoothProgressDialog(&正在搜索蓝牙设备...&);
& & showMessage.setText(&正在搜索蓝牙设备...&);
& & & &SampleGattAttributes.liteBluetooth.startLeScan(new PeriodScanCallback(SCAN_PERIOD) {
& & & & & &@Override
& & & & & &public void onScanTimeout() {
& & & & & &
BluetoothSearchActivity.this.stopBluetoothProgressDialog();
& & & & & &
mScanning =
handler1.sendEmptyMessage(3);
SampleGattAttributes.liteBluetooth.stopScan(null);
& & & & & &}
& & & & & &@Override
& & & & & &public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
& & & & & &
if(device != null && device.getName() != null && device.getName().startsWith(&XXXX&)){
bluetoothDevice =
deviceName.add(device.getName());&
mDeviceName = device.getName();
mDeviceAddress = device.getAddress();
SampleGattAttributes.address = device.getAddress();
mAdapter = new ArrayAdapter&String&(BluetoothSearchActivity.this, android.R.layout.simple_list_item_1, deviceName);
mScanning =
SampleGattAttributes.liteBluetooth.stopScan(null);
handler1.sendEmptyMessage(4);
& & & & & &}
& & & &});
3,连接蓝牙设备,通过connect连接设备,通过会返回一个回调函数gattCallBack,再回调函数中处理蓝牙设备连接的各种状态,如连接成功,失败,发现service等,作相应处理。
public void directConnect(){
mHandler.postDelayed(new Runnable() {
public void run() {
// TODO Auto-generated method stub
showMessage.setText(&连接超时,单击重新连接&);
BluetoothSearchActivity.this.stopBluetoothProgressDialog();
if(reConnect){
reConnect =
//directConnect();
}, 10000);
this.startBluetoothProgressDialog(&正在连接蓝牙设备...&);
showMessage.setText(&正在连接蓝牙设备...&);
SampleGattAttributes.mBluetoothGatt = SampleGattAttributes.liteBluetooth.connect(mBluetoothAdapter.getRemoteDevice(mDeviceAddress), false, gattCallBack);
LiteBleGattCallback gattCallBack = new LiteBleGattCallback() {
public void onServicesDiscovered(BluetoothGatt gatt, int arg1) {
// TODO Auto-generated method stub
BluetoothGattService aimService = gatt.getService(SampleGattAttributes.SERVIE_UUID);
aimCharact = aimService.getCharacteristic(SampleGattAttributes.WRITE_CHARACT_UUID);
SampleGattAttributes.writeCharact = aimC
Log.i(&12&, &onServicesDiscovered & + aimCharact.getUuid());
mHandler.removeCallbacksAndMessages(null);
SampleGattAttributes.isConnect =
handler1.sendEmptyMessage(1);
public void onConnectSuccess(BluetoothGatt gatt, int arg1) {
// TODO Auto-generated method stub
gatt.discoverServices();
SampleGattAttributes.isConnect =
Log.i(&12&, &onConnectSuccess chenyue&);
// mHandler.removeCallbacksAndMessages(null);
public void onConnectFailure(BleException arg0) {
// TODO Auto-generated method stub
SampleGattAttributes.isConnect =
SampleGattAttributes.writeCharact =
4,写数据,通过获取UUID获取了service和Characteristic,就可以如里面写数据了
& & &* write data to characteristic
& & private void writeDataToCharacteristic() {
& & & & LiteBleConnector connector = liteBluetooth.newBleConnector();
& & & & connector.withUUIDString(UUID_SERVICE, UUID_CHAR_WRITE, null)
& & & & & & & & &.writeCharacteristic(new byte[]{1, 2, 3}, new BleCharactCallback() {
& & & & & & & & & & &@Override
& & & & & & & & & & &public void onSuccess(BluetoothGattCharacteristic characteristic) {
& & & & & & & & & & & & &BleLog.i(TAG, &Write Success, DATA: & + Arrays.toString(characteristic.getValue()));
& & & & & & & & & & &}
& & & & & & & & & & &@Override
& & & & & & & & & & &public void onFailure(BleException exception) {
& & & & & & & & & & & & &BleLog.i(TAG, &Write failure: & + exception);
& & & & & & & & & & & & &bleExceptionHandler.handleException(exception);
& & & & & & & & & & &}
& & & & & & & & &});
& & &* read data from characteristic
& & private void readDataFromCharacteristic() {
& & & & LiteBleConnector connector = liteBluetooth.newBleConnector();
& & & & connector.withUUIDString(UUID_SERVICE, UUID_CHAR_READ, null)
& & & & & & & & &.readCharacteristic(new BleCharactCallback() {
& & & & & & & & & & &@Override
& & & & & & & & & & &public void onSuccess(BluetoothGattCharacteristic characteristic) {
& & & & & & & & & & & & &BleLog.i(TAG, &Read Success, DATA: & + Arrays.toString(characteristic.getValue()));
& & & & & & & & & & &}
& & & & & & & & & & &@Override
& & & & & & & & & & &public void onFailure(BleException exception) {
& & & & & & & & & & & & &BleLog.i(TAG, &Read failure: & + exception);
& & & & & & & & & & & & &bleExceptionHandler.handleException(exception);
& & & & & & & & & & &}
& & & & & & & & &});
6,监听&characteristic的数据
& & &* enble notification of characteristic
& & private void enableNotificationOfCharacteristic() {
& & & & LiteBleConnector connector = liteBluetooth.newBleConnector();
& & & & connector.withUUIDString(UUID_SERVICE, UUID_CHAR_READ, null)
& & & & & & & & &.enableCharacteristicNotification(new BleCharactCallback() {
& & & & & & & & & & &@Override
& & & & & & & & & & &public void onSuccess(BluetoothGattCharacteristic characteristic) {
& & & & & & & & & & & & &BleLog.i(TAG, &Notification characteristic Success, DATA: & + Arrays
& & & & & & & & & & & & & & & & &.toString(characteristic.getValue()));
& & & & & & & & & & &}
& & & & & & & & & & &@Override
& & & & & & & & & & &public void onFailure(BleException exception) {
& & & & & & & & & & & & &BleLog.i(TAG, &Notification characteristic failure: & + exception);
& & & & & & & & & & & & &bleExceptionHandler.handleException(exception);
& & & & & & & & & & &}
& & & & & & & & &});
7,对现有的连接加入回调函数
& & &* add(remove) new callback to an existing connection.
& & &* One Device, One {@link LiteBluetooth}.
& & &* But one device( {@link LiteBluetooth}) can add many callback {@link BluetoothGattCallback}
& & &* {@link LiteBleGattCallback} is a extension of {@link BluetoothGattCallback}
& & private void addNewCallbackToOneConnection() {
& & & & BluetoothGattCallback liteCallback = new BluetoothGattCallback() {
& & & & & & @Override
& & & & & & public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {}
& & & & & & @Override
& & & & & & public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
& & & & & & }
& & & & & & @Override
& & & & & & public void onCharacteristicWrite(BluetoothGatt gatt,
& & & & & & & & & & & & & & & & & & & & & & & BluetoothGattCharacteristic characteristic, int status) {
& & & & & & }
& & & & & & @Override
& & & & & & public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {}
& & & & };
& & & & if (liteBluetooth.isConnectingOrConnected()) {
& & & & & & liteBluetooth.addGattCallback(liteCallback);
& & & & & & liteBluetooth.removeGattCallback(liteCallback);
以上基本实现蓝牙4.0的进本功能了,下面说说我在项目过程中遇到的困难和解决方法
1,每次连接设备都要重新搜索蓝牙,比较耗时,所以在第一次连接设备时,Android端就需要自动匹配蓝牙设备,下次连接就可以直接连接了。下面的方法实现了自动匹配strAddr地址的蓝牙设备,&strPsw一般为“0000”
//蓝牙配对
public static boolean pair(String strAddr, String strPsw)&
& & & & boolean result =&
& & & & if (!BluetoothAdapter.checkBluetoothAddress(strAddr))&
& & & & { // 检查蓝牙地址是否有效&
// & & & & & & Log.d(&mylog&, &devAdd un effient!&);&
& & & & }&
& & & BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(strAddr);
& & & & if (device.getBondState() != BluetoothDevice.BOND_BONDED)&
& & & & {&
& & & & & & try&
& & & & & & {&
// & & & & & & & & Log.d(&mylog&, &NOT BOND_BONDED&);&
& & & & & & & & ClsUtils.setPin(device.getClass(), device, strPsw); // 手机和蓝牙采集器配对&
& & & & & & & & ClsUtils.createBond(device.getClass(), device);&
// & & & & & & & & remoteDevice = // 配对完毕就把这个设备对象传给全局的remoteDevice&
& & & & & & & & result =&
& & & & & & }&
& & & & & & catch (Exception e)&
& & & & & & {&
& & & & & & & & // TODO Auto-generated catch block&
// & & & & & & & & Log.d(&mylog&, &setPiN failed!&);&
& & & & & & & & e.printStackTrace();&
& & & & & & } //&
& & & & }&
& & & & else&
& & & & {&
// & & & & & & Log.d(&mylog&, &HAS BOND_BONDED&);&
& & & & & & try&
& & & & & & {&
& & & & & & & & ClsUtils.createBond(device.getClass(), device);&
& & & & & & & & ClsUtils.setPin(device.getClass(), device, strPsw); // 手机和蓝牙采集器配对&
& & & & & & & & ClsUtils.createBond(device.getClass(), device);&
// & & & & & & & & remoteDevice = // 如果绑定成功,就直接把这个设备对象传给全局的remoteDevice&
& & & & & & & & result =&
& & & & & & }&
& & & & & & catch (Exception e)&
& & & & & & {&
& & & & & & & & // TODO Auto-generated catch block&
// & & & & & & & & Log.d(&mylog&, &setPiN failed!&);&
& & & & & & & & e.printStackTrace();&
& & & & & & }&
& & & & }&
2,当传送数据量较大时,需要进行分包,我是将数据分成了256byte一个包发送。但是,分包发送可能会出现的问题是有的包发送失败,所以需要进行重传或者其他处理,我的处理方式是,当一个包发送成功后再发第二个包,发送失败就进行重传。大家放心,发送数据也是有回调函数的,发送成功或者失败都会进入相应的回调函数,大家自行处理就可以了。还是一个问题就是数据发送的速率问题,我们发送的速率本来一直很慢,后来才发现是蓝牙设备的模式问题,大家以后出现这种问题,最好查看一下蓝牙设备的收发数据模式。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:889次
排名:千里之外iOS BLE 4.0 实现搜索周边蓝牙设备并显示其信号强度(RSSI)_ble rssi_词汇网
iOS BLE 4.0 实现搜索周边蓝牙设备并显示其信号强度(RSSI)
责任编辑:词汇网 发表时间: 8:00:21
iOSBLE4.0实现搜索周边蓝牙设备并显示其信号强度(RSSI)源码:https://git.oschina.net/laughingzhong/MyBluetoothDemo.git 标签:
代码片段(1)[全屏查看所有代码] 1.[代码][Objective-C]代码 #import "ViewController.h"#import "TableViewCell.h"#import "PeripheralViewController.h"#define ScanTimeInterval 1.0@interface ViewController ()@property (nonatomic,strong) NSMutableArray *devicesA@property (nonatomic,strong) CBCentralManager *centralM@property (nonatomic,strong) CBPeripheral *selectedP@property (nonatomic,strong) NSTimer *scanT@end@implementation ViewController- (void)dealloc{ _devicesArray = _centralManager = _selectedPeripheral = _scanTimer =}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _devicesArray = [[NSMutableArray alloc] initWithCapacity:1]; [self initWithLeftBarButton]; [self initWithRightBarButton]; [self initWithTableView]; [self initWithCBCentralManager];}#pragma mark - UI- (void)initWithLeftBarButton{ UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setFrame:CGRectMake(0.0, 0.0, 60.0, 40.0)]; [button setBackgroundColor:[UIColor clearColor]]; [button setTitle:@"搜索" forState:UIControlStateNormal]; [button addTarget:self action:@selector(startScanPeripherals) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button]; [self.navigationItem setLeftBarButtonItem:item];}- (void)initWithRightBarButton{ UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setFrame:CGRectMake(0.0, 0.0, 60.0, 40.0)]; [button setBackgroundColor:[UIColor clearColor]]; [button setTitle:@"停止" forState:UIControlStateNormal]; [button addTarget:self action:@selector(stopScan) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button]; [self.navigationItem setRightBarButtonItem:item];}- (void)initWithTableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; [_tableView setDelegate:self]; [_tableView setDataSource:self]; [_tableView setBackgroundColor:[UIColor clearColor]]; [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; [_tableView setTranslatesAutoresizingMaskIntoConstraints:NO]; } if (_tableView && _tableView.superview != self.view) { [self.view addSubview:_tableView]; NSArray *h = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_tableView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView)]; NSArray *v = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_tableView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView)]; [self.view addConstraints:h]; [self.view addConstraints:v]; }}#pragma mark - ScanTimer- (void)startScanPeripherals{ if (!_scanTimer) { _scanTimer = [NSTimer timerWithTimeInterval:ScanTimeInterval target:self selector:@selector(scanForPeripherals) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:_scanTimer forMode:NSDefaultRunLoopMode]; } if (_scanTimer && !_scanTimer.valid) { [_scanTimer fire]; }}- (void)stopScan{ if (_scanTimer && _scanTimer.valid) { [_scanTimer invalidate]; _scanTimer = } [_centralManager stopScan];}#pragma mark - CBCentralManager- (void)initWithCBCentralManager{ if (!_centralManager) { dispatch_queue_t queue = dispatch_get_main_queue(); _centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:queue options:@{CBCentralManagerOptionShowPowerAlertKey:@YES}]; [_centralManager setDelegate:self]; }}- (void)scanForPeripherals{ if (_centralManager.state == CBCentralManagerStateUnsupported) {//设备不支持蓝牙 }else {//设备支持蓝牙连接 if (_centralManager.state == CBCentralManagerStatePoweredOn) {//蓝牙开启状态 //[_centralManager stopScan]; [_centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey:[NSNumber numberWithBool:NO]}]; } }}- (void)connectPeripheral{ }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - UITableView Datasource && Delegate- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _devicesArray.}- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ if (section == 0) { return @"Peripherals Nearby"; }else { }}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 50.0;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellID = @"cellID"; TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID]; } NearbyPeripheralInfo *info = [_devicesArray objectAtIndex:indexPath.row]; [cell setPeripheral:info];}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (_centralManager.state == CBCentralManagerStateUnsupported) {//设备不支持蓝牙 }else {//设备支持蓝牙连接 if (_centralManager.state == CBCentralManagerStatePoweredOn) {//蓝牙开启状态 //连接设备 NearbyPeripheralInfo *info = [_devicesArray objectAtIndex:indexPath.row]; [_centralManager connectPeripheral:info.peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES,CBConnectPeripheralOptionNotifyOnNotificationKey:@YES,CBConnectPeripheralOptionNotifyOnDisconnectionKey:@YES}]; } }}#pragma mark - CBCentralManager Delegate- (void)centralManagerDidUpdateState:(CBCentralManager *)central{ switch (central.state) { case CBCentralManagerStatePoweredOff: NSLog(@"CBCentralManagerStatePoweredOff"); case CBCentralManagerStatePoweredOn: NSLog(@"CBCentralManagerStatePoweredOn"); case CBCentralManagerStateResetting: NSLog(@"CBCentralManagerStateResetting"); case CBCentralManagerStateUnauthorized: NSLog(@"CBCentralManagerStateUnauthorized"); case CBCentralManagerStateUnknown: NSLog(@"CBCentralManagerStateUnknown"); case CBCentralManagerStateUnsupported: NSLog(@"CBCentralManagerStateUnsupported"); default: }}//发现蓝牙设备- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{// NSLog(@"\nperipheral is :\n%@\nadvertisementData is :\n%@\nRSSI is :%d",peripheral,advertisementData,[RSSI intValue]); BOOL isExist = NO; NearbyPeripheralInfo *info = [[NearbyPeripheralInfo alloc] init]; info.peripheral = info.advertisementData = advertisementD info.RSSI = RSSI; if (_devicesArray.count == 0) { [_devicesArray addObject:info]; NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:0]; [_tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationFade]; }else { for (int i = 0;i < _devicesArray.i++) { NearbyPeripheralInfo *originInfo = [_devicesArray objectAtIndex:i]; CBPeripheral *per = originInfo. if ([peripheral.identifier.UUIDString isEqualToString:per.identifier.UUIDString]) { isExist = YES; [_devicesArray replaceObjectAtIndex:i withObject:info]; [_tableView reloadData]; } } if (!isExist) { [_devicesArray addObject:info]; NSIndexPath *path = [NSIndexPath indexPathForRow:(_devicesArray.count - 1) inSection:0]; [_tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationFade]; } }}//连接蓝牙设备成功- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{ NSLog(@"%s",__FUNCTION__); [self stopScan]; _selectedPeripheral = PeripheralViewController *viewController = [[PeripheralViewController alloc] initWithNibName:nil bundle:nil]; viewController.currentPeripheral = _selectedP [self.navigationController pushViewController:viewController animated:YES];}//连接蓝牙设备失败- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{ NSLog(@"%s",__FUNCTION__);}//断开连接- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{ NSLog(@"%s",__FUNCTION__);}@end
上一集:没有了 下一集:
相关文章:&&&&&&&&&&&&&&&&
最新添加资讯
24小时热门资讯
附近好友搜索36585人阅读
Android & 蓝牙(13)
概述:蓝牙核心规范发展的主要版本:
表1&&蓝牙核心规范发展介绍
Baseband、LMP
HCI、L2CAP、RFCOMM
OBEX与IrDA的互通性
第一个正式版本
安全性,厂商设备之间连接兼容性
IEEE 802.15.1
快速连接、自适应跳频、错误检测和流程控制、同步能力
2.0 &#43; EDR
EDR传输率提升至2-3Mbps
2.1 &#43; EDR
扩展查询响应、简易安全配对、暂停与继续加密、Sniff省电
3.0 &#43; HS
交替射频技术、802.11协议适配层、电源管理、取消了UMB的应用
4.0 &#43;BLE
低功耗物理层和链路层、AES加密、Attribute Protocol(ATT)、Generic Attribute Profile(GATT)、Security Manager(SM)
1)与4G不构成干扰;
2)通过IPV6连接到网络;
3)可同时发射和接收数据;
下面对主要版本的主要特性做一个详细的介绍:
1、版本1.1:
传输率约在<span style="color:#8~810kb/s,因是早期设计,容易受到同频率之产品所干扰下影响通讯质量。支持Stereo音效的传输要求,但只能够作(单工)方式工作,加上音带频率响应不太足够,并未算是最好之Stereo传输工具。
2、版本1.2:
同样是只有<span style="color:#8~810kb/s的传输率,但在加上了(改善Software)抗干扰跳频功能。(太深入之技术理论不再详述!)。支持Stereo音效的传输要求,但只能够作(单工)方式工作,加上音带频率响应不太足够,并未算是最好之Stereo传输工具。
3、版本2.0:
<span style="color:#.0是<span style="color:#.2的改良提升版,传输率约在<span style="color:#.8M/s~2.1M/s,可以有(双工)的工作方式。即一面作语音通讯,同时亦可以传输档案/高质素图片,台湾有部份蓝牙Dongle已经有在市面发售,但在手机内有支持蓝牙<span style="color:#.0版本则是很少。蓝牙耳机能够真正使用的亦不多,<span style="color:#.0版本当然也支持Stereo运作。随后蓝牙<span style="color:#.0版本的芯片,是有机会加入了Stereo译码芯片,则连A2DP(AdvancedAudioDistributionProfile)也可以不需要了。
4、版本2.1:
为了改善蓝牙技术存在的问题,蓝牙SIG组织(Special InterestGroup)推出了Bluetooth
2.1&#43;EDR版本的蓝牙技术。改善装置配对流程:以往在连接过程中,需要利用个人识别码来确保连接的安全性,而改进过后的连接方式则是会自动使用数字密码来进行配对与连接,举例来说,只要在手机选项中选择连接特定装置,在确定之后,手机会自动列出当前环境中可使用的设备,并且自动进行连结;而短距离的配对方面:也具备了在两个支持蓝牙的手机之间互相进行配对与通讯传输的NFC(Near
Field CoMMunication)机制;更佳的省电效果:蓝牙<span style="color:#.1版加入了Sniff Subrating的功能,透过设定在<span style="color:#个装置之间互相确认讯号的发送间隔来达到节省功耗的目的。蓝牙<span style="color:#.1将装置之间相互确认的讯号发送时间间隔从旧版的<span style="color:#.1秒延长到<span style="color:#.5秒左右,如此可以让蓝牙芯片的工作负载大幅降低,也可让蓝牙可以有更多的时间可以彻底休眠。根据官方的报告,采用此技术之后,蓝牙装置在开启蓝牙联机之后的待机时间可以有效延长<span style="color:#倍以上。
5、版本3.0&#43;HS:
<span style="color:#09年<span style="color:#月<span style="color:#日,蓝牙技术联盟(BluetoothSIG)正式颁布了新一代标准规范&BluetoothCoreSpecificationVersion3.0HighSpeed&(蓝牙核心规范<span style="color:#.0版高速),蓝牙<span style="color:#.0的核心是&GenericAlternateMAC/PHY&(AMP),这是一种全新的交替射频技术,允许蓝牙协议栈针对任一任务动态地选择正确射频。最初被期望用于新规范的技术包括<span style="color:#2.11以及UMB,但是新规范中取消了UMB的应用。作为新版规范,蓝牙<span style="color:#.0的传输速度自然会更高,而秘密就在<span style="color:#2.11无线协议上。通过集成&802.11PAL&(协议适应层),蓝牙<span style="color:#.0的数据传输率提高到了大约<span style="color:#Mbps(即可在需要的时候调用<span style="color:#2.11WI-FI用于实现高速数据传输)。,是蓝牙<span style="color:#.0的八倍,可以轻松用于录像机至高清电视、PC至PMP、UMPC至打印机之间的资料传输。功耗方面,通过蓝牙<span style="color:#.0高速传送大量数据自然会消耗更多能量,但由于引入了增强电源控制(EPC)机制,再辅以<span style="color:#2.11,实际空闲功耗会明显降低,蓝牙设备的待机耗电问题有望得到初步解决。此外,新的规范还具备通用测试方法(GTM)和单向广播无连接数据(UCD)两项技术,并且包括了一组HCI指令以获取密钥长度。据称,配备了蓝牙<span style="color:#.1模块的PC理论上可以通过升级固件让蓝牙<span style="color:#.1设备也支持蓝牙<span style="color:#.0。联盟成员已经开始为设备制造商研发蓝牙<span style="color:#.0解决方案。
6. 蓝牙4.0
4.0为<span style="color:#.0的升级标准
蓝牙<span style="color:#.0最重要的特性是省电,极低的运行和待机可以使一粒纽扣连续工作数年之久。此外,低成本和跨厂商互操作性,<span style="color:#毫秒低延迟、AES-128加密等诸多特色,可以用于计步器、心律、智能仪表、传感器等众多领域,大大扩展蓝牙技术的应用范围。
6.2 主要特点:
蓝牙<span style="color:#.0是蓝牙<span style="color:#.0&#43;HS规范的补充,专门面向对成本和功耗都有较高要求的无线方案,可广泛用于卫生保健、体育健身、家庭娱乐、安全保障等诸多领域。
它支持两种部署方式:双模式和单模式。双模式中,低功耗蓝牙功能集成在现有的经典蓝牙控制器中,或再在现有经典蓝牙技术(2.1&#43;EDR/3.0&#43;HS)芯片上增加低功耗堆栈,整体架构基本不变,因此成本增加有限。
Single mode只能与BT4.0互相传输无法向下兼容(与<span style="color:#.0/2.1/2.0无法相通);Dual
mode可以向下兼容可与BT4.0传输也可以跟<span style="color:#.0/2.1/2.0传输。
单模式面向高度集成、紧凑的设备,使用一个轻量级连接层(Link Layer)提供超低功耗的待机模式操作、简单设备恢复和可靠的点对多点数据传输,还能让联网传感器在蓝牙传输中安排好低功耗蓝牙流量的次序,同时还有高级节能和安全加密连接。
蓝牙<span style="color:#.0将三种集一体,包括传统蓝牙技术、高速技术和低耗能技术,与<span style="color:#.0版本相比最大的不同就是低功耗。“4.0版本的功耗较老版本降低了<span style="color:#%,更省电,
“随着蓝牙技术由手机、游戏、耳机、便携电脑和汽车等传统应用领域向物联网、医疗等新领域的扩展,对低功耗的要求会越来越高。<span style="color:#.0版本强化了蓝牙在数据传输上的低功耗性能。”
6.4 典型蓝牙与BLE蓝牙对比
如果说蓝牙 4.0主打的是省电特性的话,那么此次升级蓝牙<span style="color:#.1的关键词应当是IOT(全联网),也就是把所有设备都联网的意思。为了实现这一点,对通讯功能的改进是蓝牙
4.1最为重要的改进之一。
7.2 主要特点
1)批量数据的传输速度
首当其冲的就是批量数据的传输速度,大家知道蓝牙的传输速率一直非常渣,与已经跨入千兆的WiFi相比毫无可比性。所以蓝牙<span style="color:#.1在已经被广泛使用的蓝牙<span style="color:#.0
LE基础上进行了升级,使得批量数据可以以更高的速率传输。当然这并不意味着可以用蓝牙高速传输流媒体视频,这一改进的主要针对的还是刚刚兴起的可穿戴设备。例如已经比较常见的健康手环,其发送出的数据流并不大,通过蓝牙<span style="color:#.1能够更快速地将跑步、游泳、骑车过程中收集到的信息传输到手机等设备上,用户就能更好地实时监控运动的状况,这是很有用处的。
在蓝牙<span style="color:#.0时代,所有采用了蓝牙<span style="color:#.0 LE的设备都被贴上了“BluetoothSmart”
和“Bluetooth SmartReady”的标志。其中Bluetooth Smart Ready设备指的是PC、平板、手机这样的连接中心设备,而Bluetooth
Smart设备指的是蓝牙耳机、键鼠等扩展设备。之前这些设备之间的角色是早就安排好了的,并不能进行角色互换,只能进行<span style="color:#对<span style="color:#连接。而在蓝牙<span style="color:#.1技术中,就允许设备同时充当“Bluetooth
Smart” 和“Bluetooth Smart Ready”两个角色的功能,这就意味着能够让多款设备连接到一个蓝牙设备上。举个例子,一个智能手表既可以作为中心枢纽,接收从健康手环上收集的运动信息的同时,又能作为一个显示设备,显示来自智能手机上的邮件、短信。借助蓝牙<span style="color:#.1技术智能手表、智能&#30524;镜等设备就能成为真正的中心枢纽。
2)通过IPV6连接到网络
除此之外,可穿戴设备上网不易的问题,也可以通过蓝牙<span style="color:#.1进行解决。新标准加入了专用通道允许设备通过 IPv6
联机使用。举例来说,如果有蓝牙设备无法上网,那么通过蓝牙<span style="color:#.1连接到可以上网的设备之后,该设备就可以直接利用IPv6连接到网络,实现与WiFi相同的功能。尽管受传输速率的限制,该设备的上网应用有限,不过同步资料、收发邮件之类的操作还是完全可以实现的。这个改进的好处在于传感器、嵌入式设备只需蓝牙便可实现连接手机、连接互联网,相对而言WiFi多用于连接互联网,在连接设备方面效果一般,无法做到蓝牙的功能。未来随着物联网逐渐走进我们的生活,无线传输在日常生活中的地位也会越来越高,蓝牙作为普及最广泛的传输方式,将在“物联网”中起到不可忽视的作用。不过,蓝牙完全适应IPv6则需要更长的时间,所以就要看芯片厂商如何帮助蓝牙设备增加IPv6的兼容性了
3)简化设备连接
  在各大手机厂商以及PC厂商的推动下,几乎所有的移动设备和笔记本电脑中都装有蓝牙的模块,用户对于蓝牙的使用也比较多。不过仍有大量用户觉得蓝牙使用起来很麻烦,归根结底还是蓝牙设备较为复杂的配对、连接造成的。试想一下,如果与手机连接的智能手表,每次断开连接后,都得在设置界面中手动选择一次才能重新连接,这就非常麻烦了。之前解决这一问题的方法是厂商在两个蓝牙设备中都加入NFC芯片,通过NFC近场通讯的方式来简化重新配对的步骤,这本是个不错的思路。只是搭载NFC芯片的产品不仅数量少,而且价&#26684;偏高,非常小众。
蓝牙4.1针对这点进行了改进,对于设备之间的连接和重新连接进行了很大幅度的修改,可以为厂商在设计时提供更多的设计权限,包括设定频段创建或保持蓝牙连接,这以改变使得蓝牙设备连接的灵活性有了非常明显的提升。两款带有蓝牙4.1的设备之前已经成功配对,重新连接时只要将这两款设备靠近,即可实现重新连接,完全不需要任何手动操作。举个例子,以后使用蓝牙4.1的耳机时,只要打开电源开关就行了,不需要在手机上进行操作,非常的简单。
4)与4G和平共处
在移动通信领域,近期最火的话题莫过于<span style="color:#G了,已经成为全球无线通信网络一个不可逆转的发展趋势。而蓝牙<span style="color:#.1也专门针对<span style="color:#G进行了优化,确保可以与<span style="color:#G信号和平共处,这个改进被蓝牙技术联盟称为“共存性”。可能大家会觉得疑惑,手机网络信号和蓝牙不是早就共存了么,为什么蓝牙<span style="color:#.1还要特别针对这点改进呢?这是因为在实际的应用中,如果这两者同时传输数据,那么蓝牙通信就可能受到手机网络信号的干扰,导致传输速率的下降。因此在全新的蓝牙<span style="color:#.1标准中,一旦遇到蓝牙<span style="color:#.1和<span style="color:#G网络同时在传输数据的情况,那么蓝牙<span style="color:#.1就会自动协调两者的传输信息,从而减少其它信号对蓝牙<span style="color:#.1的干扰,用户也就不用担心传输速率下降的问题了。
5)蓝牙4.1提供的增强功能包括:&&&
AES加密技术提供更安全的连接。该功能使无线耳机更加适用于政府、医疗及银行等安全至上的应用领域。
可通过专属Bluetooth Smart远程遥控器操控耳机、扬声器及条形音箱,并支持同步播放源于另一个完全不同设备的音频流。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:143472次
积分:1564
积分:1564
排名:千里之外
原创:47篇
转载:10篇
评论:13条
(2)(1)(1)(1)(2)(1)(1)(2)(7)(7)(3)(4)(1)(5)(1)(1)(4)(5)(5)(1)(3)(3)(1)

我要回帖

更多关于 ble蓝牙4.0串口源码 的文章

 

随机推荐