ejpcmac

ejpcmac

Getting Bluetooth work in a Nerves application with BlueZ/DBus

I am using Bluex to communicate with a BLE device from an Elixir application. It works great on a Linux host with a Bluetooth dongle, but I have troubles to get it work on a Raspberry Pi with the same dongle.

So far, I have built a custom Nerves system, including Bluetooth support in the Kernel and bluez-utils. Using the CLI utils, I am able to scan and view my device, so the system is OK. Now, the issue is that Bluex is not finding the DBus socket. There is effectively no /run/dbus/system_bus_socket.

Is there something I can do to have the DBus socket present? As Nerves systems are really minimalistic, I assume nothing is started apart from the BEAM, so I should start DBus and bluetoothd myself, isn’t it? If you have hints on how I should do that properly, I’m all ears!

Most Liked

ejpcmac

ejpcmac

Yes, I am writing a tiny app to test that a BLE device works properly, and Elixir is a great language to get things done quickly.

Thanks for the tip, I’ll check muontrap and see what I can do from that.

fhunleth

fhunleth

Co-author of Nerves

In your Elixir application’s start function, call File.mkdir("/run/dbus").

Here’s the longer answer:

The default Nerves configuration mounts several different filesystems. The main one, /, is read-only and contains OTP, Linux programs, and your Elixir application and all of its dependencies. You can add to that one via the rootfs_overlay. However, some directories are made writable at runtime. Anything placed in those directories at compile-time isn’t accessible at runtime and that’s what you’re running into. Examples are the /tmp, /dev, /run, and /root directories. In the case of /tmp, /dev, and /run, Nerves mounts small in-memory filesystems. They’ll lose their contents on reboots so if you’re going to create a directory in them, you need to do it each boot. This is generally desirable since if something gets messed up in them, a reboot returns you to a good state. In the case of /root, a writable filesystem is mounted there so that iex prompt history and other things survive reboots.

As a general rule of thumb, I try to avoid using the rootfs_overlay feature. Usually Linux programs have a way to tell them where their configuration files are. That lets me put the config file in a more convenient location - like in my OTP application’s priv directory and tell it to read it from there. If programs need to write data, I can redirect them some place on /data, etc. Of course, it’s nice to see things work once before moving paths around, so this might be something to consider after the dust settles.

ConnorRigby

ConnorRigby

Nerves Core Team

Great to see some bluetooth love.

You are on the right track. You will have to start dbus and bluetoothd manually as part of your supervision tree. Check out muontrap

Last Post!

atoncetti

atoncetti

Thanks for the great answer! That explains everything. Happy New Year, cheers!

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement