Bluetooth PAN serving a Phoenix app

For my first Nerves project, I would like to create a Phoenix application that would be available only via Bluetooth Personal Area Network (PAN).

I’ve never done this before, but from what I could understand it would be feasible.

During my researches, I came across this stackoverflow post explaining in detail how to setup a Bluetooth PAN on Raspbian.

So I tried to reproduce the steps for Nerves :

  • First, I created a new system based on nerves_system_rpi3
  • On this system I installed bluez-tools and bluez-utils packages
  • I’ve also activated the Bluetooth subsystem support in make linux-menuconfigNetworking Support

Once the firmware burn on my SD card and the Raspberry started, I executed the following commands :

# Run D-Bus & Bluetoothd daemons
mkdir -p /var/run/dbus
/usr/bin/dbus-daemon --system
/usr/libexec/bluetooth/bluetoothd &

# Create PAN interface
ip link add pan0 type bridge

# Configure interface
ifconfig pan0 192.168.50.1 netmask 255.255.255.0 up

Until then, no problem.
But when I tried to execute bt-agent -c NoInputNoOutput or bt-network -s nap pan0, I got the following error:

bt-agent: bluez service is not found
Did you forget to run bluetoothd?

However, when I display the list of processes, I can see bluetoothd running.

I would like to know if anyone has ever had this problem or if anyone has ever succeeded in setting up a Bluetooth PAN.

Thanks in advance.

You’re following the steps that I’d take if I were doing this. As a sanity check, does this work on Raspbian? And I wonder if dmesg shows any errors?

Also, not that this is a bad thing, but this is an ambitious first project. I think that you’ll be the first person to get Bluetooth PANs working with Nerves, so I’m very curious to hear your progress.

1 Like

First of all, thank you for your answer.

I just tried this afternoon on Raspbian and I was able to setup a working PAN.
For dmesg, there is no error.

I like to have ambitious projects when I try out a technology. It allows me to really try to understand how it works, especially when I’m trying to do something and there is little documentation on the topic ^^

I will try again and I will update this post if I manage to get the NAP working on Nerves.

1 Like

Small progress: After several hours of debugging, it seems that the problem comes from bluetoothd.

When I run it on Raspbian with debug mode (bluetoothd -nd) it finds my Bluetooth controller:

bluetoothd[1249]: src/adapter.c:read_index_list_complete() Number of controllers: 1

but he doesn’t find it on Nerves:

bluetoothd[279]: src/adapter.c:read_index_list_complete() Number of controllers: 0

So I tried to attach it manually by following the documentation on the Alpine website with

btattach -B /dev/ttyAMA0 -P bcm -S 115200 -N &

But I now have the following errors (dmesg):

[  139.810619] Bluetooth: Core ver 2.22
[  139.823002] NET: Registered protocol family 31
[  139.835931] Bluetooth: HCI device and connection manager initialized
[  139.851048] Bluetooth: HCI socket layer initialized
[  139.864618] Bluetooth: L2CAP socket layer initialized
[  139.878279] Bluetooth: SCO socket layer initialized
[  226.396734] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[  226.410839] Bluetooth: BNEP socket layer initialized
[  724.174859] Bluetooth: HCI UART driver ver 2.3
[  724.187883] Bluetooth: HCI UART protocol H4 registered
[  724.201545] Bluetooth: HCI UART protocol BCSP registered
[  724.215564] Bluetooth: HCI UART protocol Broadcom registered
---> [  726.312378] Bluetooth: hci0: command 0x0c03 tx timeout
---> [  734.552396] Bluetooth: hci0: BCM: Reset failed (-110)
1 Like

think you need to comment out dtoverlay=pi3-miniuart-bt in config.txt

can’t really grasp it all - but believe that overlay moves BT to tttyS0 aka the mini-uart, so it’s not on ttyAMA0 - see https://github.com/raspberrypi/documentation/blob/master/configuration/uart.md

2 Likes

Thanks! You were right! My controller is now properly detected.

Unfortunately, I always get the same errors when I run bt-agent -c NoInputNoOutput and bt-network -s nap pan0:

(bt-agent:361): GLib-CRITICAL **: 22:56:40.140: PCRE library is compiled without UTF8 support   
(bt-agent:361): GLib-CRITICAL **: 22:56:40.140: PCRE library is compiled without UTF8 properties support
bt-agent: bluez service is not found
Did you forget to run bluetoothd?

It seems that bluetoothd wants to write to /var/lib/bluetooth but it can’t (read-only partition):

bluetoothd[333]: Unable to open adapter storage directory: /var/lib/bluetooth/XX:XX:XX:XX:XX:XX

I’ll keep digging.

1 Like

Great work figuring that out so far! :rocket:

It’s been a while since I’ve done it, but I believe if you want to make that directory be writable, you can either configure the application to write to somewhere that is writable, mount a writable partition there, or use a symlink to redirect that directory to a place that is writable.

https://hexdocs.pm/nerves/advanced-configuration.html

I thought we used to have an example of doing that e.g. for making the /etc/resolv.conf file and friends be writable, but I’m having trouble finding a link to that now. Maybe someone else knows what I’m talking about and/or can fill in the gap.

1 Like

Thanks for your help!

I think I’ll create a symlink to /tmp/bluetooth because I don’t think it’s necessary to make this folder persistent.

Currently I don’t really understand how to do it and I would be happy to have some documentation on the subject or a code to study.

Small progress: I added a symbolic link from /var/lib/bluetooth to /tmp/bluetooth (via rootfs_overlay) but I still have the same error.

(bt-agent:363): GLib-CRITICAL **: 13:30:51.254: PCRE library is compiled without UTF8          
(bt-agent:363): GLib-CRITICAL **: 13:30:51.255: PCRE library is compiled without UTF8 properties support
bt-agent: bluez service is not found
Did you forget to run bluetoothd?

Now I don’t understand what the problem is since I don’t have any error anymore (neither from dmesg nor from bluetoothd).