abandonware / noble

A Node.js BLE (Bluetooth Low Energy) central module : Community maintained
https://libraries.io/npm/@abandonware%2Fnoble
MIT License
526 stars 161 forks source link

Using noble within a docker container #43

Open jackbridger opened 4 years ago

jackbridger commented 4 years ago

I am trying to use noble in a node (v13.8.0) app running in a local docker container.

When I run my application I receive the below error. It seems like there is an issue with hci-socket.

`/app/node_modules/@abandonware/noble/lib/hci-socket/hci.js:75 this._socket = new BluetoothHciSocket(); ^

Error: EAFNOSUPPORT, Address family not supported by protocol at new Hci (/app/node_modules/@abandonware/noble/lib/hci-socket/hci.js:75:18) at new NobleBindings (/app/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:28:15) at Object. (/app/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:511:18) at Module._compile (internal/modules/cjs/loader.js:1151:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10) at Module.load (internal/modules/cjs/loader.js:1000:32) at Function.Module._load (internal/modules/cjs/loader.js:899:14) at Module.require (internal/modules/cjs/loader.js:1040:19) at require (internal/modules/cjs/helpers.js:72:18) at module.exports (/app/node_modules/@abandonware/noble/lib/resolve-bindings.js:13:12) { errno: 97, code: 'EAFNOSUPPORT', syscall: 'socket' } `

I found this on noble https://github.com/noble/noble/issues/805

Does anyone have a workaround?

Thanks!

rzr commented 4 years ago

I suspect problem in docker run params ? Maybe we can add a docker-compose file

jackbridger commented 4 years ago

Thanks, these are the docker commands I'm using:

docker build -t mqtt-server . docker run -it -p 9002:3002 -v $(pwd):/app mqtt-server /bin/bash

My Dockerfile:

`FROM node:latest

WORKDIR specifies the directory our WORKDIR /app RUN npm install -g nodemon COPY package.json /app/package.json RUN npm install && npm ls RUN mv /app/node_modules /node_modules COPY . /app ` Package.json:

` { "name": "TIG-docker", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@abandonware/noble": "^1.9.2-5", "mqtt": "^3.0.0" } }

`

rzr commented 4 years ago

Is the problem in mqtt or noble module ?

Maybe try to play along different network mode, I used:

https://github.com/rzr/webthing-iotjs/blob/master/docker-compose.yml#L21

jackbridger commented 4 years ago

Thanks @rzr , Having done some more research, I think it's the bluetooth module in noble because I'm running docker locally on a mac but haven't found a solution so far?

https://forums.docker.com/t/cannot-access-macbook-built-in-bluetooth-in-docker-debian-container/32819 Maybe it's not to do with noble

rzr commented 4 years ago

Sorry I am a linux user but I can give a try, may you open a PR with docker-compose file running a sample self test and I'll try it and will share you logs

C4mp3r-Grey commented 3 years ago

Hello! As AcCalzone mentioned, I am running into the same phenomenon here https://github.com/AlCalzone/ioBroker.ble/issues/422#issue-677958385

I have closed it, as it does not seem to be an AlCalzone/BLE issue then.

Any update on this here?

C4mp3r-Grey commented 3 years ago

Maybe this issue can be solved as I solved mine:

Run the container with --net host rather than shared.

Although this thread is pretty old, it may help others to find the own mistake as I did after several days? https://github.com/buanet/docker-iobroker/issues/134#issuecomment-676683897

rzr commented 3 years ago

feel free to add a chapter in readme file about using with docker

atrovato commented 3 years ago

Hi, did you run noble within a Docker container? Can you share your Dockerfile, I'm not sure of required dependencies and commands to run.

hkayann commented 2 years ago

I have developed my own npm package that depends on @abandonware/noble

I am having a similar issue. Here is the error:

[node-red-contrib-ble-sense/protocols] Error: EAFNOSUPPORT, Address family not supported by protocol

I am running Node-RED on RPi 4 that runs DietPi.

SSharshunov commented 1 year ago

Я разработал свой собственный пакет npm, который зависит от@abandonware/noble

У меня похожая проблема. Вот ошибка:

[node-red-contrib-ble-sense/protocols] Error: EAFNOSUPPORT, Address family not supported by protocol

Я запускаю Node-RED на RPi 4, на котором работает DietPi.

Use --net=host for docker cli, to resolve this problem (EAFNOSUPPORT)

ianchanning commented 3 months ago

This is indeed now written up in the README > Docker section: https://github.com/abandonware/noble/#docker

Thanks to @atrovato :heart: