Skip to content

danielnovais-tech/starlink_connectivity_tools.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

250 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

starlink_connectivity_tools.py

A Python toolkit for monitoring and analyzing Starlink connectivity performance.

Features

  • Performance reporting over customizable time periods
  • Data export to JSON format
  • Command-line interface for easy access

Installation

Clone the repository:

Starlink Connectivity Tools

Python tools for remotely accessing and monitoring Starlink devices using cookie-based authentication.

Overview

This repository provides example scripts for interacting with Starlink devices remotely. The main script demonstrates how to:

  • Authenticate using cookies
  • Retrieve account information
  • List service lines and dishes
  • Get dish status and alerts
  • View router/WiFi information
  • List connected clients

Installation

  1. Clone this repository:
git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py
  1. Install required dependencies:
pip install -r requirements.txt

Setup

  1. Create a cookies.json file with your Starlink authentication cookies:

    • Copy cookies.json.example to cookies.json
    • Update it with your actual authentication cookies from your browser
    • You can export cookies from your browser using browser developer tools or a cookie export extension
  2. Example cookies.json structure:

[
  {
    "name": "cookie_name",
    "value": "cookie_value",
    "domain": ".starlink.com",
    "path": "/",
    "secure": true,
    "httpOnly": false
  }
]

Usage

Run the remote access example script:

python remote_access_example.py

The script will:

  1. Read authentication cookies from cookies.json
  2. Connect to your Starlink account
  3. Retrieve and display information about:
    • Dishes (ID, serial number, status, alerts)
    • Routers (ID, software version)
    • WiFi networks (2.4GHz and 5GHz SSIDs)
    • Connected clients

Output Example

-------------------------
DISH_ID: dish_12345
Dish Serial: UT12345678901234
Dish Status:
    alert1: value1
    alert2: value2

Router ID: router_12345
Software Version: 2024.01.01.mr12345
Networks: 
    2.4ghz: MyStarlink
    5ghz: MyStarlink_5G
Clients:
    Device1|192.168.1.100
    Device2|192.168.1.101

Security Notes

  • Never commit cookies.json to version control - it contains sensitive authentication information
  • The cookies.json file is already included in .gitignore
  • Cookie files stored in dir_cookies are also excluded from version control
  • Keep your authentication cookies secure and rotate them regularly A Python library for interacting with Starlink user terminals via gRPC. This library provides convenient wrappers for common Starlink methods to manage and monitor your Starlink dish.

Features

This library provides methods for:

  • Get Status/History: Retrieve current status (connectivity, alerts) and historical data
  • Get Network Stats: Download/upload speeds, latency, packet loss
  • Get Telemetry: Device alerts, errors, warnings (streaming supported)
  • Reboot Dish: Restart the user terminal
  • Set Dish Config: Enable/disable features like snow melt mode, power saving
  • Get Device Location: Precise location (local) or H3 cell (remote)
  • Get WiFi Status: SSID, connected clients
  • Change WiFi Config: Modify SSID, passwords, enable bypass mode
  • Get Account Data: Basic account info (remote only)

Installation

From source

git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py
pip install -e .

Using pip (when published to PyPI)

pip install starlink_connectivity_tools

Requirements

  • Python 3.7 or higher
  • grpcio >= 1.50.0
  • grpcio-tools >= 1.50.0

Quick Start

Basic Usage

from starlink_connectivity_tools import StarlinkClient

# Connect to local Starlink dish (default: 192.168.100.1:9200)
client = StarlinkClient()

# Get current status
status = client.get_status()
print(f"Connected: {status['is_connected']}")
print(f"State: {status['state']}")
print(f"Uptime: {status['uptime']} seconds")

# Get network statistics
stats = client.get_network_stats()
print(f"Download: {stats['download_speed_mbps']} Mbps")
print(f"Upload: {stats['upload_speed_mbps']} Mbps")
print(f"Latency: {stats['latency_ms']} ms")
print(f"Packet Loss: {stats['packet_loss_percent']}%")

# Get WiFi status
wifi = client.get_wifi_status()
print(f"SSID: {wifi['ssid']}")
print(f"Connected Clients: {len(wifi['connected_clients'])}")

Using Context Manager

from starlink_connectivity_tools import StarlinkClient

# Automatically handle connection and disconnection
with StarlinkClient() as client:
    status = client.get_status()
    print(status)

Remote Connection (with authentication)

from starlink_connectivity_tools import StarlinkClient

# Connect remotely with authentication token
client = StarlinkClient(
    target="remote.starlink.com:9200",
    auth_token="your-auth-token"
)

# Get account data (requires authentication)
account = client.get_account_data()
print(f"Email: {account['email']}")
print(f"Service Plan: {account['service_plan']}")

Explicit Secure/Insecure Connection

from starlink_connectivity_tools import StarlinkClient

# Force secure channel for local connection (optional)
secure_client = StarlinkClient(
    target="192.168.100.1:9200",
    secure=True
)

# Force insecure channel for testing (not recommended for production)
insecure_client = StarlinkClient(
    target="remote.starlink.com:9200",
    secure=False  # Only for testing/development
)

Note: The library automatically detects private IP addresses (RFC 1918: 10.x.x.x, 172.16.x.x-172.31.x.x, 192.168.x.x) and uses insecure channels for them. For all other addresses or when an auth_token is provided, it uses secure SSL/TLS channels.

Available Methods

get_status()

Retrieve current status of the Starlink dish.

status = client.get_status()
# Returns:
# {
#     "uptime": 123456,
#     "state": "CONNECTED",
#     "alerts": [],
#     "is_connected": true,
#     "software_version": "1.2.3"
# }

get_history(samples=300)

Retrieve historical data from the Starlink dish.

history = client.get_history(samples=100)
# Returns:
# {
#     "timestamps": [...],
#     "download_throughput": [...],
#     "upload_throughput": [...],
#     "latency": [...],
#     "packet_loss": [...],
#     "obstructed": [...]
# }

get_network_stats()

Get current network statistics.

stats = client.get_network_stats()
# Returns:
# {
#     "download_speed_mbps": 150.5,
#     "upload_speed_mbps": 25.3,
#     "latency_ms": 35.2,
#     "packet_loss_percent": 0.1,
#     "uptime_seconds": 123456
# }

get_telemetry(streaming=False)

Retrieve device telemetry including alerts, errors, and warnings.

telemetry = client.get_telemetry()
# Returns:
# {
#     "alerts": [...],
#     "errors": [...],
#     "warnings": [...],
#     "temperature_celsius": 45.2,
#     "power_usage_watts": 65.5
# }

reboot_dish()

Restart the Starlink user terminal.

result = client.reboot_dish()
# Returns:
# {
#     "success": true,
#     "message": "Reboot command sent"
# }

set_dish_config(snow_melt_mode=None, power_save_mode=None, **kwargs)

Configure Starlink dish settings.

result = client.set_dish_config(
    snow_melt_mode=True,
    power_save_mode=False
)
# Returns:
# {
#     "success": true,
#     "message": "Configuration updated",
#     "updated_config": {...}
# }

get_device_location(remote=False)

Get the device location.

# Get precise GPS location (local)
location = client.get_device_location(remote=False)
# Returns:
# {
#     "latitude": 47.6062,
#     "longitude": -122.3321,
#     "altitude": 50.0
# }

# Get H3 cell location (remote)
location = client.get_device_location(remote=True)
# Returns:
# {
#     "h3_cell": "8a2a1072b59ffff"
# }

get_wifi_status()

Get WiFi status and connected clients.

wifi = client.get_wifi_status()
# Returns:
# {
#     "ssid": "STARLINKXXX",
#     "enabled": true,
#     "channel": 36,
#     "connected_clients": [...],
#     "signal_strength": -45
# }

change_wifi_config(ssid=None, password=None, bypass_mode=None, **kwargs)

Modify WiFi configuration.

result = client.change_wifi_config(
    ssid="MyNewSSID",
    password="newsecurepassword123",
    bypass_mode=False
)
# Returns:
# {
#     "success": true,
#     "message": "WiFi configuration updated",
#     "updated_config": {...}
# }

get_account_data()

Get basic account information (remote only, requires authentication).

account = client.get_account_data()
# Returns:
# {
#     "email": "user@example.com",
#     "name": "John Doe",
#     "service_plan": "Residential",
#     "account_number": "ABC123456"
# }

Connection Types

Local Connection

The default connection is to the local Starlink dish at 192.168.100.1:9200. This requires you to be on the same network as your Starlink router. Local connections automatically use insecure gRPC channels.

client = StarlinkClient()  # Uses default local address with insecure channel

The library automatically detects RFC 1918 private IP addresses and uses insecure channels for them:

  • 10.0.0.0/8 (10.x.x.x)
  • 172.16.0.0/12 (172.16.x.x - 172.31.x.x)
  • 192.168.0.0/16 (192.168.x.x)

Remote Connection

For remote connections, you need an authentication token. Remote connections automatically use secure SSL/TLS channels:

client = StarlinkClient(
    target="remote.starlink.com:9200",
    auth_token="your-auth-token"
)

Manual Channel Control

You can override automatic detection with the secure parameter:

# Force secure channel even for local IP
client = StarlinkClient(target="192.168.100.1:9200", secure=True)

# Force insecure channel (not recommended except for testing)
client = StarlinkClient(target="test.local:9200", secure=False)

Error Handling

The library raises grpc.RpcError exceptions when gRPC calls fail:

from starlink_connectivity_tools import StarlinkClient
import grpc

client = StarlinkClient()

try:
    status = client.get_status()
except grpc.RpcError as e:
    print(f"gRPC error: {e.code()} - {e.details()}")
except PermissionError as e:
    print(f"Permission error: {e}")

Development

Setting up development environment

# Clone the repository
git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py

# Install in development mode with dev dependencies
pip install -e ".[dev]"

Running tests

pytest tests/

Code formatting

black starlink_connectivity_tools/

Type checking

mypy starlink_connectivity_tools/

Related Projects

This library is inspired by and compatible with:

Notes

  • The Starlink gRPC API is unofficial and undocumented
  • This library uses reverse-engineered proto files
  • API may change without notice as SpaceX updates the firmware
  • Local connections do not require authentication
  • Remote connections require valid authentication tokens

License

MIT License - see LICENSE file for details Python tools for interacting with Starlink Enterprises API via gRPC. This library provides a simple interface to monitor and manage Starlink router and dish devices.

Features

  • 📡 Get device status and diagnostics
  • 🛰️ Monitor ping metrics and network performance
  • 🚀 Run speed tests
  • 🔧 Retrieve device information
  • 🔄 Reboot devices remotely
  • 📊 Support for both router and dish devices

Requirements

  • Python 3.7+
  • starlink-client library
  • protobuf
  • grpcio

License

See LICENSE file for details.

  • gRPC
  • Protocol Buffers
  • Access to Starlink devices on your network

Installation

  1. Clone this repository:
git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py

Usage

Performance Reports

Generate a performance report for a specific time period:

python tools/starlink_monitor_cli.py report --hours 48

This command generates a performance report for the last 48 hours, showing metrics such as:

  • Average latency
  • Average download speed
  • Average upload speed
  • Uptime statistics

Data Export

Export collected data to a JSON file:

python tools/starlink_monitor_cli.py export --output starlink_data.json

This command exports all collected metrics to the specified JSON file for further analysis or archival purposes.

Help

View all available commands and options:

python tools/starlink_monitor_cli.py --help

View help for a specific command:

python tools/starlink_monitor_cli.py report --help
python tools/starlink_monitor_cli.py export --help

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details. 2. Install dependencies:

pip install -r requirements.txt
  1. You'll also need the Starlink protobuf files (device_pb2.py and device_pb2_grpc.py). These can be generated from the official Starlink protobuf definitions.

Usage

Command Line Interface

The main script provides a CLI for interacting with Starlink devices:

# Get diagnostics from both router and dish
python starlink_client.py --command diagnostics

# Get status from router only
python starlink_client.py --command status --target router

# Run a speed test
python starlink_client.py --command run-speed-test

# Get ping metrics
python starlink_client.py --command ping

# Get device information
python starlink_client.py --command device-info

# Reboot the router
python starlink_client.py --command reboot --target router

# Output to a file in JSON format
python starlink_client.py --command status --format json --output status.json

CLI Options

  • --command, -c: Command to execute (diagnostics, status, ping, reboot, speed-test, run-speed-test, device-info)
  • --target, -t: Target device (router, dish, both) - default: both
  • --router-addr: Router gRPC address - default: 192.168.1.1:9000
  • --dish-addr: Dish gRPC address - default: 192.168.100.1:9200
  • --format, -f: Output format (json, pretty) - default: pretty
  • --output, -o: Output file path (optional)

Python API

You can also use the StarlinkClient class directly in your Python code:

from starlink_client import StarlinkClient

# Initialize the client
client = StarlinkClient()

# Get status
status = client.get_status(target="both")
print(status)

# Get diagnostics
diagnostics = client.get_diagnostics(target="router")
print(diagnostics)

# Get ping metrics
ping_metrics = client.get_ping_metrics()
print(ping_metrics)

# Run speed test
speed_test = client.run_speed_test()
print(speed_test)

# Get device info
device_info = client.get_device_info(target="dish")
print(device_info)

# Reboot device
result = client.reboot(target="router")
print(result)

Custom Addresses

If your Starlink devices are on non-standard addresses:

from starlink_client import StarlinkClient

client = StarlinkClient(
    router_addr="192.168.2.1:9000",
    dish_addr="192.168.100.1:9200"
)

status = client.get_status()

Examples

The examples/ directory contains various usage examples:

  • basic_status.py - Get basic status information
  • get_diagnostics.py - Retrieve detailed diagnostics
  • ping_monitoring.py - Monitor ping metrics (with continuous monitoring option)
  • speed_test.py - Run speed tests and retrieve results
  • device_info.py - Get detailed device information
  • custom_addresses.py - Use custom gRPC addresses

Run an example:

cd examples
python basic_status.py

API Methods

StarlinkClient Methods

  • get_diagnostics(target="both") - Get diagnostic information
  • get_status(target="both") - Get current status
  • get_ping_metrics() - Get ping/latency metrics (dish only)
  • get_speed_test() - Get last speed test results (router only)
  • run_speed_test() - Run a new speed test (router only)
  • get_device_info(target="both") - Get device information
  • reboot(target) - Reboot a device (router or dish)

Parameters

  • target: Specifies which device(s) to query
    • "router" - Router only
    • "dish" - Dish only
    • "both" - Both devices (where applicable)

Default Addresses

  • Router: 192.168.1.1:9000
  • Dish: 192.168.100.1:9200

These are the standard addresses for Starlink devices on the local network.

Error Handling

All methods return a dictionary. In case of errors, the response will contain an "error" key:

result = client.get_status()
if "error" in result.get("router", {}):
    print(f"Router error: {result['router']['error']}")

Network Requirements

  • Your computer must be connected to the Starlink network
  • Starlink devices must be accessible at their gRPC endpoints
  • No authentication is required for local network access

Troubleshooting

Connection Issues:

  • Ensure you're connected to the Starlink network
  • Verify device addresses are correct
  • Check firewall settings aren't blocking gRPC ports

Import Errors:

  • Make sure protobuf files (device_pb2.py, device_pb2_grpc.py) are in the same directory
  • Install all requirements: pip install -r requirements.txt A Python package for interacting with Starlink-related APIs, focusing on space traffic coordination and satellite operations.

Features

Starlink Space Safety API

The Space Safety API is hosted at space-safety.starlink.com and provides tools for satellite operators to:

  • Submit ephemeris files: Upload orbital data for your satellites
  • Screen against Starlink constellation: Check for potential conjunctions
  • Coordinate space traffic: Ensure safe operations in shared orbital space A comprehensive Python library for interacting with Starlink user terminals. This library provides wrappers for various Starlink gRPC methods, enabling device management, network monitoring, and configuration.

Features

Available Methods

Get Status/History - Retrieve current status (connectivity, alerts) and historical data
Get Network Stats - Download/upload speeds, latency, packet loss
Get Telemetry - Device alerts, errors, warnings (streaming supported)
Reboot Dish - Restart the user terminal
Set Dish Config - Enable/disable features like snow melt mode, power saving
Get Device Location - Precise location (local) or H3 cell (remote)
Get WiFi Status - SSID, connected clients
Change WiFi Config - Modify SSID, passwords, enable bypass mode
Get Account Data - Basic account info (remote only)

Key Features

  • 🔌 Support for both local (gRPC) and remote (API) connections
  • 📊 Type-safe data models with validation
  • 🔄 Async support for telemetry streaming
  • 🛡️ Comprehensive error handling
  • 📖 Extensive documentation and examples
  • 🧪 Easy to test and integrate

Installation

pip install starlink-connectivity-tools

Or install from source:

git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py
pip install -e .

Usage

Basic Example

from starlink_connectivity_tools import SpaceSafetyAPI

# Initialize the API client
api = SpaceSafetyAPI(api_key="your_api_key_here")

# Submit ephemeris data
ephemeris_data = {
    "satellite_id": "SAT-001",
    "epoch": "2026-01-05T12:00:00Z",
    "state_vector": {
        "position": [7000.0, 0.0, 0.0],  # km
        "velocity": [0.0, 7.5, 0.0]  # km/s
    }
}

response = api.submit_ephemeris(ephemeris_data)
print(f"Submission ID: {response['submission_id']}")

# Screen for conjunctions
results = api.screen_conjunction("SAT-001")
print(f"Found {results['total_events']} potential conjunctions")

# Close the session
api.close()

Using Context Manager

from starlink_connectivity_tools import SpaceSafetyAPI

with SpaceSafetyAPI(api_key="your_api_key_here") as api:
    # Submit an ephemeris file
    result = api.submit_ephemeris_file(
        file_path="/path/to/ephemeris.oem",
        file_format="oem"
    )
    
    # Get constellation data
    constellation = api.get_starlink_constellation_data(
        filters={"active_only": True}
    )
    print(f"Active satellites: {len(constellation)}")

Screening for Conjunctions

from starlink_connectivity_tools import SpaceSafetyAPI

api = SpaceSafetyAPI(api_key="your_api_key_here")

# Screen with a specific time window
time_window = {
    "start": "2026-01-05T00:00:00Z",
    "end": "2026-01-12T00:00:00Z"
}

results = api.screen_conjunction("SAT-001", time_window=time_window)

for conjunction in results['conjunctions']:
    print(f"Potential conjunction with {conjunction['starlink_satellite_id']}")
    print(f"  Time: {conjunction['time_of_closest_approach']}")
    print(f"  Miss distance: {conjunction['miss_distance']} km")
    print(f"  Collision probability: {conjunction['probability_of_collision']}")

Checking Submission Status

from starlink_connectivity_tools import SpaceSafetyAPI

api = SpaceSafetyAPI(api_key="your_api_key_here")

# After submitting ephemeris data
response = api.submit_ephemeris(ephemeris_data)
submission_id = response['submission_id']

# Check status later
status = api.get_screening_status(submission_id)
print(f"Status: {status['status']}")

if status['status'] == 'completed':
    print("Results:", status['results'])
## Quick Start

### Basic Usage

```python
from starlink_connectivity_tools import StarlinkClient

# Connect to local Starlink device
with StarlinkClient() as client:
    # Get device status
    status = client.get_status()
    print(f"Device is {status.state.value}")
    print(f"Uptime: {status.uptime_seconds // 3600} hours")
    
    # Get network statistics
    stats = client.get_network_stats()
    print(f"Download: {stats.download_mbps} Mbps")
    print(f"Latency: {stats.latency_ms} ms")

Network Monitoring

from starlink_connectivity_tools import StarlinkClient

with StarlinkClient() as client:
    stats = client.get_network_stats()
    
    if stats.is_healthy():
        print("✓ Network performance is good")
    else:
        print(f"⚠ High latency: {stats.latency_ms}ms")
        print(f"⚠ Packet loss: {stats.packet_loss_percent}%")

WiFi Management

from starlink_connectivity_tools import StarlinkClient, WiFiConfig

with StarlinkClient() as client:
    # Get current WiFi status
    wifi = client.get_wifi_status()
    print(f"SSID: {wifi.ssid}")
    print(f"Connected clients: {wifi.client_count()}")
    
    # Update WiFi configuration
    config = WiFiConfig(
        ssid="MyStarlink",
        password="SecurePassword123"
    )
    client.set_wifi_config(config)

Dish Configuration

from starlink_connectivity_tools import StarlinkClient, DishConfig

with StarlinkClient() as client:
    # Enable snow melt mode
    config = DishConfig(snow_melt_mode_enabled=True)
    client.set_dish_config(config)
    
    # Enable power saving
    config = DishConfig(power_save_mode_enabled=True)
    client.set_dish_config(config)

Device Telemetry

from starlink_connectivity_tools import StarlinkClient, AlertLevel

with StarlinkClient() as client:
    telemetry = client.get_telemetry()
    
    print(f"Temperature: {telemetry.temperature_celsius}°C")
    print(f"Power: {telemetry.power_input_watts}W")
    
    # Check for critical alerts
    if telemetry.has_critical_alerts():
        for alert in telemetry.get_alerts_by_level(AlertLevel.CRITICAL):
            print(f"CRITICAL: {alert.message}")

Async Telemetry Streaming

import asyncio
from starlink_connectivity_tools import StarlinkClient

async def monitor_telemetry():
    client = StarlinkClient()
    client.connect()
    
    try:
        async for telemetry in client.stream_telemetry():
            print(f"Temp: {telemetry.temperature_celsius}°C")
            
            if telemetry.has_critical_alerts():
                break
    finally:
        client.disconnect()

asyncio.run(monitor_telemetry())

Remote API (Account Data)

from starlink_connectivity_tools import StarlinkClient

# Remote API requires API key
with StarlinkClient(use_remote=True, api_key="your-api-key") as client:
    account = client.get_account_data()
    
    print(f"Service Line: {account.service_line_number}")
    print(f"Data Used: {account.data_used_gb} GB")
    
    if account.is_near_limit():
        print("⚠ Warning: Approaching data limit")

Historical Data

from starlink_connectivity_tools import StarlinkClient

with StarlinkClient() as client:
    # Get last 24 hours at 15-minute intervals
    history = client.get_history(duration_hours=24, interval_minutes=15)
    
    for entry in history:
        if entry.network_stats:
            print(f"{entry.timestamp}: {entry.network_stats.latency_ms}ms")

API Reference

SpaceSafetyAPI

Constructor

SpaceSafetyAPI(api_key=None, base_url="https://space-safety.starlink.com")

Parameters:

  • api_key (str, optional): API key for authentication
  • base_url (str): Base URL for the API

Methods

submit_ephemeris(ephemeris_data)

Submit ephemeris data for a satellite.

Parameters:

  • ephemeris_data (dict): Dictionary containing orbital parameters

Returns: dict with submission confirmation

submit_ephemeris_file(file_path, file_format="oem")

Upload an ephemeris file.

Parameters:

  • file_path (str): Path to the ephemeris file
  • file_format (str): Format of the file (e.g., "oem", "tle")

Returns: dict with upload confirmation

screen_conjunction(satellite_id, time_window=None)

Screen for potential conjunctions with Starlink satellites.

Parameters:

  • satellite_id (str): Satellite identifier
  • time_window (dict, optional): Time range for screening

Returns: dict with conjunction results

get_starlink_constellation_data(filters=None)

Retrieve current Starlink constellation data.

Parameters:

  • filters (dict, optional): Filters for constellation data

Returns: list of satellite data

get_screening_status(submission_id)

Get the status of a previous submission.

Parameters:

  • submission_id (str): Submission ID from previous request

Returns: dict with status information

Important Notes

Starlink-UK API Clarification

⚠️ Important: The "Starlink-UK API" is NOT related to SpaceX's Starlink satellite constellation. It is an unrelated astronomical software API from the University of Bristol for analyzing stellar populations.

This package focuses exclusively on SpaceX Starlink-related APIs for satellite connectivity and space traffic coordination.

For more information, see STARLINK_UK_NOTE.md.

Official Resources

For official updates and documentation:

Requirements

  • Python 3.7+
  • requests >= 2.25.0

StarlinkClient

Main client class for interacting with Starlink devices.

Constructor:

StarlinkClient(
    host: str = "192.168.100.1",
    port: int = 9200,
    use_remote: bool = False,
    api_key: Optional[str] = None,
    timeout: int = 10
)

Methods:

  • connect() - Establish connection to device
  • disconnect() - Close connection
  • get_status() - Get current device status
  • get_history(duration_hours, interval_minutes) - Get historical data
  • get_network_stats() - Get network performance stats
  • get_telemetry() - Get device telemetry
  • stream_telemetry() - Stream telemetry (async)
  • reboot_dish() - Reboot the user terminal
  • set_dish_config(config) - Configure dish settings
  • get_dish_config() - Get current dish configuration
  • get_device_location() - Get device location
  • get_wifi_status() - Get WiFi status
  • set_wifi_config(config) - Update WiFi settings
  • get_account_data() - Get account info (remote only)

Data Models

DeviceStatus

  • state - Device operational state
  • uptime_seconds - Device uptime
  • connected - Connection status
  • alerts - List of alerts
  • hardware_version - Hardware version
  • software_version - Software version

NetworkStats

  • download_mbps - Download speed
  • upload_mbps - Upload speed
  • latency_ms - Latency in milliseconds
  • packet_loss_percent - Packet loss percentage
  • is_healthy(max_latency_ms, max_packet_loss) - Check if performance is good

TelemetryData

  • alerts - List of alerts
  • temperature_celsius - Device temperature
  • power_input_watts - Power consumption
  • errors - List of errors
  • warnings - List of warnings
  • has_critical_alerts() - Check for critical alerts
  • get_alerts_by_level(level) - Filter alerts by severity

WiFiStatus

  • ssid - Network name
  • enabled - WiFi enabled status
  • connected_clients - List of connected devices
  • client_count() - Number of connected clients

WiFiConfig

  • ssid - Network name to set
  • password - Network password
  • bypass_mode_enabled - Bypass mode setting
  • validate_ssid() - Validate SSID
  • validate_password() - Validate password

DishConfig

  • snow_melt_mode_enabled - Snow melt mode
  • power_save_mode_enabled - Power save mode
  • is_power_saving() - Check if power saving is active

Examples

See examples.py for comprehensive usage examples including:

  • Basic status monitoring
  • Network performance tracking
  • WiFi management
  • Dish configuration
  • Telemetry streaming
  • Remote API usage
  • Historical data retrieval

Development

Setup Development Environment

# Clone repository
git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py

# Install with dev dependencies
pip install -e ".[dev]"
Python library for interacting with the Starlink dish gRPC API. This library provides a client for querying device status, network statistics, telemetry, and performing actions like rebooting the Starlink user terminal (dish).

## Overview

The Starlink user terminal exposes an **unauthenticated gRPC API** for monitoring and control. This API is not officially documented by SpaceX but has been reverse-engineered by the community.

### API Details

- **Protocol**: gRPC over HTTP/2
- **Local Address**: `192.168.100.1:9200` (local network only)
- **Authentication**: None required for local access
- **Remote Access**: Possible via Starlink's remote API with session cookies (valid for 15 days)
- **Service Discovery**: Supports gRPC server reflection

## Features

- ✅ Connect to local Starlink dish (192.168.100.1:9200)
- ✅ Remote access with session cookie authentication
- ✅ Service discovery using gRPC server reflection
- ✅ Extract proto files from the dish
- ✅ Query device status, network stats, and telemetry (requires proto files)
- ✅ Perform actions like rebooting or configuring the dish (requires proto files)

## Installation

### From PyPI (when published)

```bash
pip install starlink-connectivity-tools

From Source

git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py
pip install -e .

Development Installation

pip install -e ".[dev]"

Quick Start

Basic Connection

from starlink_connectivity_tools import StarlinkDishClient

# Connect to local dish
with StarlinkDishClient() as client:
    # Discover available services
    services = client.discover_services()
    print(f"Available services: {services}")

Remote Access

from starlink_connectivity_tools import StarlinkDishClient

# Connect remotely with session cookie
with StarlinkDishClient(
    address="remote.starlink.com:9200",
    session_cookie="your-session-cookie"
) as client:
    services = client.discover_services()
    print(f"Available services: {services}")

Extracting Proto Files

from starlink_connectivity_tools.client import StarlinkDishClient
from starlink_connectivity_tools.reflection import ProtoReflectionClient

# Connect to dish
client = StarlinkDishClient()
client.connect()

# Create reflection client
reflection_client = ProtoReflectionClient(client._channel)

# List services
services = reflection_client.list_services()

# Extract proto file for a service
reflection_client.export_proto_file(
    services[0], 
    "./proto_files/starlink.proto"
)

Examples

Several example scripts are provided in the examples/ directory:

Basic Usage

python examples/basic_usage.py

Demonstrates basic connection and service discovery.

Extract Proto Files

python examples/extract_proto.py [output_directory]

Extracts proto file definitions from the Starlink dish using server reflection.

Remote Access

python examples/remote_access.py <session_cookie> [remote_address]

Connects to the Starlink dish remotely using session cookies.

Using Proto Files

The Starlink gRPC API requires proto files to make actual RPC calls. You have two options:

Option 1: Extract from Dish (Recommended)

Use the extract_proto.py example to extract proto files directly from your dish:

python examples/extract_proto.py ./proto_files

Option 2: Use Community Proto Files

The community has reverse-engineered proto files. Search for "starlink grpc proto" to find them.

Compiling Proto Files

Once you have the proto files, compile them:

python -m grpc_tools.protoc \
    -I./proto_files \
    --python_out=. \
    --grpc_python_out=. \
    proto_files/*.proto

API Reference

StarlinkDishClient

Main client class for interacting with the Starlink dish.

Constructor Parameters

  • address (str, optional): gRPC server address. Defaults to 192.168.100.1:9200
  • session_cookie (str, optional): Session cookie for remote access
  • use_reflection (bool): Whether to use server reflection. Default: True
  • insecure (bool): Whether to use insecure channel. Default: True
  • timeout (int): Default timeout for RPC calls in seconds. Default: 10

Methods

  • connect(): Establish connection to the gRPC server
  • close(): Close the gRPC channel
  • discover_services(): List available gRPC services
  • get_status(): Get device status (requires proto files)
  • get_network_stats(): Get network statistics (requires proto files)
  • get_telemetry(): Get telemetry data (requires proto files)
  • reboot(): Reboot the dish (requires proto files)
  • set_configuration(config): Configure the dish (requires proto files)

ProtoReflectionClient

Client for extracting proto definitions using gRPC server reflection.

Methods

  • list_services(): List all available services
  • get_file_descriptor(symbol): Get file descriptor for a symbol
  • export_proto_file(symbol, output_path): Export proto file to disk

Troubleshooting

Cannot Connect to Local Dish

  1. Ensure you're connected to the Starlink WiFi network
  2. Verify the dish is powered on and operational
  3. Check the address is 192.168.100.1:9200
  4. Some network configurations may block local gRPC access

Remote Access Not Working

  1. Verify your session cookie is still valid (15-day expiry)
  2. Session cookies can be extracted from browser developer tools
  3. Check you have internet connectivity
  4. Ensure the remote address is correct

Service Discovery Fails

  1. The dish may not support server reflection (older firmware)
  2. Try using community proto files instead
  3. Check network connectivity

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Disclaimer

This is an unofficial library and is not affiliated with, endorsed by, or connected to SpaceX or Starlink. Use at your own risk.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This is an unofficial tool and is not affiliated with or endorsed by SpaceX or Starlink. Use at your own risk.

Acknowledgments

Based on the Starlink gRPC API for enterprises and business customers. See LICENSE file for details.

Disclaimer

This is an unofficial package. For official Starlink services and support, please visit https://starlink.com.

APIs may evolve over time. Check official Starlink resources for the latest updates. This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This library is not officially supported by SpaceX. It relies on reverse-engineered API knowledge from the community. The API may change without notice, and usage is at your own risk.

Acknowledgments

  • Community efforts in reverse-engineering the Starlink API
  • Tools like grpcurl and grpc-reflection that enable API discovery

Related Tools

Support

For issues and questions:

  • Open an issue on GitHub
  • Check existing community resources and documentation Python library for interacting with the Starlink API. This library provides a simple and intuitive interface to access Starlink's various API endpoints.

Installation

pip install starlink-connectivity-tools

Or install from source:

git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py
pip install -e .

Requirements

  • Python 3.7+
  • requests >= 2.25.0

starlink_connectivity_tools.py

Starlink Enterprise API

Official API for managing Starlink accounts and devices, primarily targeted at enterprise users. It allows programmatic control over subscriptions, service lines, user terminals, and more.

Description

Purpose: Manage accounts, addresses, data usage, routers, service lines, subscriptions, TLS configurations, and user terminals.

Base URL: https://web-api.starlink.com/enterprise

Documentation:

Authentication

The Starlink Enterprise API uses OpenID Connect (OIDC) for authentication.

Well-known configuration URL: https://web-api.starlink.com/enterprise/api/auth/.well-known/openid-configuration

Authentication Process:

  1. Obtain access tokens from the OIDC provider
  2. Attach tokens to API requests using the Authorization header: Authorization: Bearer <access_token>

Service Accounts:

  • Service accounts can be created in the Starlink account settings under "Service Accounts"
  • These accounts are specifically designed for API access
  • Use service account credentials to authenticate and make API calls programmatically A Python library for interacting with Starlink satellite internet devices.

Installation

pip install -e .

Or using the package directly:

python setup.py install
# Starlink Connectivity Tools

Python library for monitoring and managing Starlink dish connectivity with emergency mode support.

## Features

- Monitor Starlink dish status in real-time
- Detect emergency conditions (motor issues, obstructions, thermal problems)
- Emergency actions (stow/unstow dish, reboot)
- Simulated dish interface for testing and development

## Installation
# starlink_connectivity_tools.py

Python tools for monitoring Starlink connectivity.

## Usage Examples

### Basic Monitoring

Check the current status of your Starlink connection:
```bash
python tools/starlink_monitor_cli.py status

Monitor your Starlink connection continuously with a 30-second interval:

python tools/starlink_monitor_cli.py monitor --interval 30

Starlink Connectivity Tools

Crisis-optimized satellite connectivity monitoring and management tools

A comprehensive Python toolkit for managing Starlink connectivity in challenging environments, with real-time monitoring, automatic failover, and crisis-specific optimizations.

Features

🛰️ Starlink API Integration

  • Uses official starlink-grpc library for real device communication
  • Real-time monitoring of dish status, obstructions, and performance metrics
  • Automated issue detection and recovery (reboot, stow/unstow)
  • Support for simulation mode when hardware isn't available

🔄 Unified Connection Management

  • Manage multiple satellite connections (Starlink, Iridium, Inmarsat, Thuraya)
  • Real metrics from Starlink API instead of simulated data
  • Automatic failover between primary and backup connections
  • Priority-based connection selection

🚨 Crisis-Optimized Monitoring

  • Pre-configured scenarios: Normal, Humanitarian, Medical, Disaster, Conflict
  • Adjustable thresholds for different crisis situations
  • Persistent issue detection with automatic recovery
  • Performance history tracking and reporting

💻 Command-Line Tools

  • starlink-monitor CLI for easy monitoring and management
  • Real-time status display with color-coded alerts
  • Performance reporting and data export
  • Quick access to reboot, stow/unstow commands

🎯 Scenario-Specific Examples

  • Venezuela crisis scenario with realistic challenges
  • Medical mission simulation with connectivity optimization
  • Power outage, network congestion, and restriction simulations

🔍 Enhanced Diagnostics

  • Integrated Starlink telemetry with diagnostic tools
  • Historical performance tracking
  • Automated alerting and issue resolution
  • Comprehensive diagnostic reports

Installation

From Source

# Clone the repository
git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py

# Install dependencies
pip install -r requirements.txt

# Install the package
pip install -e .

Dependencies

  • Python 3.8+
  • starlink-grpc >= 1.2.0
  • click >= 8.1.0
  • rich >= 13.0.0
  • numpy >= 1.24.0
  • pandas >= 2.0.0
  • loguru >= 0.7.0

Quick Start

Using the CLI

# Check Starlink status
starlink-monitor status

# Start real-time monitoring (normal scenario)
starlink-monitor monitor --interval 10

# Monitor with crisis scenario
starlink-monitor monitor --scenario humanitarian

# Generate performance report
starlink-monitor report --hours 24 --output report.json

# Run diagnostics
starlink-monitor diagnostics

# Reboot dish
starlink-monitor reboot

# Use simulation mode (no hardware required)
starlink-monitor status --simulation
starlink-monitor monitor --simulation --scenario disaster

Using as a Library

from starlink_connectivity_tools import (
    StarlinkAPI,
    SatelliteConnectionManager,
    CrisisMonitor,
    DiagnosticsEngine,
)
from starlink_connectivity_tools.satellite_connection_manager import ConnectionType
from starlink_connectivity_tools.crisis_monitor import ScenarioType

# Initialize Starlink API
api = StarlinkAPI(simulation_mode=True)  # Set False for real hardware

# Get status
status = api.get_status()
print(f"Latency: {status['ping_latency_ms']} ms")
print(f"Downlink: {status['downlink_throughput_bps'] / 1_000_000} Mbps")

# Setup connection manager with failover
manager = SatelliteConnectionManager()
manager.add_connection("Starlink Primary", ConnectionType.STARLINK, priority=100)
manager.add_connection("Iridium Backup", ConnectionType.IRIDIUM, priority=50)
manager.connect()

# Setup crisis monitoring
monitor = CrisisMonitor(manager, scenario=ScenarioType.HUMANITARIAN)
health = monitor.check_health()
print(f"Status: {health['status']}")

# Run diagnostics
diagnostics = DiagnosticsEngine(manager)
report = diagnostics.run_full_diagnostic()
print(f"Overall status: {report['status']}")

# Cleanup
manager.close_all()
api.close()

Crisis Scenarios

The toolkit includes pre-configured monitoring scenarios optimized for different crisis situations:

Scenario Max Latency Min Bandwidth Obstruction Tolerance Use Case
Normal 100ms 20 Mbps 5% Standard operations
Humanitarian 200ms 10 Mbps 15% Aid coordination
Medical 150ms 15 Mbps 10% Telemedicine
Disaster 300ms 5 Mbps 25% Emergency response
Conflict 250ms 8 Mbps 20% Restricted areas

You can also create custom scenarios:

monitor.set_custom_thresholds({
    "max_latency_ms": 180,
    "min_downlink_mbps": 12,
    "min_uplink_mbps": 4,
    "max_obstruction_percent": 0.15,
    "min_snr": 6.0,
})

Example Scenarios

The examples/ directory contains realistic crisis simulations:

Venezuela Crisis Scenario

python examples/venezuela_crisis_scenario.py

Demonstrates multi-satellite failover, network restrictions, and automatic recovery.

Medical Mission Scenario

python examples/medical_mission_scenario.py

Shows activity-based monitoring with medical-specific requirements.

Power & Network Challenges

python examples/power_network_scenario.py

Simulates power outages, network congestion, and equipment failures.

See examples/README.md for detailed documentation.

Architecture

starlink_connectivity_tools/
├── starlink_api.py              # Starlink gRPC integration
├── satellite_connection_manager.py  # Multi-satellite management
├── crisis_monitor.py            # Crisis-optimized monitoring
├── diagnostics.py               # Enhanced diagnostics
└── starlink_monitor_cli.py      # Command-line interface

Real vs Simulation Mode

Real Mode

  • Requires Starlink dish connected to network
  • Default target: 192.168.100.1:9200
  • Provides actual telemetry data
  • Can control dish (reboot, stow/unstow)
api = StarlinkAPI()  # Real mode
manager.add_connection("Starlink", ConnectionType.STARLINK, simulation_mode=False)

Simulation Mode

  • No hardware required
  • Generates realistic synthetic data
  • Perfect for testing and development
  • All features work without dish
api = StarlinkAPI(simulation_mode=True)  # Simulation mode
manager.add_connection("Starlink", ConnectionType.STARLINK, simulation_mode=True)

Monitoring Features

Real-time Metrics

  • Latency (ping to Starlink PoP)
  • Downlink/uplink throughput
  • Signal-to-noise ratio (SNR)
  • Obstruction percentage
  • Dish state and alerts

Automatic Recovery

  • Connection failure detection
  • Automatic reboot on persistent issues
  • Failover to backup connections
  • Issue resolution tracking

Performance History

  • Time-series data collection
  • Statistical analysis (avg, min, max, percentiles)
  • Long-term trend tracking
  • Export to JSON for analysis

Alerts & Diagnostics

  • Hardware alerts (motors stuck, thermal issues)
  • Performance degradation detection
  • Obstruction analysis with directional info
  • Actionable recommendations

Use Cases

🏥 Medical Missions

Ensure reliable connectivity for telemedicine with automatic failover and low-latency monitoring.

🌍 Humanitarian Aid

Coordinate relief efforts in challenging environments with crisis-optimized thresholds.

⚠️ Disaster Response

Maintain communications during emergencies with automatic recovery and redundant connections.

🌐 Remote Operations

Monitor and manage satellite connectivity in areas with limited infrastructure.

Development

Running Tests

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request Comprehensive tools for monitoring and managing Starlink satellite connectivity with CLI, configuration management, logging, and alerting capabilities.

Features

  • Real-time Monitoring: Track Starlink connection metrics including download/upload speeds, latency, signal strength, and more
  • Performance Reports: Generate detailed performance reports over customizable time periods
  • Connection Management: Manage satellite connections with automatic failover capabilities
  • CLI Interface: Powerful command-line interface for all monitoring and management tasks
  • Customizable Thresholds: Set custom alert thresholds for various metrics via config file
  • Logging: Configurable logging levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • Multiple Export Formats: Export data to JSON or CSV
  • Unit Tests: Comprehensive unit tests for all CLI commands
  • Docker Support: Containerized deployment with Docker and Docker Compose
  • CLI Autocompletion: Bash completion script for enhanced usability
  • Type Hints: Full type annotations throughout the codebase
  • Config Validation: Automatic validation of configuration files A comprehensive Python toolkit for managing, monitoring, and optimizing Starlink satellite internet connections. This project provides essential tools for connection management, bandwidth optimization, power management, failover handling, and real-time monitoring.

🌟 Features

  • Connection Management: Intelligent Starlink connection handling with automatic reconnection and health monitoring
  • Bandwidth Optimization: Traffic shaping, QoS, and bandwidth allocation strategies
  • Power Management: Multiple power modes for battery operation and emergency scenarios
  • Failover Handling: Automatic failover between Starlink and backup connections
  • Real-time Monitoring: Live metrics tracking including signal quality, satellites, latency, and throughput
  • Diagnostics: Comprehensive diagnostic tools for troubleshooting
  • Web Dashboard: User-friendly web interface for monitoring and control
  • CLI Tools: Command-line tools for monitoring and management

📋 Project Structure

starlink_connectivity_tools.py

A robust framework for maintaining satellite connectivity in challenging crisis scenarios, with special attention to the specific needs of emergency response teams.

Acknowledgments

This project was inspired by connectivity challenges in Venezuela and other crisis scenarios where reliable communications are critical for emergency response and humanitarian aid.

Key Features Implemented

1. Crisis-Optimized Connection Management

  • Automatic satellite switching based on quality metrics
  • Crisis mode with relaxed requirements for emergency situations
  • Continuous health monitoring

2. Intelligent Bandwidth Allocation

  • Priority-based bandwidth allocation
  • Critical communications (medical, SOS) receive guaranteed bandwidth
  • Dynamic adjustment based on available bandwidth

3. Robust Failover System

  • Multiple backup connection types (cellular, WiFi, secondary satellite)
  • Cost-aware backup selection
  • Automatic failover and failback

4. Power Management

  • Multiple power modes (Normal, Conservation, Crisis, Survival)
  • Battery runtime optimization
  • Scheduled sleep cycles for extreme power saving

5. Comprehensive Diagnostics

  • Full system health checks
  • Historical tracking and reporting
  • Automated issue detection and recommendations

6. Emergency Scenarios

  • Special modes for humanitarian and medical operations
  • Guaranteed minimum connectivity for emergency communications
  • Optimized for crisis response teams and aid organizations A Python library for working with Starlink connectivity.

Installation

# Starlink Connectivity Tools

A Python library for managing Starlink connections with automatic failover capabilities.

## Features

- **Automatic Connection Failover**: Seamlessly switch between primary and backup connections when failures are detected
- **Configurable Health Checks**: Customize connection health monitoring with your own callback functions
- **Failure Threshold Management**: Set custom thresholds before triggering failover
- **Comprehensive Logging**: Track connection status and failover events
- **Failover History**: Review past failover events for analysis and debugging

## Installation

```bash
pip install -e .

Configuration

Configuration is stored in ~/.config/starlink_monitor/config.json. The default configuration includes:

{
  "thresholds": {
    "min_download_speed": 25.0,
    "max_latency": 100.0,
    "max_packet_loss": 5.0,
    "max_obstruction": 10.0
  },
  "logging": {
    "level": "INFO",
    "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    "file": null
  },
  "monitor": {
    "default_host": "192.168.100.1",
    "history_size": 1000,
    "default_interval": 60
  }
}

You can edit this file directly or use the CLI to modify thresholds interactively.

Usage

CLI Commands

Check current Starlink status:

starlink-cli status

Start continuous monitoring:

starlink-cli monitor --interval 30

Generate a performance report:

starlink-cli report --hours 48

Export data to JSON:

starlink-cli export --output data.json --hours 24

Export data to CSV:

starlink-cli export --output data.csv --format csv --hours 48

Manage connection:

starlink-cli connection

Set monitoring thresholds:

starlink-cli thresholds

Reboot Starlink dish (use with caution):

starlink-cli reboot

Logging Options

Control logging output with command-line flags:

# Set log level
starlink-cli status --log-level DEBUG

# Log to file
starlink-cli monitor --log-file /var/log/starlink.log

# Combine options
starlink-cli monitor --log-level INFO --log-file /var/log/starlink.log

Python API

from src.starlink_monitor import StarlinkMonitor
from src.connection_manager import SatelliteConnectionManager
from src.config import Config

# Load configuration
config = Config()

# Initialize monitor with config
monitor = StarlinkMonitor(config=config)

# Get current metrics
metrics = monitor.get_metrics()
print(f"Download: {metrics.download_speed} Mbps")
print(f"Latency: {metrics.latency} ms")

# Get performance report
report = monitor.get_performance_report(hours=24)
print(f"Availability: {report['availability_percent']}%")

# Update thresholds
config.set_thresholds(min_download_speed=50.0, max_latency=80.0)

# Connection management
manager = SatelliteConnectionManager(enable_starlink=True)
manager.scan_available_connections()
manager.connect("starlink_satellite")

Testing

Run unit tests:

python3 -m unittest discover tests

Run specific test file:

python3 -m unittest tests.test_cli -v

Docker Support

Build Docker Image

docker build -t starlink-monitor .

Run with Docker

# Check status
docker run -it --rm --network host starlink-monitor status

# Start monitoring
docker run -it --rm --network host starlink-monitor monitor --interval 30

# Export data
docker run -it --rm --network host -v $(pwd)/output:/app/output starlink-monitor export --output /app/output/data.csv --format csv

Using Docker Compose

# Start continuous monitoring
docker-compose up -d

# Check status
docker-compose run --rm status-check

# View logs
docker-compose logs -f

# Stop monitoring
docker-compose down

CLI Autocompletion

Enable Bash completion for enhanced CLI usability:

# Install completion script
sudo cp starlink-cli-completion.sh /etc/bash_completion.d/

# Or source it in your current session
source starlink-cli-completion.sh

# Now you can use tab completion:
starlink-cli <TAB>
starlink-cli export --format <TAB>

Configuration Validation

The configuration file is automatically validated on load. To manually validate:

from src.config import Config

config = Config()
is_valid, errors = config.validate()

if not is_valid:
    for error in errors:
        print(f"Error: {error}")

Requirements

  • Python 3.7+
  • Access to Starlink router (default: 192.168.100.1)

Install from local source

pip install -e .

Or install directly

pip install starlink-connectivity-tools A comprehensive Python toolkit for managing satellite connectivity in emergency and crisis scenarios, with focus on power management and battery optimization for remote operations.

Features

  • Power Management: Battery optimization with multiple power modes for extended runtime
  • Component Control: Manage individual components to optimize power consumption
  • Automatic Optimization: Intelligent power mode selection based on target battery runtime
  • Sleep Scheduling: Schedule periodic sleep/wake cycles for extreme power conservation

Installation

A Python library for managing Starlink satellite connectivity with support for bandwidth optimization, connection management, and prioritized data transmission.

Features

  • Bandwidth Optimization: Efficiently allocate and manage bandwidth across multiple connections
  • Priority Management: Prioritize critical connections (e.g., medical emergencies)
  • Connection Management: Track and control multiple simultaneous connections
  • Use Cases: Pre-built examples for common scenarios including medical emergency communications

starlink_connectivity_tools.py

A Python library for managing and monitoring Starlink connectivity, with built-in emergency mode support for critical situations.

Features

  • Emergency Mode: Automated monitoring and recovery for critical connectivity scenarios
  • Status Monitoring: Real-time dish status and connectivity checks
  • Alert Management: Detect and respond to dish alerts
  • Automatic Recovery: Attempt automated recovery procedures when issues are detected

Installation

Clone the repository:

git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py

Quick Start

Basic Usage

from starlink_connectivity_tools import FailoverHandler

# Create a failover handler
failover_handler = FailoverHandler(
    failure_threshold=3,    # Trigger failover after 3 consecutive failures
    check_interval=5.0      # Check connection every 5 seconds
)

# Automatic failover when primary fails
if failover_handler.should_failover():
    failover_handler.initiate_failover("Primary connection lost")

Custom Health Check

import requests
from starlink_connectivity_tools import FailoverHandler

def check_connection_health():
    """Custom health check function."""
    try:
        response = requests.get("https://www.google.com", timeout=5)
        return response.status_code == 200
    except:
        return False

failover_handler = FailoverHandler(
    failure_threshold=3,
    check_interval=10.0,
    health_check_callback=check_connection_health
)
### Low Power Operation Example

Optimize satellite terminal for 24-hour battery life:

```bash
python3 examples/low_power_operation.py

This example demonstrates:

  • Automatic power optimization for target battery runtime
  • Different power modes (Normal, Conservation, Crisis, Survival)
  • Component-level power management
  • Scheduled sleep cycles for extreme power savings
  • Real-time power consumption monitoring

Usage

Power Management

The PowerManager module provides intelligent battery optimization:

from src.power_manager import PowerManager

# Initialize with battery capacity (Watt-hours)
power_manager = PowerManager(total_battery_capacity=500.0)

# Optimize for 24-hour battery life
power_manager.optimize_for_battery_life(target_runtime_hours=24)

# Get power status report
report = power_manager.get_power_report()
print(f"Estimated runtime: {report['estimated_runtime_hours']:.1f} hours")
print(f"Total power: {report['total_power_consumption_w']:.1f} W")

Manual Power Mode Control

from src.power_manager import PowerMode

# Set specific power mode
power_manager.set_power_mode(PowerMode.CONSERVATION)

# Available modes:
# - PowerMode.NORMAL: Full performance
# - PowerMode.CONSERVATION: Reduced power (30-40% savings)
# - PowerMode.CRISIS: Minimal power (60-70% savings)
# - PowerMode.SURVIVAL: Maximum savings (85-90% savings)

Component Management

# Disable non-essential components
power_manager.disable_component('cellular_modem')
power_manager.disable_component('compute_unit')

# Re-enable when needed
power_manager.enable_component('cellular_modem')

Scheduled Sleep Cycles

# Active for 5 minutes, sleep for 30 minutes
power_manager.schedule_sleep_cycle(
    active_duration=300,   # 5 minutes
    sleep_duration=1800    # 30 minutes
)
No external dependencies are required for the basic examples.

A Python library for managing Starlink satellite connectivity with support for crisis mode and bandwidth optimization.

## Features

- **Connection Management**: Scan and connect to available Starlink satellites
- **Crisis Mode**: Prioritize connections during emergency scenarios with custom bandwidth and latency requirements
- **Bandwidth Optimization**: Optimize bandwidth usage for satellite connections
- **Status Reporting**: Get detailed connection metrics and performance data

## Quick Start

```python
import json
from src.connection_manager import SatelliteConnectionManager
from src.bandwidth_optimizer import BandwidthOptimizer

# Initialize connection manager
manager = SatelliteConnectionManager()

# Enable crisis mode for emergency scenarios
manager.enable_crisis_mode({
    'crisis_min_bandwidth': 1.0,  # Mbps
    'crisis_max_latency': 1000    # ms
})

# Scan and connect
connections = manager.scan_available_connections()
if connections:
    manager.connect(connections[0])

# Get status report
report = manager.get_connection_report()
print(json.dumps(report, indent=2))
# Starlink Connectivity Tools for Crisis Scenarios

A Python-based toolkit for optimizing satellite connectivity in crisis scenarios, inspired by challenges faced in Venezuela and other emergency situations.

## Features

- **Smart Connection Management**: Automatic satellite switching and optimization
- **Bandwidth Prioritization**: Critical communications get priority bandwidth
- **Failover Handling**: Automatic switch to backup connections
- **Power Management**: Optimize for limited power/battery scenarios
- **Comprehensive Diagnostics**: Full system health monitoring
- **Emergency Mode**: Special configurations for crisis situations
# Starlink Connectivity Tools

A comprehensive Python toolkit for managing satellite connectivity in emergency and crisis scenarios, inspired by real-world connectivity challenges in Venezuela and other regions.

## Features

- **Connection Management**: Scan, connect, and manage satellite connections
- **Bandwidth Optimization**: Intelligent bandwidth allocation with traffic prioritization
- **Crisis Mode**: Special emergency mode for critical communications only
- **Failover Handling**: Automatic connection failover with health monitoring
- **Power Management**: Battery optimization with multiple power modes
- **Diagnostics**: Comprehensive connectivity diagnostics and health checks

## Installation

```bash
pip install starlink_connectivity_tools

Or install from source: git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git cd starlink_connectivity_tools.py pip install -r requirements.txt


## Usage

```python
from starlink_connectivity_tools import StarlinkConnectivity, check_connection, format_speed

# Create a connectivity instance
conn = StarlinkConnectivity(dish_id="DISH-12345")

# Connect to the dish
conn.connect()

# Check connection status
print(conn.is_connected())  # True

# Get status
status = conn.get_status()
print(status)  # {'dish_id': 'DISH-12345', 'connected': True}

# Use utility functions
print(check_connection("DISH-12345"))  # True
print(format_speed(250.5))  # "250.50 Mbps"
print(format_speed(1500))  # "1.50 Gbps"

Testing

Run the test suite using pytest:

python -m pytest tests/

Run tests with verbose output:

python -m pytest tests/ -v

Development

Install development dependencies:

pip install -e ".[dev]"

Emergency Mode Example

The emergency mode example demonstrates how to monitor and recover from connectivity issues: Run the emergency connectivity system demo:

python3 examples/emergency_mode.py

This example demonstrates:

  • Enabling emergency/crisis mode
  • Establishing satellite connectivity
  • Sending emergency SOS messages
  • Synchronizing medical data with priority bandwidth
  • Continuous monitoring and health checks
  • Graceful shutdown with status reporting

Press Ctrl+C to gracefully shutdown the system.

Core Modules

Connection Manager (src/connection_manager.py)

Handles satellite connectivity, scanning, and connection management.

from src.connection_manager import SatelliteConnectionManager

manager = SatelliteConnectionManager()
connections = manager.scan_available_connections()
manager.connect(connections[0])

Bandwidth Optimizer (src/bandwidth_optimizer.py)

Manages bandwidth allocation and traffic prioritization. A Python library for managing Starlink satellite connections, optimizing bandwidth usage, handling failover scenarios, and managing power consumption.

Features

  • Connection Management: Establish, monitor, and manage Starlink satellite connections
  • Bandwidth Optimization: Optimize bandwidth usage and manage network traffic efficiently
  • Failover Handling: Automatic failover to backup connections when primary connection fails
  • Power Management: Manage power consumption with low-power modes for battery-powered scenarios
  • Diagnostics: Comprehensive diagnostic tools and health checks for Starlink connections

Project Structure

starlink-connectivity-tools/
├── src/
│   ├── __init__.py
│   ├── connection_manager.py      # Starlink connection management
│   ├── bandwidth_optimizer.py     # Bandwidth optimization
│   ├── failover_handler.py        # Failover management
│   ├── power_manager.py           # Power consumption management
│   ├── diagnostics.py             # Diagnostic tools
│   ├── starlink_monitor.py        # Real-time monitoring
│   └── config/
│       └── settings.py            # Configuration settings
├── tools/
│   ├── starlink_monitor_cli.py    # Command-line monitoring tool
│   └── connectivity_dashboard.py  # Web dashboard
├── examples/
│   ├── emergency_mode.py          # Emergency mode example
│   ├── venezuela_scenario.py      # Venezuela scenario example
│   └── low_power_mode.py          # Low power mode example
├── requirements.txt
├── setup.py
└── README.md

🚀 Installation

Basic Installation

# Clone the repository
git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py

# Install dependencies
pip install -r requirements.txt

# Install the package
pip install -e .

With Web Dashboard Support

pip install -e .[web]
│   ├── connection_manager.py      # Connection establishment and monitoring
│   ├── bandwidth_optimizer.py     # Bandwidth optimization and traffic management
│   ├── failover_handler.py        # Automatic failover to backup connections
│   ├── power_manager.py           # Power consumption management
│   ├── diagnostics.py             # Diagnostic tools and health checks
│   └── config/
│       └── settings.py            # Configuration management
├── tests/
│   ├── test_connection_manager.py # Tests for connection manager
│   └── test_bandwidth_optimizer.py # Tests for bandwidth optimizer
├── examples/
│   ├── emergency_mode.py          # Emergency mode configuration example
│   └── low_power_mode.py          # Low power mode configuration example
├── requirements.txt               # Project dependencies
├── setup.py                       # Package setup configuration
└── README.md                      # This file

Installation

git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py
### From Source

```bash
git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py
pip install -e .

Quick Start

from starlink_connectivity import BandwidthOptimizer

# Initialize optimizer with available bandwidth
optimizer = BandwidthOptimizer(total_bandwidth=100.0)  # 100 Mbps

# Allocate bandwidth for a connection
allocation = optimizer.allocate_bandwidth(
    connection_id="my_connection",
    destination="data.endpoint",
    requested_bandwidth=10.0
)

print(f"Allocated: {allocation.allocated_bandwidth} Mbps")
print(f"Status: {allocation.status}")

Use Cases

1. Automatic Connection Monitoring

Monitor your Starlink connection and automatically switch to a backup connection when the primary fails:

import time
from starlink_connectivity_tools import FailoverHandler

failover_handler = FailoverHandler(failure_threshold=3, check_interval=5.0)

while True:
    if failover_handler.should_failover():
        failover_handler.initiate_failover("Primary connection lost")
        print(f"Switched to: {failover_handler.get_current_state().value}")
    
    time.sleep(1)

2. Integration with Network Management

from starlink_connectivity_tools import FailoverHandler
import subprocess

def switch_to_backup():
    """Execute network switch commands."""
    subprocess.run(["ip", "route", "add", "default", "via", "backup.gateway"])

failover_handler = FailoverHandler(failure_threshold=2, check_interval=3.0)

if failover_handler.should_failover():
    failover_handler.initiate_failover("Primary connection timeout")
    switch_to_backup()

Examples

See the examples/ directory for complete working examples:

  • automatic_failover.py: Demonstrates automatic failover with simulated connection failures

Run an example:

cd examples
python automatic_failover.py

API Reference

FailoverHandler

Main class for managing connection failover.

Constructor Parameters:

  • failure_threshold (int): Number of consecutive failures before triggering failover (default: 3)
  • check_interval (float): Time in seconds between health checks (default: 5.0)
  • health_check_callback (Callable): Optional callback function for custom health checks

Methods:

  • should_failover() -> bool: Check if failover should be initiated
  • initiate_failover(reason: str) -> bool: Initiate failover to backup connection
  • get_current_state() -> ConnectionState: Get current connection state
  • get_failure_count() -> int: Get current consecutive failure count
  • get_failover_history() -> list: Get history of failover events
  • reset() -> None: Reset handler to initial state

Testing

Run the test suite:

# Run all tests
python -m pytest tests/

# Run with coverage
python -m pytest tests/ --cov=starlink_connectivity_tools

# Run specific test file
python -m unittest tests/test_failover.py

Development

Setup Development Environment

1. Remote Off-Grid Operation

Operating satellite terminals in remote locations with limited solar or battery power:

# Optimize for 24-hour battery life
power_manager.optimize_for_battery_life(target_runtime_hours=24)

2. Emergency Backup Power

Extend battery life during power outages:

# Switch to crisis mode immediately
power_manager.set_power_mode(PowerMode.CRISIS)

# Disable non-critical components
power_manager.disable_component('compute_unit')

3. Scheduled Operations

Maintain connectivity with periodic check-ins to conserve battery:

# Active 10 minutes every hour
power_manager.schedule_sleep_cycle(
    active_duration=600,    # 10 minutes active
    sleep_duration=3000     # 50 minutes sleep
)

Power Consumption Reference

Typical power consumption by component and mode:

Component Normal Conservation Crisis Sleep
Satellite Modem 60W 40W 20W 5W
Router 10W 7W 5W 2W
Cellular Modem 8W 6W 4W 1W
Compute Unit 25W 15W 10W 3W
Total 103W 68W 39W 11W

Example Runtimes (500 Wh battery):

  • Normal mode: ~5 hours
  • Conservation mode: ~7.5 hours
  • Crisis mode: ~13 hours
  • Survival mode: ~45 hours
  • Sleep cycles (5m/30m): ~26 hours

Medical Emergency Communications

Prioritize medical data transmission during emergency situations:

from starlink_connectivity import BandwidthOptimizer

optimizer = BandwidthOptimizer(total_bandwidth=100.0)

# Prioritize medical data transmission
optimizer.allocate_bandwidth(
    connection_id="medical_evac",
    destination="medical.data",
    requested_bandwidth=10.0
)

See the examples/medical_emergency.py for a complete medical emergency communications scenario.

API Reference

BandwidthOptimizer

Main class for managing bandwidth allocation.

Methods

  • allocate_bandwidth(connection_id, destination, requested_bandwidth, priority=0): Allocate bandwidth for a connection
  • release_bandwidth(connection_id): Release bandwidth from a connection
  • get_allocation(connection_id): Get allocation details for a connection
  • get_all_allocations(): Get all current allocations
  • get_available_bandwidth(): Get currently available bandwidth

Running Examples

# Medical emergency communications example
python examples/medical_emergency.py

Development Installation

pip install -e .[dev]

📖 Usage

Python Library

from src.connection_manager import ConnectionManager
from src.starlink_monitor import StarlinkMonitor
from src.power_manager import PowerManager, PowerMode

# Initialize components
connection = ConnectionManager()
monitor = StarlinkMonitor()
power = PowerManager()

# Connect to Starlink
connection.connect()

# Get current metrics
metrics = monitor.get_current_metrics()
print(f"Signal Quality: {metrics['signal_quality']}%")
print(f"Download Speed: {metrics['download_mbps']} Mbps")

# Set power mode
power.set_power_mode(PowerMode.ECO)

Command-Line Monitoring

# Live monitoring
python tools/starlink_monitor_cli.py monitor --interval 5

# Get statistics
python tools/starlink_monitor_cli.py stats --duration 60

# Run diagnostics
python tools/starlink_monitor_cli.py diagnostics

# Export metrics
python tools/starlink_monitor_cli.py export --format json --output metrics.json

Web Dashboard

# Start the web dashboard
python tools/connectivity_dashboard.py --host 0.0.0.0 --port 5000

# Access at http://localhost:5000

Examples

Emergency Mode

python examples/emergency_mode.py --simulate --duration 30

Venezuela Scenario (Power Outage Optimization)

python examples/venezuela_scenario.py --simulate-outage --duration 60

Low Power Mode

python examples/low_power_mode.py --battery 1000 --target-hours 12 --monitor

🔧 Configuration

Configuration can be customized via environment variables or by modifying src/config/settings.py:

# Starlink Configuration
STARLINK_ENDPOINT = "192.168.100.1"
STARLINK_GRPC_PORT = 9200

# Monitoring Configuration
MONITOR_INTERVAL_SECONDS = 30
METRICS_HISTORY_SIZE = 100

# Alert Thresholds
ALERT_SIGNAL_QUALITY_MIN = 70
ALERT_LATENCY_MAX_MS = 100

🌍 Use Cases

Emergency Communications

  • Optimized for extended battery operation
  • Critical services prioritization
  • Minimal power consumption
  • Automatic failover to backup connections

Remote/Off-Grid Scenarios

  • Power management for solar/battery systems
  • Bandwidth optimization for limited capacity
  • Real-time monitoring and alerts
  • Diagnostic tools for troubleshooting

Areas with Unreliable Power

  • Automatic power mode adjustment
  • Battery runtime estimation
  • Failover to backup connections during outages
  • Continuous monitoring even during transitions

📊 Monitoring Capabilities

  • Signal Quality: Real-time signal strength monitoring
  • Satellite Tracking: Number of visible satellites
  • Network Performance: Latency, jitter, packet loss
  • Throughput: Download/upload speeds
  • Obstructions: Detection and analysis
  • Temperature: Dish temperature monitoring
  • Alerts: Configurable thresholds with notifications

🔋 Power Modes

  • Normal: Full features, maximum performance
  • ECO: Balanced power consumption and features
  • Low Power: Extended battery life, essential features only
  • Emergency: Maximum battery life, critical communications only

🔄 Failover Features

  • Automatic detection of primary connection failures
  • Seamless switching to backup connections
  • Configurable failover thresholds
  • Automatic restoration of primary connection
  • Support for multiple backup connections

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

⚠️ Disclaimer

This is an independent project and is not affiliated with, endorsed by, or connected to SpaceX or Starlink. Use at your own risk.

🙏 Acknowledgments

  • Built for communities with challenging connectivity scenarios
  • Inspired by real-world needs in areas with unreliable power and internet access
  • Special consideration for scenarios like Venezuela where reliable communications are critical

📞 Support

For issues, questions, or contributions, please visit the GitHub repository. pip install -e ".[dev]"


## Quick Start

```python
from starlink_connectivity_tools import StarlinkClient, AccountsAPI, AddressesAPI

# Initialize the client
client = StarlinkClient(base_url="https://api.starlink.com", api_key="your_api_key")

# Get account information
accounts_api = AccountsAPI(client)
account = accounts_api.get_account()
print(f"Email: {account['email']}")

# Create a new address
addresses_api = AddressesAPI(client)
address = addresses_api.create_address({
    'street': '123 Main St',
    'city': 'Seattle',
    'state': 'WA',
    'zip': '98101'
})
print(f"Address ID: {address['id']}")

API Endpoints

This library provides access to the following Starlink API endpoints:

Accounts

  • GET /account - Retrieve account details (email, customer info)
from starlink_connectivity_tools import StarlinkClient, AccountsAPI

client = StarlinkClient(api_key="your_api_key")
accounts = AccountsAPI(client)
account = accounts.get_account()

Addresses

  • POST /addresses - Create a new address for service activation
  • GET /addresses/{id} - Get details of a specific address
from starlink_connectivity_tools import StarlinkClient, AddressesAPI

client = StarlinkClient(api_key="your_api_key")
addresses = AddressesAPI(client)

# Create address
new_address = addresses.create_address({
    'street': '123 Main St',
    'city': 'Seattle',
    'state': 'WA',
    'zip': '98101'
})

# Get address
address = addresses.get_address('addr_12345')

Data Usage

  • GET /data-usage - Fetch data usage statistics for the account or devices
from starlink_connectivity_tools import StarlinkClient, DataUsageAPI

client = StarlinkClient(api_key="your_api_key")
data_usage = DataUsageAPI(client)
usage = data_usage.get_data_usage()

Routers

  • GET /routers/{id}/config - Get router configuration
from starlink_connectivity_tools import StarlinkClient, RoutersAPI

client = StarlinkClient(api_key="your_api_key")
routers = RoutersAPI(client)
config = routers.get_router_config('router_12345')

Service Lines

  • POST /service-lines - Create a new service line (for activation)
  • GET /service-lines/{id} - Retrieve service line details
from starlink_connectivity_tools import StarlinkClient, ServiceLinesAPI

client = StarlinkClient(api_key="your_api_key")
service_lines = ServiceLinesAPI(client)

# Create service line
new_line = service_lines.create_service_line({
    'address_id': 'addr_12345',
    'product_id': 'prod_12345'
})

# Get service line
line = service_lines.get_service_line('line_12345')

Subscriptions

  • GET /subscriptions - List available or active subscription products
from starlink_connectivity_tools import StarlinkClient, SubscriptionsAPI

client = StarlinkClient(api_key="your_api_key")
subscriptions = SubscriptionsAPI(client)
subs = subscriptions.get_subscriptions()

User Terminals

  • GET /user-terminals/{id} - Get user terminal (dish) details, including ID
  • POST /user-terminals - Activate or manage a user terminal
from starlink_connectivity_tools import StarlinkClient, UserTerminalsAPI

client = StarlinkClient(api_key="your_api_key")
terminals = UserTerminalsAPI(client)

# Get terminal
terminal = terminals.get_user_terminal('term_12345')

# Create/activate terminal
new_terminal = terminals.create_user_terminal({
    'service_line_id': 'line_12345',
    'serial_number': 'SN12345'
})

TLS

  • GET /tls - Retrieve TLS configuration for secure communications
from starlink_connectivity_tools import StarlinkClient, TLSAPI

client = StarlinkClient(api_key="your_api_key")
tls = TLSAPI(client)
config = tls.get_tls_config()

Development

Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run tests
python -m pytest tests/

# Run with coverage
python -m pytest --cov=starlink_connectivity_tools tests/

Running Tests with unittest

python -m unittest discover tests
from starlink_connectivity_tools import StarlinkManager

# Initialize the manager
manager = StarlinkManager()

# Enable emergency mode for crisis scenarios
manager.enable_emergency_mode()

# Monitor connection health
status = manager.get_connection_status()
print(f"Connection Status: {status}")

Usage

from starlink_client import StarlinkClient

client = StarlinkClient()  # Local connection
stats = client.get_network_stats()
print(f"Download: {stats.download_speed} Mbps, Latency: {stats.latency} ms")
client.reboot_dish()

Features

  • Network Statistics: Retrieve download/upload speeds, latency, and connection status
  • Device Control: Reboot your Starlink dish remotely
  • Easy Integration: Simple Python API for Starlink device interaction

API Reference

StarlinkClient

Main client class for interacting with Starlink devices.

client = StarlinkClient(host="192.168.100.1", port=9200, timeout=10)

Methods

  • get_network_stats(): Returns a NetworkStats object with current network performance metrics
  • reboot_dish(): Initiates a reboot of the Starlink dish

NetworkStats

Data class containing network statistics:

  • download_speed: Download speed in Mbps
  • upload_speed: Upload speed in Mbps
  • latency: Latency in milliseconds
  • uptime: Device uptime in seconds
  • obstruction_percentage: Percentage of time obstructed
  • connected: Whether the dish is connected to satellites

Example

See example.py for a complete example:

python example.py

Development

Install development dependencies:

pip install -e ".[dev]"
### Connection Management

The `SatelliteConnectionManager` class provides methods to manage satellite connections:

- `enable_crisis_mode(config)`: Enable crisis mode with custom configuration
- `scan_available_connections()`: Scan for available satellite connections
- `connect(connection)`: Connect to a specific satellite
- `get_connection_report()`: Get detailed status report of the current connection

### Bandwidth Optimization

The `BandwidthOptimizer` class helps optimize bandwidth usage:

- `enable_optimization(profile)`: Enable bandwidth optimization with a specific profile
- `disable_optimization()`: Disable bandwidth optimization
- `get_optimization_status()`: Get current optimization status

## License

See [LICENSE](LICENSE) for details.
### Smart Connection Management

```python
# Automatic satellite switching
manager.enable_auto_switching()

# Manual satellite selection
manager.select_satellite(satellite_id="sat-001")

Bandwidth Prioritization

# Set priority for critical communications
manager.set_priority("emergency_calls", priority=1)
manager.set_priority("data_sync", priority=2)
manager.set_priority("general_web", priority=3)
### Basic Connection Management

```python
from src.connection_manager import ConnectionManager

# Create a connection manager
manager = ConnectionManager()

# Connect to Starlink
manager.connect()

# Check connection status
status = manager.get_status()
print(f"Connected: {status['connected']}")

# Disconnect
manager.disconnect()

Bandwidth Optimization

from src.bandwidth_optimizer import BandwidthOptimizer

optimizer = BandwidthOptimizer(total_bandwidth=100.0)
optimizer.enable_crisis_mode()
allocated = optimizer.allocate_bandwidth(
    connection_id="emergency_msg",
    destination="emergency.comms",
    requested_bandwidth=5.0
)

Failover Handler (src/failover_handler.py)

Manages connection failover and health monitoring.

Create bandwidth optimizer

optimizer = BandwidthOptimizer(max_bandwidth=100) # 100 Mbps limit

Enable optimization

optimizer.enable_optimization()

Set bandwidth limit

optimizer.set_bandwidth_limit(50)

Get current usage

usage = optimizer.get_current_usage() print(f"Optimization enabled: {usage['optimization_enabled']}")


### Failover Configuration

```python
from src.failover_handler import FailoverHandler

handler = FailoverHandler()
healthy = handler.check_connection_health(latency=50.0, packet_loss=0.5)
if not healthy:
    handler.initiate_failover(reason="High latency detected")

Power Manager (src/power_manager.py)

Manages power consumption and battery optimization.

from src.power_manager import PowerManager, PowerMode

power_mgr = PowerManager(total_battery_capacity=500.0)
power_mgr.set_power_mode(PowerMode.CRISIS)
power_mgr.optimize_for_battery_life(target_runtime_hours=48)

Diagnostics (src/diagnostics.py)

Performs connectivity diagnostics and health checks.

from src.diagnostics import ConnectivityDiagnostics

diagnostics = ConnectivityDiagnostics()
report = diagnostics.run_full_diagnostic()

Crisis Mode

Crisis mode prioritizes critical traffic only, reducing power consumption and ensuring essential communications remain operational:

  • Emergency communications: SOS messages, emergency calls
  • Medical data: Patient records, medical telemetry
  • Coordination: Central command communications

Non-critical traffic is automatically denied to preserve bandwidth and battery life.

Requirements

  • Python 3.7+
  • Standard library only (no external dependencies)

License

MIT License - see LICENSE file for details

Author

Daniel Azevedo Novais

Create failover handler

failover = FailoverHandler()

Enable automatic failover

failover.enable_failover()

Add backup connections

failover.add_backup_connection({"type": "cellular", "priority": 1}) failover.add_backup_connection({"type": "satellite_backup", "priority": 2})

Trigger manual failover if needed

result = failover.trigger_failover() print(f"Failover status: {result['status']}")


### Power Management

```python
# Enable power-saving mode
manager.enable_power_saving()

# Set battery threshold for emergency mode
manager.set_battery_threshold(20)  # Switch to emergency mode at 20%
from src.power_manager import PowerManager

# Create power manager
power_mgr = PowerManager()

# Enable low power mode
power_mgr.enable_low_power_mode()

# Get power status
status = power_mgr.get_power_status()
print(f"Power mode: {status['power_mode']}")
print(f"Power consumption: {status['power_consumption']}%")

# Estimate battery runtime
runtime = power_mgr.estimate_runtime(battery_capacity=500)  # 500 Wh battery
print(f"Estimated runtime: {runtime:.1f} hours")

Diagnostics

# Get comprehensive system diagnostics
diagnostics = manager.run_diagnostics()
print(diagnostics.report())

# Monitor specific metrics
signal_strength = manager.get_signal_strength()
latency = manager.get_latency()
bandwidth = manager.get_available_bandwidth()

Configuration

Create a config.yaml file in your project directory:

starlink:
  emergency_mode:
    enabled: false
    auto_activate: true
    battery_threshold: 15
  
  bandwidth_priorities:
    emergency_calls: 1
    medical_data: 2
    emergency_messages: 3
    general_traffic: 4
  
  power_management:
    power_saving_enabled: false
    low_power_threshold: 30
    critical_battery_level: 10
  
  failover:
    enabled: true
    backup_connections:
      - type: cellular
        priority: 1
      - type: mesh_network
        priority: 2

Crisis Scenario Use Cases

Venezuela Emergency Response

  • Optimize connectivity during power outages
  • Prioritize medical and emergency communications
  • Efficient bandwidth usage in limited infrastructure

Natural Disaster Response

  • Quick deployment and configuration
  • Automatic failover when primary connections fail
  • Battery-optimized operation for extended periods

Remote Area Operations

  • Intelligent satellite selection for best coverage
  • Adaptive bandwidth management
  • Real-time diagnostics and monitoring

Requirements

  • Python 3.8 or higher
  • Network connectivity for satellite communication
  • Compatible Starlink hardware (for production use)

Development

Setting Up Development Environment

# Clone the repository
git clone https://github.com/danielnovais-tech/starlink_connectivity_tools.py.git
cd starlink_connectivity_tools.py

# Install in development mode
pip install -e .

Quick Start

from starlink_connectivity_tools import StarlinkDish

# Connect to the dish
with StarlinkDish() as dish:
    # Get status
    status = dish.get_status()
    print(f"Connected satellites: {status['connected_satellites']}")
    
    # Check for emergencies
    emergency = dish.check_emergency_conditions()
    if emergency:
        print(f"Emergency detected: {emergency}")
        dish.stow()  # Protective action

Usage Examples

Emergency Mode Example

Run the comprehensive emergency mode example:

python examples/emergency_mode.py

This example demonstrates:

  • Real-time status monitoring
  • Emergency condition detection
  • Interactive emergency handling
  • Continuous monitoring mode

See examples/README.md for more details.

API Overview

StarlinkDish Class

Main interface for interacting with Starlink dish.

Methods:

  • connect() - Establish connection to dish
  • disconnect() - Disconnect from dish
  • get_status() - Get current dish status
  • check_emergency_conditions() - Check for emergency conditions
  • stow() - Stow dish to emergency position
  • unstow() - Return dish to normal operation
  • reboot() - Reboot the dish

Context Manager Support:

with StarlinkDish() as dish:
    # Automatic connection and cleanup
    status = dish.get_status()

Emergency Conditions

The library monitors for various emergency conditions:

  • MOTOR_STUCK: Dish motor malfunction
  • HIGH_OBSTRUCTION: Objects blocking dish view (>10%)
  • THERMAL_THROTTLE: Overheating causing performance degradation
  • HIGH_LATENCY: Network latency exceeding thresholds (>100ms)

Development

This is a simulated implementation for demonstration and testing. In production, it would connect to an actual Starlink dish via gRPC at 192.168.100.1:9200.

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Create virtual environment

python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate

Install in development mode

pip install -e .

Install development dependencies

pip install -r requirements-dev.txt

Run tests

python -m pytest tests/


### Running Tests

```bash
pytest

Code Formatting

black starlink_connectivity_tools/
ruff check starlink_connectivity_tools/

Requirements

  • Python 3.8+
  • grpcio >= 1.50.0

License

MIT License - see LICENSE file for details. python -m unittest discover tests

Run all tests

pytest

Run with coverage

pytest --cov=starlink_connectivity_tools

Run specific test file

pytest tests/test_connection_manager.py


## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
We welcome contributions! Please follow these guidelines:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

Please ensure your code:
- Follows PEP 8 style guidelines
- Includes appropriate tests
- Updates documentation as needed

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Disclaimer

This library is not officially affiliated with or endorsed by Starlink or SpaceX. Use at your own risk. Always refer to the official Starlink API documentation for the most up-to-date information.
## Acknowledgments

- Built on top of the excellent [starlink-grpc](https://github.com/sparky8512/starlink-grpc-tools) library
- Designed for crisis response and humanitarian applications
- Inspired by real-world connectivity challenges in remote areas

## Disclaimer

This is an independent project and is not affiliated with, endorsed by, or supported by SpaceX or Starlink. Use at your own risk. The authors are not responsible for any issues arising from the use of this software.

## Support

For issues, questions, or contributions, please use the [GitHub issue tracker](https://github.com/danielnovais-tech/starlink_connectivity_tools.py/issues).
- Inspired by real-world challenges in Venezuela and crisis scenarios
- Built with support from the open-source community
- Thanks to all contributors and supporters

## Support

For issues, questions, or contributions:
- Open an issue on [GitHub](https://github.com/danielnovais-tech/starlink_connectivity_tools.py/issues)
- Contact: daniel.novais@sempreceub.com
- Documentation: [GitHub Repository](https://github.com/danielnovais-tech/starlink_connectivity_tools.py)

## Roadmap

- [ ] Enhanced power optimization algorithms
- [ ] Multi-satellite mesh networking
- [ ] Mobile app for remote monitoring
- [ ] Integration with emergency response systems
- [ ] Advanced predictive failover
- [ ] Support for additional satellite providers

## Disclaimer

This tool is designed to assist in crisis scenarios and optimize satellite connectivity. Always follow local regulations and guidelines when deploying communication equipment. This software is provided "as is" without warranty of any kind.
from src.diagnostics import Diagnostics

# Create diagnostics instance
diag = Diagnostics()

# Run health check
health = diag.run_health_check()
print(f"Health status: {health['status']}")

# Test connectivity
connectivity = diag.test_connectivity()
print(f"Connectivity test: {connectivity['status']}")

# Get signal strength
signal = diag.get_signal_strength()
print(f"Signal strength: {signal['signal_strength']}")

Examples

Emergency Mode

Run the emergency mode example for automatic failover configuration:

python examples/emergency_mode.py

This example will:

  1. Connect to a Starlink dish
  2. Perform an initial connectivity assessment
  3. Activate emergency mode if issues are detected
  4. Attempt automatic recovery procedures
  5. Monitor connectivity for a period
  6. Provide a detailed summary of operations

Using the Library

from starlink_connectivity_tools import StarlinkDish, EmergencyMode

# Connect to dish using context manager
with StarlinkDish(host="192.168.100.1") as dish:
    # Create emergency mode handler
    emergency = EmergencyMode(dish)
    
    # Check connectivity
    assessment = emergency.check_connectivity()
    
    # Activate emergency mode if needed
    if assessment and not assessment['operational']:
        emergency.activate()
        emergency.attempt_recovery()
    
    # Monitor for a period
    emergency.monitor(duration=60, interval=10)

API Overview

StarlinkDish

  • connect(): Establish connection to the dish
  • disconnect(): Disconnect from the dish
  • get_status(): Get current dish status
  • get_alerts(): Get active alerts
  • reboot(): Reboot the dish

EmergencyMode

  • activate(): Activate emergency mode
  • deactivate(): Deactivate emergency mode
  • check_connectivity(): Assess current connectivity
  • attempt_recovery(): Attempt automatic recovery
  • monitor(duration, interval): Monitor connectivity over time
  • print_summary(): Print operation summary

Note

This is a simplified implementation for demonstration purposes. In a production environment, you would integrate with the actual Starlink gRPC API using libraries like starlink-grpc-core.

License

See LICENSE file for details. This example demonstrates:

  • Extended connection timeout and retry settings
  • Automatic failover with multiple backup connections
  • Health check monitoring

Low Power Mode

Run the low power mode example for battery-powered scenarios:

python examples/low_power_mode.py

This example demonstrates:

  • Reduced power consumption settings
  • Bandwidth limiting and optimization
  • Battery runtime estimation

Running Tests

# Run all tests
python -m unittest discover tests

# Run specific test file
python -m unittest tests.test_optimizer
python -m pytest tests/

# Run with coverage
python -m pytest --cov=src tests/

# Run specific test file
python -m pytest tests/test_connection_manager.py

Configuration

The library uses a centralized configuration system in src/config/settings.py:

from src.config.settings import Settings

# Create settings with custom config
config = {
    "connection": {
        "timeout": 60,
        "retry_attempts": 5,
    },
    "power": {
        "default_mode": "low_power",
    },
}
settings = Settings(custom_config=config)

# Get configuration values
timeout = settings.get("connection.timeout")

# Update configuration
settings.set("connection.retry_attempts", 3)

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests with coverage
pytest --cov=starlink_connectivity tests/
### Code Style

This project follows Python best practices:
- PEP 8 style guide
- Type hints where appropriate
- Comprehensive docstrings

### Running Linters

```bash
# Format code with black
black src/ tests/ examples/

# Check code with flake8
flake8 src/ tests/ examples/

# Type checking with mypy
mypy src/

License

MIT License - see LICENSE file for details This project is licensed under the Apache License 2.0 - see the LICENSE file for details. This project is licensed under the Apache License 2.0 - see the LICENSE file for details. This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

Inspired by:

Support

For issues and questions, please use the GitHub Issues page.

Support

For issues and questions, please open an issue on the GitHub repository.

Acknowledgments

Designed for reliable satellite connectivity in remote, off-grid, and emergency scenarios where power management is critical. This library is designed to work with Starlink satellite internet connections, providing tools for optimized bandwidth management in various scenarios including critical communications during emergencies. Inspired by real-world connectivity challenges and the need for reliable emergency communication systems in crisis scenarios.

Support

For issues, questions, or contributions, please visit the GitHub repository.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages