Repository navigation
The radios Knit uses
A Knit phone talks to the phones around it over Bluetooth LE and Wi-Fi Aware at the same time, with no router, SIM or Google Play services involved. For a large file or a call between neighbours it can also raise a Wi-Fi Direct connection for a few minutes. Two more paths are optional: a Meshtastic LoRa board adds hops measured in kilometres, and an Internet relay carries direct and group messages between phones that are nowhere near each other.
This page puts those paths side by side: how far each reaches, how fast it is, what it carries, what it costs in battery, and how Knit decides which one to use. For the same story from a user's side, see How Knit uses Bluetooth and Wi-Fi Aware on the Knit website.
Checked against Knit 2.11.0-beta.0.
| Path | Typical reach | Speed | What it carries | When Knit uses it |
|---|---|---|---|---|
| Bluetooth link | Tens of metres | About 5 to 25 KB/s for a file | Everything | Always, to up to six nearby phones |
| Bluetooth long range (Coded PHY) | One Knit walk trial held a link at 215 m | About 1 KB/s for a file | Everything | When a linked phone moves toward the edge of range |
| Bluetooth advertising page | Bluetooth range | One packet of up to 236 bytes | Nearby room posts and small public updates | Beside the links |
| Wi-Fi Aware message | Wi-Fi range | Up to 255 bytes each | Small updates and short direct messages | While Wi-Fi Aware runs |
| Wi-Fi Aware connection | Wi-Fi range | Hundreds of megabits a second is typical | Catch-up, pictures and files | Opened on demand, closed seconds later |
| Wi-Fi Direct | Wi-Fi range | About 70 MB/s measured on 5 GHz | One large file, or one live call | When you send a file directly or call a neighbour |
| LoRa board (optional) | Kilometres | About 1 kbit/s is typical | Your own short Nearby posts and short direct messages | Once you pair and set up a board |
| Internet relay (optional) | Anywhere online | Your connection's speed | Sealed direct and group messages and their pictures | Once you turn a relay on |
The 215 m and 70 MB/s figures come from Knit's trials. The other ranges, and the Wi-Fi Aware and LoRa speeds, are typical for those radios, and walls and pockets shorten every range.
Everything above the radios in Knit talks to one interface that stands for "the mesh". Behind it, CompositeMeshTransport runs each radio as a child, in order of preference: Bluetooth first, then Wi-Fi Aware, then LoRa, which stays idle until a board is set up. A phone without Wi-Fi Aware just has one child fewer, and nothing above notices.
The children are merged by Knit identity, so a phone heard over both Bluetooth and Wi-Fi Aware is one neighbour. A message for one phone goes over the most preferred radio holding a live link to it. A flooded message reaches each neighbour once, over its preferred radio. If a copy still arrives twice, the duplicate check in How a message crosses the mesh drops the second one.
The children also pass each other hints. When Bluetooth holds a link to a phone, Wi-Fi Aware stops opening connections to it for catch-up, since that traffic already flows over Bluetooth. When Wi-Fi Aware spots a phone first, Bluetooth scans at once to catch it, because a Bluetooth link costs less to keep. The mesh counts as healthy while any one radio works.
Nearly every Android phone has Bluetooth LE, and it holds links open cheaply, which makes it the radio Knit builds on.
Each phone advertises all the time. Its 24-byte advert holds its Knit identity, what its version of Knit can do, a short summary of the messages it carries, and the channel to connect on. A phone opens a link to a neighbour it has heard for 12 seconds at −90 dBm or stronger, and the phone with the larger identity dials, so a pair doesn't dial each other at the same time. A phone holds up to six links. When it's full, a newcomer replaces the weakest link only if it's at least 8 dB stronger, so links don't churn as people shift around.
The links are L2CAP connection-oriented channels, a Bluetooth LE socket that carries a stream of bytes. A file goes out in chunks with messages slipped in between, so a photo in progress doesn't hold up a text. Beside the socket, Knit can open a GATT client on the same connection, the kind a fitness band uses, to read the link's signal and ask for a different radio speed or connection interval.
The interval sets the speed, because a link moves data once per connection event: about 9 KB/s at a typical 45 ms, and 22 to 29 KB/s at 15 ms. While a file moves, a phone whose screen is on asks for the short interval. The receiver reports how much it has taken in, and the sender paces the file by those reports, so the file goes as fast as the link drains it and a text sent mid-photo waits behind only a short queue. Between two lit Pixels in a Knit trial, a 410 KB photo took under half a minute. By default, a file over 1 MB that only Bluetooth can bring waits for your tap, a limit you can change in Settings › Chats.
Two additions reach further on phones whose Bluetooth controllers support them. Advertising pages are broadcast packets that carry Nearby room posts, reactions, receipts, group updates and profiles to phones that hear this one but hold no link to it. Direct messages never use them, and a phone listens for pages only while a page-capable phone nearby is unlinked or one of its own links is busy with a file.
Long range uses the Bluetooth LE Coded PHY, a slower encoding a receiver can pick out of a weaker signal. When a link's signal fades, the phone with the larger identity steps it down to Coded, and steps it back up once the signal is strong again, because files on Coded crawl at about 1 KB/s. If a link drops at range, both phones spend three minutes trying to get it back. iPhones and some older phones, such as the Pixel 3, have no Coded PHY.
Wi-Fi Aware lets two phones talk over Wi-Fi with no access point. Knit runs it on Android 12 and newer, on phones that have the hardware.
Each phone announces Knit's Wi-Fi Aware service and looks for it, and the announcement carries the phone's Knit identity, so discovery alone tells a phone who is near. Phones can then send each other small Wi-Fi Aware messages of up to 255 bytes without a connection, and Knit splits a frame across at most three. They carry each phone's message fingerprint every 30 seconds, small public updates to every neighbour, and short direct messages to their recipient alone. Carrying and catch-up cover whatever these best-effort messages lose.
For anything larger, two phones open a Wi-Fi Aware connection, a TCP socket between them. Setting one up takes one to four seconds, so Knit opens one only when fingerprints differ and no Bluetooth link already carries the catch-up, or when a picture or file is waiting. Each phone has a single Wi-Fi Aware data interface, so it opens one connection of its own at a time, from the larger identity again. When the exchange has been quiet for 5 seconds, or 2 if another phone is waiting, the connection closes and frees the radio.
Attachments reverse the usual preference and go over Wi-Fi Aware even when Bluetooth holds a link, because a connection moves in a second what Bluetooth needs tens of seconds for.
flowchart TD
F["A picture or file to send"] --> L{"Wi-Fi Aware connection<br/>already open to that phone?"}
L -- yes --> A["Send over Wi-Fi Aware"]
L -- no --> S{"128 KiB or larger<br/>after Knit shrinks it?"}
S -- no --> B["Send over the Bluetooth link"]
S -- yes --> O["Ask Wi-Fi Aware to open a connection"]
O --> W{"Open within 10 seconds?"}
W -- yes --> A
W -- no --> B
Below 128 KiB, setting up a connection takes longer than Bluetooth needs for the whole file.
Knit uses Wi-Fi Direct for two things, and neither passes through other phones.
Send directly, in a direct message to a contact who is nearby, moves one file of up to 8 GiB straight to their phone. The mesh carries only the sealed offer and answer, and no other phone keeps a copy. From a Pixel 7 to a Pixel 9 Pro XL on 5 GHz, Knit measured about 70 MB/s, a gigabyte in 15.2 seconds, after about 6 seconds for the receiving phone to join.
A live call to a mesh neighbour can also ride a Wi-Fi Direct group the two phones raise, with no Internet or relay. Voice calls covers calls in full.
Android won't run Knit's Wi-Fi Direct group beside its Wi-Fi Aware session, so Wi-Fi Aware pauses while the group is up and Bluetooth keeps both phones on the mesh. A transfer and a call can't share the group either: whichever starts first holds the radio until it ends.
A mesh call, the hold-to-talk kind, uses the mesh radios instead. Your voice goes out at about 1.5 KB/s, small enough for a Coded link, and each chunk to a neighbour takes the quickest link: Wi-Fi Aware when one is open, Bluetooth otherwise. A phone further away gets it through up to three other phones, or through a relay you both use when the radios have no path.
A Meshtastic LoRa board is optional. You pair it over Bluetooth, and nothing goes out over LoRa until you set it up. Once it's set up, it carries your own short Nearby room posts that fit one packet, short direct messages to contacts with a board, and their delivery checkmark. Pictures, catch-up and calls never use it, since LoRa typically moves about a kilobit a second. LoRa and Meshtastic has the details.
An Internet relay is optional too, and off until you turn it on. It holds sealed copies of direct and group messages and their pictures for the people in those conversations, and can't read them. Nearby room posts never go to a relay. Relays sit beside the radios rather than among them: a message pulled from one rejoins the local mesh like any other, so one phone online can bridge a whole group. What an Internet relay can see covers what a relay learns.
Bluetooth advertises all the time so other phones can find yours, and saves power on scanning. With the screen on or the phone charging, it scans for 12 seconds with gaps of at least 30 seconds. With the screen off, it scans for 8 seconds with gaps of at least 2 minutes, or 5 minutes below 15 percent battery. Gaps grow with each neighbour. A phone that's alone leaves only 12-second gaps for three minutes so it can rejoin quickly, then relaxes unless it's charging.
Wi-Fi Aware costs the most. In Knit's battery trials, with deep sleep held off, it drew about 20 mA standing by on a Pixel 8 and 42 mA on a Pixel 3, where Bluetooth links cost an order of magnitude less. On a Pixel 9 it also cut the phone's own Wi-Fi throughput to about a third while the screen was on. So Wi-Fi Aware sleeps after three minutes with nothing to do, as long as Bluetooth works and no phone heard over Bluetooth can run Wi-Fi Aware. It wakes when such a phone comes near or a large transfer needs it, and every 12 minutes it wakes for 30 seconds to find a phone whose Bluetooth is off. Settings › Wi-Fi Aware turns it off altogether, leaving the mesh to Bluetooth.
Wi-Fi Direct draws power only while a transfer or call runs, and a LoRa board runs on its own battery.
- Architecture, section 3, describes the transport interface and both radios.
- The Bluetooth plane walks through advertising pages, long range and file pacing, with diagrams.
- Mesh transport reference has the detail behind both radios and how files pick a radio.
- Voice calls design covers the Wi-Fi Direct call leg and how mesh calls travel.
- How a message crosses the mesh explains flooding and catch-up, which work the same on every radio.
- How pictures and files cross the mesh follows an attachment from sender to recipient.
- How Knit uses Bluetooth and Wi-Fi Aware describes the radios from a user's side.
Knit is free and ad-free, funded by its supporters.
☕ Ko-fi ·
💖 GitHub Sponsors ·
Liberapay ·
Other ways to help
Supporting Knit on Ko-fi or GitHub Sponsors comes with Knit Anywhere. Liberapay goes to the developer personally.