AndroWish Bluetooth LE apps, unchanged, on Linux.
On Linux, undroidwish has a blz command for BlueZ instead of AndroWish's ble. This package provides ble on top of blz, so your app only needs one extra line. It also comes with simulated DE1 and Skale devices, so you can test without any Bluetooth hardware.
# the one line your AndroWish app needs package require blz_ble_shim # no Bluetooth hardware? use the simulator package require blz_sim package require blz_ble_shim # try the bundled examples tclsh examples/scan.tcl --sim wish8.6 examples/run_bledemo_sim.tcl
Two-minute tour
The AndroWish Bluetooth LE debugger, unaltered, in undroidwish on Ubuntu: one added line, a simulated DE1 and Skale, reading, subscribing and writing, and the tests.
What it's for
AndroWish's ble and undroidwish's blz share the same ideas but use different commands and events, so AndroWish Bluetooth apps don't run on Linux as they are. The shim translates every call and event in both directions.
Apps written for AndroWish's ble, such as the Decent Espresso de1app, run on desktop and embedded Linux with one added package require.
The blz_sim package simulates a DE1 and a Skale: they advertise, answer writes and stream weight data in the real format.
It only installs ble when no real one exists and blz is present. On Android or macOS it stays out of the way.
Two test suites pass on Tcl 8.6 and 9 (35/35 and 27/27), and on Linux it finds and connects to a real DE1, Decent Scale and Skale through a USB Bluetooth adapter.
Get started
Any of these makes package require blz_ble_shim work. For real Bluetooth on Linux you also need blz compiled from the AndroWish source; the repo has a step-by-step recipe.
./install.sh puts it in /usr/local/lib; ./install.sh --user uses your own Tcl folder with no sudo.
Put the three .tcl files in a blz_ble_shim/ folder on Tcl's auto_path, or use the single-file .tm module.
Put package require blz_ble_shim in your app. Set BLZ_ADAPTER=hciN if your adapter isn't hci0.
Simulator
blz_sim is a stand-in for blz that follows the real command's contract, backed by virtual devices:
RequestedState triggers a StateInfo notification.blz can't (it needs Linux sd-bus and BlueZ).# list the virtual devices tclsh examples/scan.tcl --sim # full GUI Bluetooth debugger, no radio wish8.6 examples/run_bledemo_sim.tcl
Technical details
blz_ble_shim runs AndroWish / Android Bluetooth-LE Tcl code unaltered on Linux/BlueZ. It installs an AndroWish-compatible ble command implemented on top of undroidwish's built-in blz (BlueZ) command. Programs written against AndroWish's ble API — for example the Decent Espresso de1app — run on desktop/embedded Linux with no code changes, save one line:
package require blz_ble_shim
It ships with a simulator (blz_sim) backed by virtual DE1 + Skale devices, for developing and testing AndroWish BLE apps on any platform, including macOS, with no Bluetooth hardware.
AndroWish (Android) provides a ble command. undroidwish on Linux instead provides blz, a different BlueZ-backed command. The two use the same concepts but different verbs and event shapes, so AndroWish BLE apps do not run as-is on Linux. This package presents the AndroWish ble surface and translates every call and event to and from blz.
your AndroWish app ──ble …──▶ blz_ble_shim ──blz …──▶ BlueZ (bluetoothd)
(unchanged) (this package) (undroidwish on Linux)
blz emits only three callbacks (scan, connection, notification) and its read / write are synchronous with no event. AndroWish apps, however, sequence on events blz never sends — the write-with-response ACK (characteristic access=w), the read-completion (access=r), the per-service discovery stream (characteristic state=discovery), and the notification-enable acknowledgement (descriptor access=w). The shim synthesizes those events, delivered asynchronously (via after 0) so ordering matches Android. It also:
blz context per connection (plus one for scanning) and routes events to the right handle;blz's pull-style discovery (blz services / blz characteristics) into AndroWish's push-style discovery events;sinstance / cinstance integers AndroWish apps record and echo back.The install is guarded: it registers the global ble command only if no real ble already exists and blz is present. It also does package provide ble 1.0, so an app's own package require ble is satisfied. Everywhere else it stays inert: it does not override a real ble (Android, or macOS CoreBluetooth) and does not crash when blz is absent.
blz command contract.test/selftest_mock.tcl — 35/35 pass under tclsh8.6 and tclsh9.0: verifies write-ACK / read / discovery / CCCD synthesis, advertising-name parsing, event shapes, and ordering.test/test_shim_e2e.tcl — 27/27 pass (Tcl 8.6 and 9): the full app flow of scan → name-resolve → connect → discovery → enable/notify → write-ACK-gated writes → read → concurrent DE1 + Skale event routing → disconnect → UUID helpers.blz extension has been compiled from AndroWish source and driven by the shim end-to-end: ble state → poweredOn, UUID helpers, and the BlueZ error paths work. The unmodified bledemo BLE-debugger GUI runs live on Linux under native wish8.6 + real blz + the shim.undroidwish's downloadable prebuilt binaries do not bundle blz; it lives in the AndroWish source tree and must be compiled in (see below).
Pick either install form — both make package require blz_ble_shim work.
A. Installer
./install.sh # -> /usr/local/lib (tclsh/wish/undroidwish; may need sudo)
./install.sh --user # -> ~/Library/Tcl (no sudo)
./install.sh /my/libdir # -> a directory of your choice
B. By hand — copy pkgIndex.tcl, blz_ble_shim.tcl, and blz_sim.tcl into a blz_ble_shim/ directory on Tcl's auto_path, or point TCLLIBPATH at wherever you put them. Cloning the repo and putting the clone on auto_path also works — the repo root is a valid package directory.
C. Single-file Tcl Module — copy blz_ble_shim.tcl renamed blz_ble_shim-1.0.tm to a directory on tcl::tm::path.
Then, in your app:
package require blz_ble_shim
Override the BlueZ adapter with the environment variable BLZ_ADAPTER=hciN (default hci0).
Building the real blz (Linux). undroidwish's prebuilt binaries do not bundle blz; it must be compiled from the AndroWish source tree. docs/BUILDING_BLZ.md has a step-by-step recipe. The gotchas:
blzlib (from undroid/blz/blzlib/), not the upstream infsoft-locaware/blzlib — AndroWish patched it to add the Tcl event-loop hooks blz_get_fd / blz_get_events / blz_handle_read; upstream lacks them and fails at load with undefined symbols.-lsystemd -lbluetooth explicitly (blzlib calls sd_bus_* directly; the TEA build doesn't add them).tcl8.6-dev, libbluetooth-dev, libsystemd-dev, gcc, tk8.6.The companion blz_sim package is a simulated blz (matching the real command contract) backed by virtual DE1 and Skale peripherals. They advertise, complete discovery, ACK writes, react to writes (a RequestedState write drives a StateInfo notification), and stream weight notifications in the real 18-byte Atomax format. This allows development and testing on any platform, including macOS, where the real blz cannot run (it needs Linux sd-bus + BlueZ).
package require blz_sim ;# simulated blz + virtual devices
package require blz_ble_shim ;# `ble` on top of the simulator
Run the bundled examples:
tclsh examples/scan.tcl --sim # list the virtual devices
wish8.6 examples/run_bledemo_sim.tcl # full GUI BLE debugger, no radio
examples/bledemo.tcl is a LightBlue-style BLE debugger (scan → connect → browse services → read / subscribe / write). It is an unmodified AndroWish app, run as-is on the shim.
Limitations. blz (BlueZ) exposes a smaller surface than Android's GATT layer, so a few AndroWish features are approximated or unavailable — none of which affect typical central-role apps (DE1, scales, sensors):
pair / unpair are no-ops (fine for Just-Works / unencrypted peripherals).sinstance / cinstance are constants (devices with unique UUIDs are unaffected).Source, installer, tests, examples, and the blz build recipe: github.com/johnbuckman/blz_ble_shim. Tcl/Tk (BSD-style) license.