我正在尝试对蓝牙设备进行逆向工程,以便我可以创建自己的应用程序来与之通信。
我已经设法从我的Android手机获取蓝牙日志,并且还能够通过网络连接到蓝牙设备。
不幸的是,每当我尝试将值写入特征时,都会收到错误:bluetooth.html:1 Uncaught (in promise) DOMException: GATT operation failed for unknown reason.
在 Wireshark 中,我在写入请求中找到的值是:0120030000000000
如何在 Javascript 中发送它? 我尝试了以下方法,但都不起作用:
characteristic.writeValue(0x0120030000000000)
characteristic.writeValue(new Uint16Array([0x0120030000000000]));
characteristic.writeValue(new Uint8Array([0x0120030000000000]));
characteristic.writeValue(new Uint16Array([0x0120030000000000]));
characteristic.writeValue(new TextEncoder("utf-16").encode(0x0120030000000000));
我知道原始值是0120030000000000的,如何通过 ArrayBuffer 发送它?
假设Wireshark已经用十六进制编码了数据,那么你应该创建一个这样的Uint8Array
,
new Uint8Array([0x01, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00])
如果方便在程序中将此数据表示为字符串,则可以编写一个函数来构建Uint8Array
,方法是一次解析两个字符串。