Pocket Chip updated with Bluez 5.46 first try worked great!

I got my pocket chip in the mail this past week. And I’ve been curious if I had to do anything to my bluez 5.46-1 build working on chip

Pocket Chip comes with the original CHIP (not the pro). It has some spaces and breathing room to do a lot in 3.3GB (2.6G free) of space.

On to trying out bluez 5.46;  I just installed it and it worked out of the box.   https://github.com/eSpecialized/bluez-5.46-rpi3

Pocket Chip once updated is at version Debian 8.9.

Preliminary tests;
scan on = success
scan off = success

after reboot; still running
when I removed the bluetooth from within my paired iPhone and tried to start up bluetoothctl, bluetoothd was dead.

I power cycled the device, to ensure it is still running.
bluetoothd is back online.  And it all works great. This means the firmware is loading at boot time properly.
remove (iPhone Mac address) = success.
trust 64:A5:C3:B8:9A:2B:D6 = worked
pair 64:A5:C3:B8:9A:2B:D6 = worked

I’m all paired up with my iPhone again.

What benefits does this have?
I’ll get back to this. Today is looking like a beach day for my family.  Least to say BLE works really great in Bluez 5.46, plus numerous other bug fixes since 5.23.

My true plans are really to work with the BLE and see how well it works. Also to work with some A2DP with stereo headsets and play some mp3’s.

Trying PAN with Bluez 5.46

chip@chip:~$ cat bnepconnect
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_64_A5_C3_DC_F7_1C org.bluez.Network1.Connect string:nap

chip@chip:~$ bash ./bnepconnect
method return sender=:1.18 -> dest=:1.17 reply_serial=2
string "bnep0"

chip@chip:~$ sudo vi /etc/network/interfaces

#add these two lines
auto bnep0
iface bnep0 inet dhcp

chip@chip:~$ sudo /sbin/ifup bnep0
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/bnep0/a0:2c:36:63:d3:7f
Sending on LPF/bnep0/a0:2c:36:63:d3:7f
Sending on Socket/fallback
DHCPDISCOVER on bnep0 to port 67 interval 4
DHCPDISCOVER on bnep0 to port 67 interval 9
DHCPREQUEST on bnep0 to port 67
bound to — renewal in 33235 seconds.

chip@chip:~$ ip addr show
6: bnep0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether a0:2c:36:63:d3:7f brd ff:ff:ff:ff:ff:ff
inet brd scope global bnep0
valid_lft forever preferred_lft forever
inet6 2607:fb90:8232:e7f4:a22c:36ff:fe63:d37f/64 scope global mngtmpaddr dynamic
valid_lft forever preferred_lft forever
inet6 fe80::a22c:36ff:fe63:d37f/64 scope link
valid_lft forever preferred_lft forever

Contact me here;


todo: finish this post later.

todo: power draw requirements for bluetooth PAN over WIFI.

Raspberry PI with I2S audio out, and trying I2S audio in.

The basic concept is that I2S Audio runs on SPI1 on the PI3.  The PI2/PI3 have 2 SPI’s (SPI1 and SPI0). With SPI0 evidently being a full featured interface with two enable pins, while SPI0 has only one enable pin.

It does appear possible to run 4 audio streams on I2S thru SPI0.  The speaker Bonnet would have 2 streams for stereo output, and the MEMS mic would have 2 streams for stereo input. To wire them together causes contention in the drive currently.  With two different drivers to drive two different audio functions on the same bus.   I have limited knowledge on how to use either SPI thru the new kernel interfaces (device tree).

RPI pinout

The Adafruit Speaker Bonnet uses I2S and a MISO (Master In Slave Out) pin.  The I2S mic uses a MOSI (Master Out Slave IN) pin. I2S is via SPI1.

The speaker out uses snd_bcm2835, and mic in uses a kernel module you have to build.

At the moment the two are conflicted;

[    3.540234] i2c /dev entries driver
[    3.644933] my_loader: loading out-of-tree module taints kernel.
[    3.650534] request module load 'bcm2708-dmaengine': 0
[    3.650955] register platform device 'asoc-simple-card': 0
[    3.651115] Hello World :)
[    3.841256] systemd-udevd[147]: starting version 215
[    4.285633] gpiomem-bcm2835 3f200000.gpiomem: Initialised: Registers at 0x3f200000
[    4.334938] snd-hifiberry-dac soc:sound: pcm5102a-hifi <-> 3f203000.i2s mapping ok
[    4.546427] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[    4.621951] bcm2835-i2s 3f203000.i2s: Trying to bind component to card "snd_rpi_simple_card" but is already bound to card "snd_rpi_hifiberry_dac"
[    4.621966] asoc-simple-card asoc-simple-card.0: ASoC: failed to instantiate card -19

So what would the next steps be to have both types of I2S audio working, microphone in, and speaker output through the same SPI1?

I already looked some at the kernel my_loader.c and other c sources. Not being familiar with Kernel module compiling it has some very special changes.

I think the easiest way to have both I2S devices working on the same Raspberry PI would be to use the two separate SPI’s one for each task. It wasn’t immediately apparent on how to do this, so I think it requires ‘digging’ to find a solution.

MEM’s mic module;



Speaker Module;

It’s just a start.

So these two bits of info talk about using SPI0, and that it has two enable pins out on the pin header.



Bluez 5.46 hciuart configuration changes

Update; 2017-08-13 Sunday
I discovered the problem is really in the tools/hciattach_bcm43xx.c file
I have now uploaded a patch to the git repo.

1. The speed cannot be set before the fiimware is uploaded

2. Wait 1 second before the reset command is sent.

Patch information;

git diff tools/hciattach_bcm43xx.c
diff --git a/tools/hciattach_bcm43xx.c b/tools/hciattach_bcm43xx.c
index 81f38cb..13a877c 100644
--- a/tools/hciattach_bcm43xx.c
+++ b/tools/hciattach_bcm43xx.c
@@ -43,7 +43,7 @@
#include "hciattach.h"
-#define FIRMWARE_DIR "/etc/firmware"
+#define FIRMWARE_DIR "/lib/firmware"
#define FW_EXT ".hcd"
@@ -368,8 +368,6 @@ int bcm43xx_init(int fd, int def_speed, int speed, struct termios *ti,
if (bcm43xx_locate_patch(FIRMWARE_DIR, chip_name, fw_path)) {
fprintf(stderr, "Patch not found, continue anyway\n");
} else {
- if (bcm43xx_set_speed(fd, ti, speed))
- return -1;
if (bcm43xx_load_firmware(fd, fw_path))
return -1;
@@ -380,6 +378,7 @@ int bcm43xx_init(int fd, int def_speed, int speed, struct termios *ti,
return -1;
+ sleep(1);
if (bcm43xx_reset(fd))
return -1;

Nikolay patch; This has the binary file in it hciattach you can just replace yours with..

Nikolay solution Is here;

Nikolay (2xl) wrote on 2017-04-04:
I did the same patch – modify firmware patch and speed initialization patch… and I got bluetooth working on RPi!

############################## older information

When you upgrade to the latest bluez 5.46-1 everything will work as of 2017-08-12.

goal;  that firmware simply loads on boot and bluetooth works.

Indications that firmware loading failed;
   the mac address is all AA’s

hci0: Type: Primary Bus: UART
BD Address:  AA:AA:AA:AA:AA:AA ACL MTU: 1021:8 SCO MTU: 64:1
RX bytes:2095 acl:0 sco:0 events:118 errors:0
TX bytes:1974 acl:0 sco:0 commands:118 errors:0

How does it work to update bluez-5.46 then later not?

The Chip still has its firmware uploaded, until you reboot. Then the firmware needs to be reloaded.  And there is the change;

/etc/firmware is expected location from hciattach
BCM43430A1.hcd << one file needed

/var/firmware is where all the RPI’s firmware is located.
/var/firmware/BCM43430A1.hcd << cp this

mkdir /etc/firmware
cp /var/firmware/BCM43430A1.hcd /etc/firmware


Other related files;


My final analysis in retrospect;
The bluez 5.23 package that is in Jessie has an edit not part of the patches in tools/hciuart_bcm43xx.c, and this lead to a missed non working update to 5.46.  All is working in the 5.46-1 release.

Bluez 5.46 and Personal Area Network PAN connectivity with RPI3

For all purposes PAN connection should work with a lot of revisions of Bluez. This is really focused on 5.46 but the changes to get PAN connection from 5.23 should still work.

#Check the version of your software first;
bluetoothctl -v

Paring serves multiple purposes;
1.Being able to connect by PAN with established services.
In order for PAN to become an option, your smart phone must have Hot Spot for bluetooth enabled.

To do it properly for a PAN connection to an iPhone;
a. Turn on “hotspot” on your iPhone
b. Ensure its only set to bluetooth and USB.
c. Begin the Pair process from the linux side.

pi@billspi3:/usr/src $ bluetoothctl
[NEW] Controller B8:27:EB:1E:EF:45 billspi3 [default]
[NEW] Device 64:A5:C3:DC:F7:1C Bills iPhone6+
Agent registered

[bluetooth]# remove 64:A5:C3:DC:F7:1C
[DEL] Device 64:A5:C3:DC:F7:1C Bills iPhone6+
Device has been removed

[bluetooth]# pairable on
Changing pairable on succeeded


[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:1E:EF:45 Discovering: yes
[NEW] Device 64:A5:C3:DC:F7:1C Bills iPhone6+
[bluetooth]# scan off

[CHG] Controller B8:27:EB:1E:EF:45 Discovering: no
Discovery stopped

[bluetooth]# trust 64:A5:C3:DC:F7:1C
[CHG] Device 64:A5:C3:DC:F7:1C Trusted: yes
Changing 64:A5:C3:DC:F7:1C trust succeeded

[bluetooth]# pair 64:A5:C3:DC:F7:1C
Attempting to pair with 64:A5:C3:DC:F7:1C
[CHG] Device 64:A5:C3:DC:F7:1C Connected: yes

Request confirmation
[agent] Confirm passkey 675499 (yes/no): yes

[CHG] Device 64:A5:C3:DC:F7:1C Modalias: bluetooth:v004Cp6F01d0A30
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00000000-deca-fade-deca-deafdecacafe
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00001000-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C ServicesResolved: yes
[CHG] Device 64:A5:C3:DC:F7:1C Paired: yes

Pairing successful
[CHG] Device 64:A5:C3:DC:F7:1C ServicesResolved: no
[CHG] Device 64:A5:C3:DC:F7:1C Connected: no


Once Paired this way, you can use PAN to connect;

Bluez makes extensive use of Dbus, so the best way to get that connection rolling is to send this NAP command thru the dbus at the proper device.

sudo dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_64_A5_C3_DC_F7_1C org.bluez.Network1.Connect string:"nap"

Successful Output;
method return sender=:1.28 -> dest=:1.45 reply_serial=2
string “bnep0”

sudo dbus-send –system –print-reply –type=method_call –dest=org.bluez /org/bluez/hci0/dev_64_A5_C3_DC_F7_1C org.bluez.Network1.Disconnect

You can form a second PAN connection from your PC/MAC.

Note: PAN allows multiple devices to connect to it.

After about 1 minute for the connection to settle, you can then ssh to the PI so long as you are on the same PAN connection.

Turn off all other connections temporarily;

sudo ifdown wlan0
sudo ifdown eth0
sudo ifconfig wlan0 down
sudo ifconfig eth0 down

NOTE: when you turn off WLAN0 or ETH0, and you were SSH’d, expect large long delays and disconnect. Simply reconnect after waiting about 1 minute for the PAN connection to settle.

Raspbian on the Pi3 comes setup with mDNS so you simply just look for it by <name>.local

Williams-iMac:Downloads speccy67$ ping billspi3.local
PING billspi3.local ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=26.763 ms
64 bytes from icmp_seq=1 ttl=64 time=77.890 ms
64 bytes from icmp_seq=2 ttl=64 time=31.794 ms
64 bytes from icmp_seq=3 ttl=64 time=31.039 ms

ssh pi@billspi3.local

Introspecting the Dbus to find the Network Device Name;

You can use d-feet and inspect the /org/bluez/hci0 interface to find the PAN device.

sudo dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.freedesktop.Dbus.Introspectable.Introspect

sudo dbus-send –system –print-reply –type=method_call –dest=org.bluez /org/bluez/hci0 org.freedesktop.Dbus.Introspectable.Introspect | grep “node name”

</method></interface><node name=”dev_64_A5_C3_DC_F7_1C”/></node>”

To compose your dbus send command;

1. sudo dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0
2. /dev_64_A5_C3_DC_F7_1C
3. org.bluez.Network1.Connect string:"nap"

sudo dbus-send –system –print-reply –type=method_call –dest=org.bluez /org/bluez/hci0/dev_64_A5_C3_DC_F7_1C org.bluez.Network1.Connect string:”nap”

Measuring the speed and time

LTE 2 bars; 13 feet away from RPI3, 1 foot next to OSX
pi@billspi3:~ $

time wget http://www.blog.willandnora.com/downloads/gatt-service
--2017-08-05 19:16:42-- http://www.blog.willandnora.com/downloads/gatt-service
Resolving www.blog.willandnora.com (www.blog.willandnora.com)...
Connecting to www.blog.willandnora.com (www.blog.willandnora.com)||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 221880 (217K) [text/plain]
Saving to: ‘gatt-service’
gatt-service 100%[====================================================================================>] 216.68K 62.7KB/s in 3.5s

2017-08-05 19:16:46 (62.7 KB/s) – ‘gatt-service’ saved [221880/221880]
real 0m4.459s
user 0m0.040s
sys 0m0.020s

Splitting the difference; iPhone between both devices
LTE 2 bars; 6 feet from OSX, 7 feet from RPI3.
pi@billspi3:~ $ time wget http://www.blog.willandnora.com/downloads/bluez-5.46-deb-src.tar.gz
–2017-08-05 19:18:55– http://www.blog.willandnora.com/downloads/bluez-5.46-deb-src.tar.gz
Resolving www.blog.willandnora.com (www.blog.willandnora.com)…
Connecting to www.blog.willandnora.com (www.blog.willandnora.com)||:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 2369419 (2.3M) [application/x-tar]
Saving to: ‘bluez-5.46-deb-src.tar.gz’
bluez-5.46-deb-src.tar.gz 100%[====================================================================================>] 2.26M 84.9KB/s in 27s
2017-08-05 19:19:23 (84.3 KB/s) – ‘bluez-5.46-deb-src.tar.gz’ saved [2369419/2369419]
real 0m27.911s
user 0m0.050s
sys 0m0.140s

Bluez 5.46 And BLE quick test

Once you have upgraded to Bluez 5.46 from the previous post;

You can perform a quick BLE test with this file

To start your BLE adventure;
sudo hciconfig hci0 leadv 0 #this sets LE advertising on and as ‘connectable’
./gatt-service #starts the service

The source for gatt-service;
inside the bluez/tools folder is all the source you need to get started with your own Linux BLE Applet.

How can I view the BLE service?
there are lots of BLE exploring apps, I use the “LightBlue” App on my iPhone.

Build Bluez 5.46 yourself for your Debian Jessie RPI3

Updated on 2017-08-13 Sunday – all working with 5.46-1 on RPI3.
All patches that were included as part of ‘stretch’ deb source Bluez 5.43 are now in 5.46-1

You can git the source package contents here;
git clone https://github.com/eSpecialized/bluez-5.46-rpi3.git


Pre-built packages ready to install;

Why would you want to do this?
-To get the latest BLE (Low Energy Features) of Bluez, its required.
-A lot of bug fixes were made since 5.23 that is available on RPI3 Jessie that are needed for BLE to work reliably.
-Using a debian package allows for a clean upgrade path. Files are guaranteed to upgrade as opposed to “make install” over a running bluetooth system which doesn’t work.
-Debian Stretch doesn’t include the latest bluez 5.46, it comes close but I found that (during May 2017) that BLE didn’t function correctly.

Note: This was built on a RPI3 with Jessie.

Steps are intentionally missing, you will need to make up the differences to get the new source into the old directory, update the changelog in the ./debian folders with dch -i and a few other things to get a new build.  In my source package all this done for convenience.

How I made it;
#Activate src in /etc/apt/sources.list
# Uncomment line below then ‘apt-get update’ to enable ‘apt-get source’

vi /etc/apt/sources.list

deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi

sudo apt-get install ccache  #configure this is required! ie Add to Path!
sudo apt-get install build-essential devscripts lintian diffutils patch patchutils
cd /usr/src
apt-get source bluez
apt-get build-depend bluez

#grab a version from bluez.org

cd bluez-5.23

#untar the source ball in the new directory

#How to build it;
#On the RPI3 it takes about 15 minutes without ccache
time dpkg-buildpackage -rfakeroot -uc -b

real 5m48.312s #<< using ccache
user 4m0.350s
sys 0m24.680s

How to clean it;

dpkg-buildpackage -rfakeroot -Tclean

Find what bluez packages you have installed now;

pi@billspi3:/usr/src $ dpkg -l | egrep -e '^\||blue'
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
ii bluej 3.1.7b all A simple but powerful Java IDE.
ii bluez 5.43-2 armhf Bluetooth tools and daemons
ii bluez-firmware 1.2-3+rpi1 all Firmware for Bluetooth devices
ii libbluetooth3:armhf 5.43-2 armhf Library to use the BlueZ Linux Bluetooth stack
ii pi-bluetooth 0.1.3 armhf Raspberry Pi 3 bluetooth
ii pulseaudio-module-bluetooth 5.0-13 armhf Bluetooth module for PulseAudio sound server

How to install only what you need;
sudo dpkg -i <package name>
#From the above list, you can see I only need bluez and libbluetooth3.
sudo dpkg -i bluez_5.46_armhf.deb libbluetooth3_5.46_armhf.deb

Bluez 5.46 for RaspberryPi 3 (pi3)

Updated on 2017-08-13 Sunday – all working with 5.46-1 on RPI3.
All patches that were included as part of ‘stretch’ deb source Bluez 5.43 are now in 5.46-1

It’s been a while since I last blogged. I had to wipe out my previous blog and start over a lot of life has changed in 3 years since my last updates. It was time to start new anyway! 🙂

I’ve been working with Bluez 5.45 for quite some time. I decided to help out the pi3 maker community with a Debian package made in Jessie to assist those who would seek to use the latest Bluez for it’s BLE (Low Energy) capabilities, and the updated bluetooth classic capabilities like PAN.

This is to test out the latest Bluez 5.46

I can say with certainty that USB dongles do work.
RaspberryPi 3 (RPI3) – Built in Chipset = Works out of the box with this update!

Use  from here;
wget http://www.blog.willandnora.com/downloads/bluez546.tar.gz

Find out what you have installed first;
dpkg -l | grep blue

Install the required packages;
dpkg -i <package>

Happy Bluez adventures with your BLE!