Gowshik S
All posts

Ocean Sentinels: An Offline App for Coastal Communities

The full build: a web dashboard, an Android app with 21 screens, a FastAPI backend, and a Bluetooth mesh that relays reports when there is no internet.

Published
Reading time
3 minutes
Project
Ocean Sentinels case study

When a natural disaster takes out the cell towers, coastal communities are cut off at the moment they most need to be heard. Ocean Sentinels turns ordinary Android phones into a Bluetooth mesh network: a hazard report hops from phone to phone until any one of them finds a connection, and then it reaches rescue teams and authorities.

This one is personal. India's coastal communities are among the most disaster-prone in the world, and the cruel part is that when a disaster hits hardest, communication goes first. Nobody should be unreachable because a tower fell.

The platform

Ocean Sentinels is three pieces that work together.

  • Web app: a Mapbox map with live incident markers, separate dashboards for four kinds of user (public, authority, rescue team and admin), live notifications over WebSockets, and analytics charts.
  • Android app: 21 Jetpack Compose screens in Material 3, built offline-first with Room, plus Firebase push notifications, GPS tracking and the Bluetooth mesh.
  • Backend: FastAPI and PostgreSQL with async database access, more than 16 REST endpoints, JWT sign-in, role-based access and de-duplication of mesh messages.
Video on YouTubeWatch the walkthrough on YouTube

How the mesh works

This is the heart of the project. When there is no internet:

  1. Someone files a hazard report on their phone.
  2. The report is broadcast over Bluetooth Low Energy to phones nearby, about 400 m away.
  3. Each phone stores it, carries it and passes it on.
  4. As soon as any phone in the chain gets online, the report uploads and the authorities are alerted.

No special hardware. Just phones.

The details that make it hold up:

  • Coded PHY S8. Eight-times forward error correction stretches Bluetooth's range to about 400 m, against roughly 100 m normally.
  • A 72-hour expiry instead of a hop limit. In a disaster a chain can run past 50 phones before it reaches the internet, so messages expire by time, not by hops.
  • De-duplication in three layers: the relay path each message carries, an in-memory cache of the last 10,000 message IDs, and a check in the database.
  • Deterministic message IDs. A SHA-256 hash means the same report from the same phone always gets the same ID, wherever it surfaces.
  • A fallback for older phones. The app tries Coded PHY first for range and drops to the standard 1M PHY on devices that don't support it.

Every phone can play every role

The three roles a phone can play in the meshAny phone becomes a gateway the moment it gets a connection. Gatewayhas internetrelaysuploadsdownloadsRelayno internetreceivesforwardsrebroadcastsNormalno internetsendsreceivesbroadcasts
Swipe sideways to see the whole diagram. Any phone becomes a gateway the moment it gets a connection.

What happens to a report

What happens to a reportA report is saved on the phone before anything else, so it is never lost. Each relay drops copies it has already seen and anything older than 72 hours. Offline phonecreates the reportsaves it to Room firstbroadcasts it over BLEBLERelay phonereceives the reportdrops duplicates (SHA-256)checks the 72-hour expiryIs this phone online?noyesKeep relayingadds itself to the pathpasses it to the next phoneUploadsends it to the backendserver drops duplicatesby mesh_message_id
Swipe sideways to see the whole diagram. A report is saved on the phone before anything else, so it is never lost. Each relay drops copies it has already seen and anything older than 72 hours.
SettingValue
Phones connected at once7
Fragment size469 bytes
Largest packet512 bytes
De-duplication cache10,000 message IDs
Message lifetime72 hours
A peer counts as gone after180 seconds
Scanning restarts every30 seconds
RadioCoded PHY for range, 1M PHY as fallback

The protocol, layer by layer

The mesh protocol, layer by layerFrom the message a person writes down to the radio that carries it. Applicationlayer 4incident report · status updatesync request · acknowledgementTransportlayer 3Protocol Buffers · 469-byte fragmentssequence numbers and CRC · ChaCha20-Poly1305Networklayer 272-hour expiry · SHA-256 IDs, 10,000 in cacherandomised delays to avoid collisionsRadiolayer 1Coded PHY S8: ~400 m at 125 kbpsfallback 1M PHY: ~100 m at 1 Mbps
Swipe sideways to see the whole diagram. From the message a person writes down to the radio that carries it.

Messages on the mesh are encrypted with ChaCha20-Poly1305.

Built with

LayerStack
BackendPython 3.11, FastAPI, SQLAlchemy 2.0 (async), PostgreSQL, JWT, WebSockets
WebJavaScript, Mapbox GL JS, CSS
AndroidKotlin, Jetpack Compose, Material 3, Hilt, Room, Retrofit, Mapbox SDK, Firebase
MeshBLE 5.0 Coded PHY S8, GATT server and client, SHA-256 de-duplication, foreground service

Tested in the open

Field test: phones about 400 m apart relaying a report with no internet.
The same relay, seen on the phones.
Reporting, the map and the mesh screen.

Screens

The web app's home page.
Public analytics.
The authorities' analytics.
Android: home, with quick actions.
Android: filing a report with GPS and hazard type.
Android: nearby phones and relay status.
Android: the live map.
How a report travels from phone to phone.

Try it

Code on GitHubOcean-Sentinels on GitHub

Built for coastal communities everywhere. When the network goes down, the mesh goes up.

The full story is in the Ocean Sentinels case study.

An earlier version of this post appeared on DEV