蓝牙4.0实现及原理

/*

建?立中?心设备

扫描外设(Discover Peripheral)

连接外设(Connect Peripheral)

扫描外设中的服务和特征(Discover Services And Characteristics)

利?用特征与外设做数据交互(Explore And Interact)

断开连接(Disconnect)

*/

#import "ViewController.h"

#import <CoreBluetooth/CoreBluetooth.h>

@interface ViewController ()<CBCentralManagerDelegate,CBPeripheralDelegate>

//所有扫描外设的列表

@property(nonatomic,strong)NSMutableArray*peripherals;

//创建蓝牙管理工具 中心设备

@property(nonatomic,strong)CBCentralManager*manager;

//服务信息(心率跳动次数)

@property(nonatomic,strong)CBCharacteristic*characteristicHeart;

@end

@implementation ViewController

-(CBCentralManager*)manager

{

if (!_manager) {

_manager=[[CBCentralManager alloc]init];

}

return _manager;

}

-(NSMutableArray*)peripherals

{

if (!_peripherals) {

_peripherals=[[NSMutableArray alloc]init];

}

return _peripherals;

}

- (void)viewDidLoad {

[super viewDidLoad];

//2.扫描外设

//  可以扫描指定的服务或者特性 [数组里传UUID唯一标识

[self.manager scanForPeripheralsWithServices:@[@"778899"] options:nil];

//  可以扫描所有的设备

[self.manager scanForPeripheralsWithServices:nil options:nil];

//设置代理,获取扫描产生的设备

self.manager.delegate=self;

//3.连接外设 可以设置btn点击连接外设

for (CBPeripheral *per in self.peripherals) {

[self.manager connectPeripheral:per options:nil];

//设置外设代理,用于信息交互

per.delegate=self;

}

}

#pragma mark CBCentralManagerDelegate

//扫描外部设备就会调用

-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

{

//peripheral 外设 如果存在就不添加

if(![self.peripherals containsObject:peripheral])

{

[self.peripherals addObject:peripheral];

}

}

//4 一旦连接到外设 扫描服务信息

-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral

{

//扫描服务

[peripheral discoverServices:@[@"123456"]];

}

//中心设备状态更新调用

-(void)centralManagerDidUpdateState:(CBCentralManager *)central

{

NSLog(@"扑捉当前中心设备的状态!");

}

#pragma mark CBPeripheralDelegate

//外设扫描到服务调用

-(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error

{

for (CBService *service in peripheral.services) {

[peripheral discoverCharacteristics:@[@"222222"] forService:service];

}

}

//扫描到服务中的特性的时候调用

-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error

{

for (CBCharacteristic *character in service.characteristics) {

if ([character .UUID.UUIDString isEqualToString:@"222222"]) {

self.characteristicHeart=character;

NSLog(@"记录查到的特性");

}

}

}

-(void)dealloc

{

}

@end

时间: 2024-07-28 13:22:32

蓝牙4.0实现及原理的相关文章

https://github.com/coolnameismy/BabyBluetooth github上的一个ios 蓝牙4.0的库并带文档和教程

The easiest way to use Bluetooth (BLE )in ios,even bady can use. 简单易用的蓝牙库,基于CoreBluetooth的封装,并兼容ios和mac osx. 为什么使用它? 1:基于原生CoreBluetooth框架封装的轻量级的开源库,可以帮你更简单地使用CoreBluetooth API. 2:CoreBluetooth所有方法都是通过委托完成,代码冗余且顺序凌乱.BabyBluetooth使用block方法,可以重新按照功能和顺序

Android低功耗蓝牙(蓝牙4.0)——BLE开发(上)

段时间,公司项目用到了手机APP和蓝牙设备的通讯开发,这里也正好对低功耗蓝牙(蓝牙4.0及以后标准)的开发,做一个总结. 蓝牙技术联盟在2010年6月30号公布了蓝牙4.0标准,4.0标准在蓝牙3.0+HS标准的基础上增加了对低功耗蓝牙(BLE)的支持.相比原有的普通蓝牙和高速蓝牙,BLE最大的特点就是低功耗,低延时,快速的搜索和连接速度,但数据传输速度相比传统蓝牙低.接下去将从BLE的概念以及代码两个方面介绍Android下的BLE. 先来说说基本概念: 1.BLE相关概念 1.1 GATT.

蓝牙4.0

http://www.voidcn.com/blog/wangqjpp/article/p-5038224.html android使用蓝牙4.0的条件:Android API Level 要在18及以上,即android 4.3以上. 一.蓝牙的几个参数: 1.1 BluetoothGatt 继承BluetoothProfile,通过BluetoothGatt可以连接设备(connect),发现服务(discoverServices),并把相应地属性返回到BluetoothGattCallba

蓝牙4.0技术

1.2 牙 蓝牙  4.01 1.2.1 牙 什么是蓝牙  4.0 图 1.1 蓝牙 4.0 logo 和 BLE logo蓝牙无线技术是使用范围最广泛的全球短距离无线标准之一,全新的蓝牙 4.0 版本将三种蓝牙技术(即传统蓝牙,高速蓝牙和低功耗蓝牙技术)合而为一.它集成了蓝牙技术在无线连接上的固有优势,同时增加了高速蓝牙和低功耗蓝牙的特点,这三个规格可以组合使用,也可以单独使用,低功耗蓝牙即 ble 是蓝牙 4.0 的核心规范,该技术最大特点是拥有超低的运行功耗和待机功耗,蓝牙低功耗设备使用一

蓝牙4.0 BLE

读了N多文档,其中推荐的有: Webee的<蓝牙4.0是战演练> Ghostyu的 <BLE权威教程> 1:透穿实现: 利用TI的BLE包里的工程直接烧 上位设备用 central,下位设备用peripheral工程 做以下处理: central 的NPI初始化时添加uart CB,并在串口回调函数中 直接添加write char函数写进特征值(实现上位从串口接收并通过蓝牙发送), 使能特征值通知,并在通知处理事件中将数据从串口发送(实现上位的从蓝牙接受并从串口发送) periph

蓝牙4.0浅析

接触蓝牙4.0一个多月,主要学习了怎样搜索从节点,选择从节点,建立连接,主节点与从节点之间的相互通信,还有一主多从通信. 1 BLE协议栈 BLE协议栈包含两部分:主机和控制器.控制器部分包括:物理层PHY.链路层LL.主机控制接口层HCI.主机部分包括:逻辑链路控制及自适应协议层L2CAP.安全管理层SM.属性协议层ATT.通用访问配置文件层GAP.通用属性配置文件层GATT. PHY是1Mbps自适应调频的GFSK射频,工作于免许可证的2.4GHz ISM(工业.科学和医疗)频段. LL用于

蓝牙4.0 BLE学习笔记

一.知识普及 1.蓝牙4.0分为两个部分: 1)Bluetooth Ready,兼容传统蓝牙的高速部分: 2)Bluetooth Smart,BLE(Bluetooth Low Energy),功耗低,速率低.最大传输速率4~5k字节/s: 2.BLE协议栈: 1)只是一个协议规范,BLE协议栈是该协议的代码实现:蓝牙组织SIG负责制定协议,芯片公司负责实现协议: 2)BLE协议栈是芯片公司预先编好的源码或者库: 3.CC2540/2541,CC254x就是一颗带有蓝牙功能的51单片机,BLE协

Android ble 蓝牙4.0 总结一

本文介绍Android ble 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用,如果手机系统版本API level < 18,也是用不了蓝牙4.0的哦. 首先发一下官方的demo,有兴趣的可以过去看看:http://developer.android.com/guide/topics/connectivity/bluetooth-le.html.android系统4.3以上,手机支持蓝牙4.0,具有搜索,配对,连接,发现服务及特征值,断开连接等功能,下载地

Android 蓝牙4.0 BLE

Android ble (Bluetooth Low Energy) 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用. BLE是蓝牙4.0的核心Profile,主打功能是快速搜索,快速连接,超低功耗保持连接和传输数据,弱点是数据传输速率低,由于BLE的低功耗特点,因此普遍用于穿戴设备. 官方demo:http://developer.android.com/guide/topics/connectivity/bluetooth-le.html 官方demo(