如何解决使用 javascript 将数据发送到 BLE 设备将不起作用
我有一个蓝牙设备,想用 p5ble 库打开它。 https://itpnyu.github.io/p5ble-website/
设备的 UUID 为 f000aa60-0451-4000-b000-000000000000 当向特征 UUId f000aa61-0451-4000-b000-000000000000 发送 0xAEAA01646456 时,它应该打开。 我在 Android 上使用 NRF Connect 应用程序对此进行了测试,它完美地找到了。
使用我的代码,我可以连接并找到正确的特征并发送数据。但它不会开启。 这是我从脚本中得到的输出:
找到:f000aa61-0451-4000-b000-000000000000 写作 192045191029846 到特征...断开与蓝牙设备的连接...
这里可能有什么问题?
const serviceUuid = "f000aa60-0451-4000-b000-000000000000";
const characteristicsUUID = {
led:"f000aa61-0451-4000-b000-000000000000"
}
let ledCharacteristic;
let myBLE;
let buttonValue = 0;
function setup() {
myBLE = new p5ble();
// Create a 'Connect and Start Notifications' button
const connectButton = createButton('Connect and Start Notifications')
connectButton.mousepressed(connectAndStartNotify);
// Create a 'Toggle' button
const ledButton = createButton('LED on');
ledButton.position(15,15);
ledButton.mousepressed(LEDon);
}
function connectAndStartNotify() {
// Connect to a device by passing the service UUID
myBLE.connect(serviceUuid,gotcharacteristics);
}
// A function that will be called once got characteristics
function gotcharacteristics(error,characteristics) {
if (error) console.log('error: ',error);
for(let i = 0; i < characteristics.length;i++){
if(characteristics[i].uuid == characteristicsUUID.led){
ledCharacteristic = characteristics[i];
console.log("found: "+characteristicsUUID.led)
}
}
}
// A function that turns on the LED
function LEDon(){
myBLE.write(ledCharacteristic,0xAEAA01646456);
myBLE.disconnect();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。