SonicWave is a resilient and decentralized emergency communication system designed to transmit SOS packets through a mesh network of user devices. The system ensures that critical emergency information reaches rescue services even when conventional communication infrastructure is unavailable.
- π΅ Bluetooth Low Energy (BLE) - Short-range device-to-device communication
- π‘ Wi-Fi UDP Multicast - Local network emergency broadcasting
- π΅ Audio (GGWave) - Sound-based communication when all else fails
- π°οΈ Automatic GPS Location - Real-time coordinate acquisition
- π Manual Location Input - Text-based location descriptions
- π Multiple Location Formats - Coordinates, addresses, landmarks
- πΊοΈ Location History Tracking - Track moving emergencies
- β‘ Urgency Levels - CRITICAL, HIGH, MEDIUM, LOW priority handling
- π Location Updates - Real-time position updates for moving emergencies
- π Packet Deduplication - Prevents duplicate emergency messages
- π Thread Management - Groups related emergency updates
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Mobile Device β β Mobile Device β β Mobile Device β
β (SonicWave βββββΊβ (SonicWave βββββΊβ (SonicWave β
β Client) β β Client) β β Client) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β (Mesh Network)
βΌ
βββββββββββββββββββββββββββ
β Central Server β
β β’ Emergency Dashboard β
β β’ Rescue Coordination β
β β’ Real-time Monitoring β
β β’ MySQL Database β
βββββββββββββββββββββββββββ
client.py- Main client orchestrating all componentspacket.py- SOS packet data structure with GPS supportpacket_manager.py- Intelligent packet caching and relay managementlocation_service.py- Windows-compatible GPS and location servicestransports/- Multi-protocol communication (BLE, UDP, GGWave)server_uploader.py- Reliable server communication with retry logic
server.py- FastAPI emergency coordination server- Emergency Dashboard - Real-time web interface for monitoring
- MySQL Database - Persistent emergency data storage
- WebSocket Updates - Live emergency notifications
- Rescue Authority Integration - Automated emergency service alerts
# Clone and navigate to project
cd sonicnet/
# Copy environment template
cp .env.example .env
# Edit .env with your MySQL credentials:
# DB_HOST=localhost
# DB_USER=sonicwave
# DB_PASSWORD=sonicwave123
# DB_NAME=sonicwave_emergency# Install client requirements
pip install -r requirements.txt
# Install server requirements
pip install -r server_requirements.txt# Automatic setup (recommended)
python setup_database.py
# Manual setup (alternative)
mysql -u root -p < database_setup.sql# Terminal 1: Start Emergency Server
python server.py
# Terminal 2: Run Client Example
python client_example.py
# Terminal 3: View Dashboard
# Open http://localhost:8000 in browserAccess the real-time emergency dashboard at http://localhost:8000:
- π Live Statistics - Active emergencies, total packets, notifications sent
- πΊοΈ Emergency Map - Real-time emergency locations and updates
- π Packet History - Complete emergency communication logs
- π¨ Alert Management - Rescue authority notification status
- π‘ Network Health - Mesh network topology and node status
# Get emergency statistics
GET /api/stats
# Get recent emergency packets
GET /api/packets/recent
# Get specific packet history
GET /api/packets/{packet_id}/history
# Get emergency thread (related updates)
GET /api/packets/thread/{thread_id}
# Get network topology
GET /api/network/topology
# Manage rescue authorities
GET /api/authorities
POST /api/authorities// Connect to live emergency updates
const ws = new WebSocket('ws://localhost:8000/ws');
ws.onmessage = function(event) {
const data = JSON.parse(event.data);
if (data.type === 'new_emergency') {
// Handle new emergency alert
displayEmergencyAlert(data.packet);
} else if (data.type === 'stats') {
// Update dashboard statistics
updateDashboard(data);
}
};# config.py - Customize transport settings
# BLE Configuration
BLE_SCAN_INTERVAL = 10 # seconds between scans
BLE_CONNECTION_TIMEOUT = 15 # connection timeout
BLE_MAX_CONNECTIONS = 5 # max simultaneous connections
# UDP Configuration
UDP_MULTICAST_GROUP = "224.1.1.1" # multicast address
UDP_PORT = 9999 # communication port
UDP_BROADCAST_INTERVAL = 5 # seconds between broadcasts
# GGWave Audio Configuration
GGWAVE_SAMPLE_RATE = 48000 # audio sample rate
GGWAVE_VOLUME = 50 # volume percentage
GGWAVE_PROTOCOL_AUDIBLE = True # audible vs ultrasonic# Urgency levels with different TTL and routing
URGENCY_LEVELS = {
"CRITICAL": {
"ttl": 20, # maximum hops
"priority": 1, # highest priority
"auto_notify": True # immediate rescue notification
},
"HIGH": {
"ttl": 15,
"priority": 2,
"auto_notify": True
},
"MEDIUM": {
"ttl": 10,
"priority": 3,
"auto_notify": False
},
"LOW": {
"ttl": 5,
"priority": 4,
"auto_notify": False
}
}# Mock location for testing
client.set_mock_location(40.7128, -74.0060, 10.0)
# GPS timeout settings
GPS_TIMEOUT = 10 # seconds for GPS fix
GPS_MIN_ACCURACY = 100 # meters
LOCATION_CACHE_TIME = 300 # seconds
# Geocoding (coordinates to address)
GEOCODING_ENABLED = True# Run complete system test (tests everything)
python comprehensive_test.pyThis tests:
- β Server startup and database connectivity
- β Client initialization with all transports
- β Location services (GPS, manual, coordinates)
- β SOS message transmission and reception
- β WebSocket real-time updates
- β Emergency notification system
- β Packet deduplication and relay
- β Network topology analysis
- β Multi-client mesh communication
- β Stress testing and stability
# Test just the client functionality
python client_example.py
# Test database setup
python setup_database.py- Discovery: Scans for SonicWave service UUID
- Connection: Direct device-to-device pairing
- Data Transfer: JSON packet transmission via GATT characteristics
- Range: ~50-100 meters in open areas
- Advantages: Low power, works without infrastructure
- Broadcasting: Multicast to 224.1.1.1:9999
- Discovery: Automatic peer discovery on local networks
- Data Transfer: JSON packets via UDP
- Range: Local network coverage
- Advantages: Fast, high throughput
- Encoding: Digital data encoded as audio frequencies
- Transmission: Via device speakers and microphones
- Range: ~5-15 meters depending on volume and environment
- Advantages: Works when all other methods fail
CREATE TABLE sos_packets (
packet_id VARCHAR(32) PRIMARY KEY,
sender_id VARCHAR(100) NOT NULL,
message TEXT NOT NULL,
urgency ENUM('CRITICAL', 'HIGH', 'MEDIUM', 'LOW'),
latitude DECIMAL(10, 8),
longitude DECIMAL(11, 8),
location_text TEXT,
packet_timestamp BIGINT,
hop_count INT DEFAULT 0,
relay_path JSON,
thread_id VARCHAR(100),
notifications_sent INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);CREATE TABLE rescue_authorities (
id INT PRIMARY KEY,
name VARCHAR(200) NOT NULL,
contact_type ENUM('phone', 'email', 'webhook', 'sms'),
contact_value VARCHAR(500) NOT NULL,
coverage_area TEXT,
active BOOLEAN DEFAULT TRUE
);- π Packet Deduplication - SHA256 hashing prevents duplicate emergencies
- π’ Hop Count Limiting - TTL prevents infinite relay loops
- β±οΈ Rate Limiting - Prevents emergency system flooding
- π Packet Validation - Input sanitization and validation
- π Audit Logging - Complete emergency communication logs
# Production server with SSL
uvicorn server:app --host 0.0.0.0 --port 443 --ssl-keyfile key.pem --ssl-certfile cert.pem
# Docker deployment
docker build -t sonicwave-server .
docker run -p 8000:8000 -e DB_HOST=mysql_server sonicwave-server# Production environment
DB_HOST=production_mysql_server
DB_PASSWORD=secure_password
TWILIO_SID=your_twilio_sid
TWILIO_TOKEN=your_twilio_token
GOOGLE_MAPS_API_KEY=your_maps_key# Install development dependencies
pip install -r requirements.txt -r server_requirements.txt
# Run tests
python comprehensive_test.py
# Code formatting
black *.py
isort *.py- Create new transport class in
transports/ - Inherit from
BaseTransport - Implement
start(),stop(), andsend()methods - Add to
client.pytransport initialization
- Update packet structure in
packet.pyif needed - Extend server API in
server.py - Add corresponding client methods
- Update tests in
comprehensive_test.py
The system can be configured to automatically notify:
- π Emergency Medical Services
- π Police Departments
- π₯ Fire Departments
- β°οΈ Search and Rescue Teams
- π Emergency Hotlines (911, 112, etc.)
Contact integration supports:
- π§ Email notifications
- π± SMS alerts
- βοΈ Automated phone calls
- π Webhook notifications
- ποΈ Wilderness Emergencies - Hiking, camping, remote area incidents
- π Vehicle Breakdowns - Highway emergencies, remote road incidents
- π Natural Disasters - Communication when infrastructure is down
- π Industrial Accidents - Factory, construction site emergencies
- π₯ Mass Events - Concert, festival, large gathering incidents
- π Maritime Emergencies - Coastal and near-shore incidents
SonicWave: When Every Second Counts, Every Device Helps π¨