vojtamolda / homebridge-bluetooth

Homebridge plugin to expose BLE peripherals as HomeKit accessories.
https://www.npmjs.com/package/homebridge-bluetooth
MIT License
174 stars 29 forks source link

Install fails on Homebridge on Raspberry Pi3+ #34

Open simplenotezy opened 3 years ago

simplenotezy commented 3 years ago

Upon running npm install -g noble I get below error:

make: *** [binding.target.mk:109: Release/obj.target/binding/src/BluetoothHciSocket.o] Error 1
make: Leaving directory '/usr/local/lib/node_modules/noble/node_modules/bluetooth-hci-socket/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 5.4.51-v7+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/noble/node_modules/bluetooth-hci-socket
gyp ERR! node -v v12.19.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: xpc-connection@~0.1.4 (node_modules/noble/node_modules/xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for xpc-connection@0.1.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bluetooth-hci-socket@0.5.1 (node_modules/noble/node_modules/bluetooth-hci-socket):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bluetooth-hci-socket@0.5.1 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ noble@1.9.1
updated 1 package in 47.272s

If I run it with sudo (which I believe I am not supposed to, as my node_modules is owned by my current user), I get this error:

pi@homebridge:~ $ sudo npm install -g noble

> usb@1.6.3 install /usr/local/lib/node_modules/noble/node_modules/usb
> prebuild-install --verbose || node-gyp rebuild

prebuild-install info begin Prebuild-install version 5.3.6
prebuild-install WARN install EACCES: permission denied, access '/root/.npm'
gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/root/.cache/node-gyp/12.19.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/noble/node_modules/usb/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/noble/node_modules/usb/.node-gyp'
gyp ERR! System Linux 5.4.51-v7+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/noble/node_modules/usb
gyp ERR! node -v v12.19.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok

> bluetooth-hci-socket@0.5.1 install /usr/local/lib/node_modules/noble/node_modules/bluetooth-hci-socket
> node-gyp rebuild

gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/root/.cache/node-gyp/12.19.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/noble/node_modules/bluetooth-hci-socket/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/noble/node_modules/bluetooth-hci-socket/.node-gyp'
gyp ERR! System Linux 5.4.51-v7+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/noble/node_modules/bluetooth-hci-socket
gyp ERR! node -v v12.19.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: xpc-connection@~0.1.4 (node_modules/noble/node_modules/xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for xpc-connection@0.1.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: usb@1.6.3 (node_modules/noble/node_modules/usb):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: usb@1.6.3 install: `prebuild-install --verbose || node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bluetooth-hci-socket@0.5.1 (node_modules/noble/node_modules/bluetooth-hci-socket):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bluetooth-hci-socket@0.5.1 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ noble@1.9.1
updated 1 package in 13.782s

Any ideas on how I can proceed?

gdavids57 commented 2 years ago

This plugin relies on the noble utility to implement a BLE Central device. The bluetooth-hci-socket version relied upon by the noble package does not work with nodejs versions newer than v8. The abandonware version of bluetooth-hci-socket will build on my RPi using nodejs v14. (see https://www.npmjs.com/package/@abandonware/bluetooth-hci-socket). I'm still working to get noble to use the alternate bluetooth module.

uswong commented 2 years ago

Any solution to this issue yet?

I have successfully installed home bridge-bluetooth but homebridge log shows the following error:

Screen Shot 2022-06-15 at 1 31 24 pm

Any help is much appreciated.

uswong commented 2 years ago

The solution suggested by @gdavids57 actually works for me. Please do not forget to change all instances of require('bluetooth-hci-socket') to require('@abandonware/bluetooth-hci-socket').

Moreover, the chalk version 5 does not work for this plugin as the moment. So what you need to do is to downgrade chalk version to version 4. What I have done is as follow:

sudo npm uninstall chalk sudo npm install chalk@4.1.2

uswong commented 2 years ago

I have a Bluetooth version of Xiaomi Power Strip 2 (model: qmi.plug.pvs3). It connected ok, but no service discovered.

This is my config file:

 {
     "platform": "Bluetooth",
     "accessories": [
         {
             "name": "Xiaomi Outlet 2",
             "address": "68:AB:BC:07:50:AD",
             "services": [
                 {
                     "name": "JBL",
                     "type": "Outlet",
                     "UUID": "80c77a06-ec5c-11ec-8ea0-0242ac120002",
                     "characteristics": [
                         {
                             "type": "On",
                             "UUID": "80c77a06-ec5c-11ec-8ea0-0242ac120002"
                         }
                     ]
                 }
             ]
         }
     ]
 }

The log on Homebridge as follow:

[15/06/2022, 9:43:48 pm] [Bluetooth] [Xiaomi Outlet 2] Connected | Xiaomi Outlet 2 (68:AB:BC:07:50:AD)
[15/06/2022, 9:43:48 pm] [Bluetooth] [Xiaomi Outlet 2] No services discovered

What have I done wrong?

kard8 commented 2 years ago

The solution suggested by @gdavids57 actually works for me. Please do not forget to change all instances of require('bluetooth-hci-socket') to require('@abandonware/bluetooth-hci-socket').

Hi @uswong.

Can you please tell me how to find the instances as mentioned in your reply

uswong commented 2 years ago

cd to your homebridge-bluetooth plugin directory and try using the following command: grep -r bluetooth-hci-socket *|grep require