bbangert

bbangert

bluez - bluez over d-bus library

I’ve been working on some Elixir based projects for awhile now, slowly spinning out libraries from the project as they stabilize some and thought this one might be useful for the community. My project is Nerves based and needed bluetooth support, so I originally tried blue_heron, then evaluated whether Bluex had the support I needed, but eventually ended up building this out with claude.

Features

  • One supervisor that brings up dbus-daemon, bluetoothd -E, and (optionally) bluealsad, with crash-isolation and restart ordering (:rest_for_one) already worked out — an audio fault never restarts scanning, a bus restart rebuilds everything above it.
  • Passive and active BLE scanning, runtime-switchable. Passive mode uses BlueZ’s AdvertisementMonitor1 (no scan requests — peripherals don’t burn battery answering); active mode collects SCAN_RSP data.
  • Advertisement reconstruction — BlueZ only exposes parsed properties; they’re re-serialized into AD byte structures, emit-gated (first sighting / payload change / RSSI heartbeat) and LRU-capped, then fanned out through your on_advertisement: fun.
  • Handle-keyed GATT client — connect / service discovery / read / write / notify / pair / unpair / clear-cache, with a documented, host-agnostic event contract delivered through your on_gatt_event: function. Generation-stamped so late replies can’t corrupt replaced connections.
  • Pairing agent that authorizes exactly the pairings your code initiated.
  • bluez-alsa integration (optional) — enumerates ready-to-open A2DP playback PCMs and signals your app when the set changes.
  • No host coupling — configuration flows exclusively through start_link/1 opts (functions, a PubSub, child specs); no Application.get_env, no callbacks into named host modules.

While this library is built for Nerves, it should work on a normal linux host. The passive scanning required some additional changes to the rebus library that I’ve opened a PR to upstream, the current 0.1 release of bluez vendors it in. This passive scanning mode is extremely efficient which was the primary reason I went with this approach.

I’ve been using this in deployed code for weeks now where its been very stable, the early version is mainly to reflect that it might still need changes.

For this project I’ve mainly been building out features with the Elixir Phoenix plugin for claude code, with manual and AI reviews as well as frequent audits to try and prevent any AI sloppiness from manifesting. :crossed_fingers:

Most Liked Switch mode

quatermain

quatermain

Hi, creator of that plugin for Elixir/Phoenix development with Agents here. Thanks for using it and mentioning it here. Happy to see users of it. Fyi if you want help to contribute to plugin and even improve experience with Nerves and others, there is way how you (we) can retrospectively analyze your sessions and generate improvements for plugin or new skills at all. Whole framework is (hidden) inside the plugin.

Where Next?

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
385 14863 120
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
zachdaniel
Introducing AshStorage! Attachment and file management that slots directly into your resources :smiling_face_with_sunglasses: I had hope...
New

Other Trending Topics Top

type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
yureehuh
Introduction Founded in 2017 by landscape ecologist and fire mitigation expert Harry Statter, Frontline developed the first fully integra...
New

We're in Beta

About us Mission Statement