When Disasters Strike, Cell Towers Fall First — So I Built a Mesh Network for Coastal Communities
Source: Dev.to
Ocean Sentinels is an Android‑first platform that lets coastal communities report hazards, coordinate rescues, and stay connected even when cellular or Wi‑Fi networks are down. The core idea is to turn ordinary Android phones into a disaster‑proof relay network using Bluetooth Low Energy (BLE). A report created offline hops phone‑to‑phone (≈ 400 m per hop) until any device in the chain reaches the internet and uploads the data to the server.
How It Works
[ Phone A ] ---BLE 400 m---> [ Phone B ] ---BLE 400 m---> [ Phone C : Has Internet ]
No signal No signal Uploads to server ✓
- Report hazards – GPS + photo (high waves, flooding, lost boats, etc.)
- BLE mesh relay – offline propagation tested up to ~400 m per hop
- Live map – real‑time incident markers (Mapbox)
- Role‑based access – Citizens, Rescue Teams, Authorities, Admins
- Push notifications – Firebase, works even when the app is closed
- Web dashboard – for authorities (requires internet)
Overview
Ocean Sentinels provides a unified, full‑stack safety platform for coastal communities worldwide. It supports four user roles, each with a dedicated console and workflow:
| Role | Capabilities |
|---|---|
| Citizen | Submit incident reports, view live map |
| Rescue Team | Receive push alerts, verify reports, coordinate response |
| Authority | Dashboard analytics, manage users, oversee incidents |
| Admin | Full system configuration and user management |
Key technical highlights
- Android app – Kotlin + Jetpack Compose, Hilt DI, Room for offline storage, foreground BLE service.
- BLE mesh layer – time‑based expiry (72 h) instead of hop‑count TTL, works with Android 6+ MAC‑randomization.
- Backend – FastAPI + PostgreSQL, role‑based access control, WebSocket live updates.
- Push – Firebase Cloud Messaging for instant alerts.
Architecture
+-------------------+ +-------------------+ +-------------------+
| Android App | | BLE Mesh Layer | | Internet (API) |
+-------------------+ +-------------------+ +-------------------+
| |
v v
+-------------------+ +-------------------+
| Local Room DB | | Firebase Cloud |
+-------------------+ +-------------------+
- Device ↔︎ Mesh – BLE advertisements carry encrypted payloads; each node stores pending reports in Room.
- Device ↔︎ Server – When any node regains connectivity, it batches stored reports and sends them via the FastAPI endpoint.
- Server ↔︎ Dashboard – WebSocket pushes new incidents to the web UI; REST API serves historical data.
Project Structure
/android-app
/src/main/kotlin/com/oceansentinels
- ui/ # Compose screens
- ble/ # Mesh service
- di/ # Hilt modules
- data/ # Room + repository
/backend
/app
- routers/ # FastAPI routers
- models/ # SQLAlchemy models
- services/ # Business logic
/web-dashboard
/src
- components/ # React/Vue components
- store/ # State management
Backend API
- POST
/reports/– Accepts JSON with GPS, photo URL, and optional metadata. - GET
/reports/– Returns paginated list of recent incidents (filterable by region, severity). - WebSocket
/ws/updates– Streams new incident events to connected dashboards.
Authentication is JWT‑based; role claims determine access to admin endpoints.
Frontend Web App
- Built with React + TypeScript.
- Mapbox GL JS renders the live incident map.
- Role‑specific panels (verification, analytics, user management).
- Real‑time updates via the WebSocket endpoint.
Android App
- Kotlin + Jetpack Compose UI.
- BLE Mesh Service runs as a foreground service to survive background restrictions.
- Room stores pending reports; a WorkManager job syncs them when connectivity is restored.
- Firebase Messaging delivers push alerts even if the app is closed.
BLE Mesh Network
- Range: ~400 m per hop in open areas (tested with three phones).
- Message Lifetime: 72 h time‑based expiry, ensuring delivery across long chains.
- Identification: Uses generated UUIDs instead of MAC addresses (Android 6+ randomizes MACs).
Real‑World Test
Three phones placed ~400 m apart successfully relayed a hazard report from the offline end to a device with internet, which then uploaded the data to the server.
Getting Started
Prerequisites
- Android Studio Flamingo (or newer)
- Python 3.10+ with
pip - PostgreSQL 13+
Android
git clone https://github.com/yourorg/ocean-sentinels.git
cd ocean-sentinels/android-app
./gradlew assembleDebug
Install the generated APK on a device and grant location & Bluetooth permissions.
Backend
cd ocean-sentinels/backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
alembic upgrade head # apply migrations
uvicorn app.main:app --reload
Web Dashboard
cd ocean-sentinels/web-dashboard
npm install
npm run dev
Open http://localhost:3000 in a browser.
Deployment
- Backend – Dockerize the FastAPI service; use PostgreSQL on a managed cloud instance.
- Web – Serve the static build via Nginx or a CDN.
- Android – Distribute via Google Play (internal testing) or side‑load APKs for target communities.
Configuration
| Setting | Description | Default |
|---|---|---|
BLE_MAX_HOPS | Maximum hops before dropping a message | 50 |
MESSAGE_TTL_HOURS | Time‑based expiry for pending reports | 72 |
MAPBOX_TOKEN | Mapbox access token for the live map | "" |
FIREBASE_SERVER_KEY | Server key for push notifications | "" |
DATABASE_URL | PostgreSQL connection string | postgresql://user:pass@localhost/db |
All values can be overridden with environment variables.
API Reference
- Authentication –
POST /auth/loginreturns JWT. - Reports – see Backend API section above.
- Users – admin endpoints for CRUD operations (
/users/).
Full OpenAPI spec is available at http:///docs.
License
This project is licensed under the MIT License. See LICENSE for details.
Test Credentials
| Role | Password | |
|---|---|---|
| Citizen | sihcitizen@vi.com | SIH@2025 |
| Rescue | sihrescue@vi.com | Ocean@123 |
| Admin | OceanAdmin1 | admin |
These accounts work on both the Android app and the web dashboard.