【发布时间】:2020-11-29 09:36:54
【问题描述】:
我正在使用微芯片 rn4780。
我成功连接到设备,但是当我尝试向它发送数据(2 个字节)时,
我没有得到回应(它应该运行一些马达)。
我认为问题在于我正在使用的特性,但我不确定。
这是我的代码
override fun onServicesDiscovered(gatt: BluetoothGatt?, status: Int) {
super.onServicesDiscovered(gatt, status)
for (service in gatt!!.services){
Log.d(TAG, "Service: " + service.uuid.toString())
for (char in service.characteristics) {
Log.d(TAG, "Char: " + char.uuid.toString())
if(char.uuid.toString() == "49535343-8841-43f4-a8d4-ecbe34729bb3") {
Log.d(TAG, "Try to write")
char.value = byteArrayOf(0x39, 0x31)
gatt!!.writeCharacteristic(char)
Log.d(TAG, "Finish to write")
}
}
}
}
我尝试使用 google play 中的其他应用程序,但只有一个有效,它称为“lightblue”。
From that screen, it worked perfect (I send 39 and then 31 in hex)
From that screen it doesn't work, for each characteristic, I have tried
有一个微芯片指南,但我不明白他们在做什么不同:
https://microchipdeveloper.com/wireless:ble-mchp-transparent-uart-service
顺便说一下,我用flutter试过了,还是不行,所以如果有flutter的解决方案就更好了。
【问题讨论】:
-
请注意,您可能只有一项未完成的 GATT 操作。等待回调,直到执行下一个。
-
我只做一个操作,首先我等待它会连接,然后我等到我得到服务我只做一个操作,首先我等待它会连接,然后我等到我得到服务,然后只是运行它们并写入某些特征。有什么我想念的吗?
-
如果该 uuid 有多个特征,您将在第一个完成之前使用该代码进行多次写入。
-
那个uuid只有一个特征
-
您可以尝试将无响应写入作为写入类型?
标签: android android-studio flutter bluetooth-lowenergy microchip