BLE does not work on RPI3 (Bluez 5.23)


#1

Hello,

I’m trying to make https://github.com/resin-io-playground/wifi-connect-ble work on my rpi 3 (Resin OS 1.24.1 - SUPERVISOR 2.8.3). But I can’t reach the Bluetooth signal even if in the logs it’s ON.

This is the output of hciconfig status :

hci0:   Type: BR/EDR  Bus: UART
        BD Address: AA:AA:AA:AA:AA:AA  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING
        RX bytes:775 acl:0 sco:0 events:47 errors:0
        TX bytes:638 acl:0 sco:0 commands:47 errors:0

and hcitool | grep ver :

hcitool - HCI Tool ver 5.23

Any Idea ?


#2

Hello, I see you opened an issue - as you reported on GH, it seems there is a failure in patching the BT controller. Will give it a look in the upcoming days.


#3

It should be noted here, that code that lives in the resin-io-playground org, as the name suggests, is not normally maintained. It’s a place we dump code we think others may find useful, but want to signal that it’s not something we actively maintain. Code in our other orgs (resin-io, resin-io-modules, resin-io-projects, resin-io-library) is all maintained and kept up to date :slight_smile:


#4

Based on the @samoud’s comments on the issue, this should be fixed! Looks like the issue is not with wiffi-connect-ble, but an attempt to combine that with resin-electronjs. The latter pins the repository to the Debian ones, while the bluetooth drivers need to be installed from the Raspbian repos to work. Removing that pinning (inherited from resin-electronjs) fixes things. This whole thing does seem to make sense - and show that care needed to combine projects from separate code bases.


#5

Hi there,

I am having the very same issue here, but don’t quite understand how to fix it, despite the explainations.

I would like to combine the resin.io electronjs image with bluetooth support in order to create a digital signage solution. Everything works ok, but I can’t use the package bleacon to read out the beacons from within electronjs…

Any help would be much appreciated,
MMedial


#6

This is what I get when I start a script that is using bleacon:

A JavaScript error occurred in the main process

Uncaught Exception:
Error: The module '/usr/src/app/node_modules/bluetooth-hci-socket/build/Release/binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 48. This version of Node.js requires
NODE_MODULE_VERSION 53. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or`npm install`).
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/src/app/node_modules/bluetooth-hci-socket/lib/native.js:3:15)
    at Object.<anonymous> (/usr/src/app/node_modules/bluetooth-hci-socket/lib/native.js:17:3)

#7

hey @mmedial

It looks like the bleacon module has been compiled with a different version of node to that running on the device. Can you post your dockerfile or provide a link to the project so we can get a better idea how to help.


#8

Hello Joe,

thanks for getting back to me. Yes, I can see that the bleacon module has been compiled for a different version, but issueing “npm rebuild bluetoothctl” or “npm rebuild bleacon” does not remedy the situation, I
seem to miss something.

You asked for the Dockerfile used, find it below. Also, I am using the electronjs-boilerplate project, which in return relies on the node 6.9 image from resin as you can see (https://github.com/resin-io/resin-electronjs).

I had to use bluez 5.23-2+rpi2 taken from the bluetooth rpi3 sample, which in return, however, uses the python base image, see https://github.com/resin-io-projects/rpi3-bluetooth/blob/master/Dockerfile.template) in order to get bluetooth to work on in the electronjs image. Additionally, I must issue an

/usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -

in the start.sh script in order to get bluetooth enabled, but it works. My functionality test is a scan by issueing

hcitool lescan

which then in return finds beacons lying around.

I am foremost interested in finding a solution to get bluetooth and the bleacon module to work with electronjs on a raspberry pi3. I want to build a digital signage solution using bluetooth BLE beacons.

If this doesn’t work for any reason, I’d alternatively be interested in transplanting the electronjs project to the bluetooth sample image you are providing at resin.io, but I am unaware of all the necessary components one needs to add to make it work, especially the X server component, although I could eventually cannibalize it from the electronjs-boilerplate project.

The buetooth sample you are providing works well for me, but lacks the X server needed to display electronjs…

Thanks for your help which is much appreciated!

FROM resin/%%RESIN_MACHINE_NAME%%-node:6.9

# debian httpredir mirror proxy often ends up with 404s - editing source file to avoid it
RUN sed -i "s!httpredir.debian.org!`curl -s -D - http://httpredir.debian.org/demo/debian/ | awk '/^Link:/ { print $2 }' | sed -e 's@<http://\(.*\)/debian/>;@\1@g'`!" /etc/apt/sources.list

COPY debian-pinning /etc/apt/preferences.d/

# Install other apt deps
RUN apt-get update && apt-get install -y \
  bluez=5.23-2+rpi2 \
  samba \
  apt-utils \
  clang \
  xserver-xorg-core \
  xserver-xorg-input-all \
  xserver-xorg-video-fbdev \
  xorg \
  libdbus-1-dev \
  libgtk2.0-dev \
  libnotify-dev \
  libgnome-keyring-dev \
  libgconf2-dev \
  libasound2-dev \
  libcap-dev \
  libcups2-dev \
  libxtst-dev \
  libxss1 \
  libnss3-dev \
  fluxbox \
  libsmbclient \
  libssh-4 \
  fbset \
  libexpat-dev && rm -rf /var/lib/apt/lists/*

# Set Xorg and FLUXBOX preferences
RUN mkdir ~/.fluxbox
RUN echo "xset s off" > ~/.fluxbox/startup && echo "xserver-command=X -s 0 dpms" >> ~/.fluxbox/startup
RUN echo "#!/bin/bash" > /etc/X11/xinit/xserverrc \
  && echo "" >> /etc/X11/xinit/xserverrc \
  && echo 'exec /usr/bin/X -s 0 dpms -nocursor -nolisten tcp "$@"' >> /etc/X11/xinit/xserverrc

# Move to app dir
WORKDIR /usr/src/app

# Move package.json to filesystem
COPY ./app/package.json ./

# Install npm modules for the application
RUN JOBS=MAX npm install --unsafe-perm --production \
	&& npm cache clean && node_modules/.bin/electron-rebuild

# Move app to filesystem
COPY ./app ./

## uncomment if you want systemd
ENV INITSYSTEM on

# Start app
CMD ["bash", "npm install bleacon -g"]
CMD ["bash", "/usr/src/app/start.sh"]

#9

Hi, combining resin-electronjs and the bluetooth sample should be relatively straightforward :tools:

  1. Starting from resin-electronjs you just need to add the extra dependencies of bluez and bluez-firmware (as the bluetooth sample shows), and then
  2. expand the start.sh in resin-electronjs with the relevant scripts to start up bluetooth like you did

And after this you should be on the right track, unless I’m missing anything? :mag:


In the Dockerfile you’ve shared, you also have two CMD lines, that won’t work like that, CMD is the command that is run on container start, and only the last one is applied. I’m guessing that earlier line supposed to be a RUN npm install -g beacon like or something similar?


#10

Hi,

yes, it does.

I got bluetooth to run, my problem is bleacon which is not running because of the submodule bluetoothctl nit being compiled in the right version (node module version 48 instead of 55).

I am just stuck there - i do not know how to access bleacon from within electron, yet I need it in there.


#11

Hey @mmedial, I gave this a try today, and seems like the module works just fine for me. What I’ve done was:

  1. Add these dependencies to the apt-get list in the Dockerfile:
bluez=5.23-2+rpi2 \
bluez-firmware=1.2-3+rpi1 \
libudev-dev \

2). Add the hciattach code to the start.sh script:

echo "Attaching hci0..."
if ! /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -; then
    echo "First try failed. Let's try another time."
    /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -
fi
  1. Add the bleacon dependency to package.json (that’s the module you are using, right?)
"bleacon": "^0.5.1",
  1. Adding some demo beacon scanning code to the end of main.js:
console.log("Start scanning for beacons!");
Bleacon.startScanning();
Bleacon.on('discover', function(bleacon) {
  console.log(bleacon);
});

Here’s the screenshot of the result:

The code is added in this repo, please just check the changes, and don’t fork, as it’s a throw-away repo, really :slight_smile:

Let us know what do you think!


#12

Hey, it works!

This is awesome, I thank you very much. It was probably the missing firmware and libusbdev ?

In any case, I appreciate your help.


#13

Yes, that was probably missing indeed. bluez-firmware was in project template for BLE, and libudev-dev (not libusbdev:) was required by one of the dependencies of the bleacon Node.js module.

Hope it will work out well, and would love to hear if when you got your project up and running! :dragon: