这是广告客户(通知data作为AdvertiseData类型传递)
private void advertise() {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothLeAdvertiser advertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
AdvertiseSettings settings = new AdvertiseSettings.Builder()
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
.setConnectable(false)
.build();
ParcelUuid pUuid = new ParcelUuid(UUID.fromString("cf2c82b6-6a06-403d-b7e6-13934e602664"));
AdvertiseData data = new AdvertiseData.Builder()
//.setIncludeDeviceName(true)
.addServiceUuid(pUuid)
.addServiceData(pUuid, "123456".getBytes(Charset.forName("UTF-8")))
.build();
AdvertiseCallback advertiseCallback = new AdvertiseCallback() {
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
Log.i(tag, "Advertising onStartSuccess");
super.onStartSuccess(settingsInEffect);
}
@Override
public void onStartFailure(int errorCode) {
Log.e(tag, "Advertising onStartFailure: " + errorCode);
super.onStartFailure(errorCode);
}
};
advertiser.startAdvertising(settings, data, advertiseCallback);
}
Run Code Online (Sandbox Code Playgroud)
它成功地开始了.
这是扫描仪
private …Run Code Online (Sandbox Code Playgroud) 我有一个蓝牙低功耗(BTLE)设备,我需要连接到我的电脑.为此,我在桌面WPF应用程序中使用Windows API参考.
蓝牙设备相当简单:1个服务,2个特性(一个读取/通知,一个写入).
To make below code work, add the following references to the WPF (for windows 10):
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
Run Code Online (Sandbox Code Playgroud)
C#的Windows API代码
public GattDeviceService BLEService;
public GattCharacteristic BLEData_ReadNotify;
public GattCharacteristic BLEData_Write;
private static readonly Guid Guid_service = new Guid("25FB9E91-1616-448D-B5A3-F70A64BDA73A");
public static readonly Guid Characteristics_ReadNotify = new Guid("C3FBC9E2-676B-9FB5-3749-2F471DCF07B2");
public static readonly Guid Characteristics_Write = new Guid("D6AF9B3C-FE92-1CB2-F74B-7AFB7DE57E6D");
// Find all BTLE devices that have the service Guid: Guid_service
public void findandconnect() {
var BTLEdeviceList = await …Run Code Online (Sandbox Code Playgroud) 我有一个使用BTLE连接到设备(arduino)的iOS应用程序.我的iPad iOS 7上的一切正常.升级到iOS 8后,CBCentralManager找不到任何外围设备.
- (void)startScanningForSupportedUUIDs
{
[self.centralManager scanForPeripheralsWithServices:nil options:nil];
}
Run Code Online (Sandbox Code Playgroud)
我不知道会出现什么问题.
我现在周围有一个Polar h7设备(它是BTLE)而且我已经完成了所有工作,但我很困惑如何获得BPM我们characteristic.value现在正在更新.我必须将一些字节转换为bpm ...
我的外设正在更新:
func peripheral(peripheral: CBPeripheral!, didUpdateValueForCharacteristic characteristic: CBCharacteristic!, error: NSError!) {
if characteristic.UUID == CBUUID.UUIDWithString(heartRateChar) {
getInfoAboutHeartRate(characteristic)
}
}
Run Code Online (Sandbox Code Playgroud)
我收到有关心率的信息:
func getInfoAboutHeartRate(characteristic:CBCharacteristic) {
println(characteristic.value)
var bytes = characteristic.value.bytes
}
Run Code Online (Sandbox Code Playgroud)
我知道我需要将这些字节转换为BPM.
根据规格(这是我困惑的地方)在bluetooth.org,字节0要么是a 1还是0..如果是0心率值是a uint8,如果它是a 1那么它是a uint16和我可以从中获得BPM.
如何确定byte 0是a 1还是a 0?如何把它变成一个uint8或uint16.如果我这样做,我会直接获得BPM,还是必须为此做其他事情?现在,BPM回归到了<16447d03>有意义的东西.
我需要从CBPeripheral和CBCenter的输入连接和传出连接中获取目标mac地址.标识符剂量没有在其中定义.看起来是从iOS 7删除.还有其他方法吗?
我是新手开发的移动应用程序,通过蓝牙连接到外围设备.我搜索了GATT是用于bluetoothLE通信的相关配置文件,但我们的客户建议我们使用UART服务.现在我很困惑1.这两件事情是如何相关的2.我们是否必须选择其中一件,如果是的话,每件事的优点和缺点是什么.谢谢
我知道答案名义上是"不",但我的意思是 -如果应用程序进入后台(启用BTLE后台处理)会怎么样?24小时?在应用更新中?
在"重新连接到外围设备"标题下,此Apple文档描述了重新连接工作流程,该工作流程首先尝试重新连接到先前通过配对的外围设备,retrievePeripheralsWithIdentifiers:但如果连接失败则再次开始扫描.connect如果没有正式超时,你怎么知道何时放弃以前找到的外围设备?你怎么知道什么时候开始/继续扫描,如果想要重新连接到以前找到的BTLE设备,只要你回到它附近,而不是用户必须与你的应用程序交互?
此外,该页面下方的一个注释表明,一些BTLE设备可能会在每次开机时为自己创建一个随机标识符,因此即使您发现一些以前配对的外围设备retrievePeripheralsWithIdentifiers:也可能无法连接到它们作为其名称已经改变.任何BTLE设备在实践中都这样做吗?那太疯狂了!