Skip to content
cd ..~/abhay/projects/leyline.md · 4.3K · case study 08 of 09

9 files open · click a tab, or use prev / next at the bottom of the page

// case 08 — Mobile mesh · 2026

Leyline.md

An offline SOS app that carries emergency messages phone to phone over a Bluetooth mesh.

> SOS messages that hop across phones with no internet and no cell signal.

MY ROLESimulator, data layer and device services
TIMELINEOct 2026 · Code Sangam DroidRush
TEAM3 people
STACK
KotlinAndroidBluetooth LECoroutinesGradle
leyline · SOS · 3 hops
WAIT SOS raised from quick-settings tile
location fix attached · packet signed (keystore)
chunk MTU − 3 → ~180 byte chunks
relay hop 1 → hop 2 → hop 3 (no internet)
battery 12% on node C → stops relaying for others
OK delivered · alarm + notification on rescuer phone
mesh-sim: virtual nodes replay the same packet on a laptop
$
PIPELINE
1SOS tile
2Sign
3Chunk
4BLE hops
5Rescuer
NETWORKnone needed
CHUNK~180 B
LANGUAGEKotlin
works with zero bars
// 01 — context

the problem_

cat problem.md

In a flood or an earthquake, the network is the first thing to go, exactly when people need to call for help. Code Sangam 2026 DroidRush (problem 07) asked for a way to send an SOS without it.

Leyline turns nearby phones into a mesh: each one relays signed SOS packets over Bluetooth LE until one reaches someone who can help.

## constraints
  • No internet
  • No cell signal
  • Battery matters
  • BLE addresses rotate
  • Small MTU
  • Defend every line in a viva
./my-role.sh --verbose

abhay@os ~ % what did I actually do?

  1. 01Built mesh-sim, a simulator that runs the mesh on a laptop so routing can be tested without a pile of phones.
  2. 02Built the app's data layer.
  3. 03Built the device services: location, battery monitoring, topology, notifications, the alarm and the SOS quick-settings tile.
  4. 04Made relaying battery-aware: a phone below 15% that isn't charging stops relaying for others first.

[ ok ] exit 0 · 4 tasks · owner: abhay

// 02 — results

what moved_

Three numbers I'd put on a slide. Measured in production, not in a benchmark I wrote the night before.

NETWORKnoneinternet or cell neededPhone to phone over Bluetooth LE.
CHUNK~180 Bdefault chunk sizeNegotiated MTU minus 3.
BATTERY15%relay cut-offLow phones stop relaying for others first.
// 03 — architecture

how it fits_

mesh-core never imports android.*, so the router is tested on the JVM and driven by the simulator.

open architecture.excalidraw — leyline
PHONE
SOS tilequick settings
Device serviceslocation · battery
packet
MESH
mesh-corerouter · JVM-tested
mesh-bleGATT · chunks
BLE
RESCUER
Notifieralarm + notification
mesh-simlaptop test bed
request / write pathresponse / events backnode identity is never a BLE address
// 04 — key decisions

git blame me_

adr-001.md
CHOSE

A pure-Kotlin router module

REJECTED

Routing inside Android services

TRADE-OFF

An interface to maintain, but routing is tested on the JVM in seconds.

adr-002.md
CHOSE

Chunks sized from the negotiated MTU

REJECTED

A fixed packet size

TRADE-OFF

More connection bookkeeping, but every chunk fits the link it travels on (~180 bytes by default).

adr-003.md
CHOSE

The sticky battery broadcast

REJECTED

Polling the battery

TRADE-OFF

Android-specific code, but no polling and the latest value arrives the moment we register.

// 05 — under the hood

the good bit_

vim app/src/main/kotlin/dev/leyline/app/mesh/BatteryMonitor.ktKotlin
1data class BatteryState(val percent: Int, val charging: Boolean) {
2 /** Relaying for others is the first thing to give up when the phone is about to die. */
3 val low: Boolean get() = !charging && percent in 0 until LOW_PERCENT
4
5 companion object {
6 const val LOW_PERCENT = 15
7 }
8}
9
10fun start() {
11 // Sticky broadcast: registering returns the latest value immediately.
12 context.registerReceiver(receiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED))?.let(::update)
13}
NORMAL app/src/main/kotlin/dev/leyline/app/mesh/BatteryMonitor.kt13 lines · utf-8

Relaying for others is the first thing to give up when a phone is about to die. The sticky broadcast means no polling.

less lessons.txt

If I built it again, I'd change…

  1. L1Simulate firstmesh-sim runs the mesh on a laptop, so routing can be tested without a table full of phones.
  2. L2Addresses lieBLE addresses rotate, so identity has to be a node id of our own.
  3. L3Own your moduleEach of us committed only our own modules and explained every change, because every member defends their code in a live viva.

lessons.txt (END) — press q to quit

// 06 — timeline

git log --since_

Oct 2026 · Code Sangam DroidRush

git log --reverse --format=milestone leyline
  1. 0122 Oct 2026ModulesCore, BLE, simulator and app split by owner.
  2. 0223 Oct 2026Device servicesLocation, battery, topology, alarm, SOS tile.
  3. 0324 Oct 2026DemoEnd-to-end SOS across phones.
cd ~/work./contact — itsabhay@abhay.si