问题描述
我正在尝试使用 node js 扫描 BLE 设备。但我在运行时遇到错误。 我已经提到了这个 Git Repo https://github.com/noble/noble
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'bluetooth-hci-socket'
Require stack:
- D:\BLE-node\node_modules\noble\lib\hci-socket\hci.js
- D:\BLE-node\node_modules\noble\lib\hci-socket\bindings.js
- D:\BLE-node\node_modules\noble\lib\resolve-bindings.js
- D:\BLE-node\node_modules\noble\index.js
- D:\BLE-node\app.js
这里是 App.js
app.js
const Noble = require("noble");
const BeaconScanner = require("node-beacon-scanner");
var scanner = new BeaconScanner();
scanner.onadvertisement = (advertisement) => {
var beacon = advertisement["iBeacon"];
beacon.RSSi = advertisement["RSSi"];
console.log(JSON.stringify(beacon,null," "))
};
scanner.startScan().then(() => {
console.log("Scanning for BLE devices...");
}).catch((error) => {
console.error(error);
});
解决方法
尝试检查 bluetooth-hci-socket
是否已正确安装和声明。 (https://github.com/noble/node-bluetooth-hci-socket#windows)
尝试使用最新的noble fork:https://github.com/abandonware/noble