A professional, modular telemetry collection system for Live for Speed racing simulator.
A modular and complete system for collecting, processing, and visualizing telemetry data from the Live for Speed racing simulator using the InSim protocol.
This repository provides a professional implementation of the Live for Speed InSim protocol, enabling:
LFS-Ayats/
βββ src/ # Main source code
β βββ api/ # REST API (FastAPI)
β β βββ __init__.py
β β βββ main.py # FastAPI application
β β βββ models.py # Pydantic models
β β βββ dependencies.py # Dependency injection
β β βββ middleware.py # CORS and logging
β β βββ exceptions.py # Custom exceptions
β β βββ routers/ # API endpoints
β βββ connection/ # InSim connection module
β β βββ __init__.py
β β βββ insim_client.py # InSim TCP/UDP client
β β βββ packet_handler.py # InSim packet handling
β βββ telemetry/ # Telemetry module
β β βββ __init__.py
β β βββ collector.py # Telemetry data collection
β β βββ processor.py # Data processing and validation
β βββ database/ # Database module
β β βββ __init__.py
β β βββ models.py # SQLAlchemy models
β β βββ repository.py # Data access layer
β βββ visualization/ # Visualization module
β β βββ __init__.py
β β βββ dashboard.py # Real-time web dashboard (Dash)
β β βββ plots.py # Analysis plots
β β βββ map_view.py # Circuit map visualization
β β βββ comparator.py # Lap comparison
β β βββ components/ # Reusable components
β βββ export/ # Export module
β β βββ __init__.py
β β βββ csv_exporter.py # CSV export
β β βββ json_exporter.py # JSON export
β β βββ db_exporter.py # Database export
β βββ config/ # Configuration management
β β βββ __init__.py
β β βββ settings.py # Application configuration
β βββ utils/ # Common utilities
β βββ __init__.py
β βββ logger.py # Logging system
βββ tests/ # Automated tests
β βββ unit/ # Unit tests
β βββ integration/ # Integration tests
β βββ fixtures/ # Test data
βββ examples/ # Usage examples
β βββ basic_connection.py # Basic connection
β βββ telemetry_monitor.py # Telemetry monitor
β βββ data_logger.py # Data logger
β βββ api_client_example.py # REST API client
βββ docs/ # Documentation
β βββ insim_protocol.md # InSim protocol documentation
β βββ packet_reference.md # Packet reference
β βββ api_reference.md # API reference
β βββ api_documentation.md # REST API documentation
β βββ development.md # Development guide
βββ scripts/ # Utility scripts
β βββ delete-branches.sh # Branch management
βββ .gitignore # Git ignored files
βββ requirements.txt # Python dependencies
βββ setup.py # Package installation
βββ pytest.ini # pytest configuration
βββ README.md # This file
# Clone the repository
git clone https://github.com/lfsplayer97/LFS-Ayats.git
cd LFS-Ayats
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# β οΈ IMPORTANT: Install package in development mode
pip install -e .
π‘ Why
pip install -e .is required:The
-eflag installs the package in editable/development mode, which:
- Makes the
srcmodule importable from anywhere in your code- Automatically reflects code changes without reinstalling
- Creates a symbolic link to your source code
Without this step, youβll encounter
ModuleNotFoundError: No module named 'src'when running examples or tests.β Verify installation:
pip show lfs-ayatsshould display the package info
Run the verification script to check your setup:
python scripts/verify_setup.py
This will check:
If you see ModuleNotFoundError: No module named 'src':
pip install -e . from the project root directorypip show lfs-ayatspython scripts/verify_setup.py to diagnose issuesFor more help, see the Troubleshooting Guide.
LFS-Ayats has extensive documentation for all user levels:
| Tutorial | Description | Time | Level |
|---|---|---|---|
| 01 - First Session | Collect and export basic telemetry | 30 min | Beginner |
| 02 - Lap Analysis | Compare laps and find improvements | 45 min | Intermediate |
| 03 - Real-time Dashboard | Create interactive web dashboard | 30 min | Intermediate |
| 04 - Advanced Analysis | Machine learning and predictions | 60 min | Advanced |
| 05 - Database | Store historical data | 45 min | Advanced |
π Complete Documentation Index
from src.connection import InSimClient
from src.telemetry import TelemetryCollector
# Create InSim client
client = InSimClient(
host='127.0.0.1',
port=29999,
admin_password='',
app_name='LFS-Ayats'
)
# Connect
client.connect()
# Create telemetry collector
collector = TelemetryCollector(client)
# Start data collection
collector.start()
from src.export import CSVExporter, JSONExporter
# Export to CSV
csv_exporter = CSVExporter('telemetry_data.csv')
csv_exporter.export(telemetry_data)
# Export to JSON
json_exporter = JSONExporter('telemetry_data.json')
json_exporter.export(telemetry_data)
The system includes a complete REST API built with FastAPI for programmatic access:
The API supports environment-based configuration for different deployment scenarios:
Database Configuration:
# Copy the example environment file
cp .env.example .env
# Edit .env to configure your database
# For development (default):
DATABASE_URL=sqlite:///telemetry.db
# For production with PostgreSQL:
DATABASE_URL=postgresql://username:password@localhost:5432/lfs_telemetry
# For production with MySQL:
DATABASE_URL=mysql://username:password@localhost:3306/lfs_telemetry
Security Notes:
.env file to version control (already in .gitignore)# Start the API server
uvicorn src.api.main:app --reload --host 0.0.0.0 --port 8000
Automatic Documentation:
Client usage example:
import requests
# List sessions
response = requests.get("http://localhost:8000/api/v1/sessions")
sessions = response.json()
# Get lap telemetry
response = requests.get("http://localhost:8000/api/v1/1/telemetry")
telemetry = response.json()
# WebSocket for real-time telemetry
import websockets
import asyncio
async def receive_telemetry():
uri = "ws://localhost:8000/api/v1/telemetry/live"
async with websockets.connect(uri) as websocket:
while True:
data = await websocket.recv()
print(f"Telemetry: {data}")
asyncio.run(receive_telemetry())
Available endpoints:
/api/v1/health - Health check/api/v1/sessions - Session management/api/v1/{lap_id} - Lap information/api/v1/telemetry/live - WebSocket streaming/api/v1/stats/best-laps - Best laps/api/v1/export/csv/{lap_id} - CSV exportSee docs/api_documentation.md for complete API documentation.
LFS-Ayats offers integrations with external services for notifications, streaming, and automatic backup.
Send automatic notifications to Discord channels:
from src.integrations import DiscordIntegration
discord = DiscordIntegration(webhook_url="https://discord.com/api/webhooks/...")
# Notify personal best
await discord.notify_personal_best({
'circuit': 'Blackwood GP',
'time': 98.456,
'vehicle': 'XF GTI',
'improvement': 0.234
})
Send messages and images via a Telegram bot:
from src.integrations import TelegramIntegration
telegram = TelegramIntegration(bot_token="YOUR_TOKEN", chat_id="YOUR_CHAT_ID")
await telegram.send_message("<b>System online!</b>")
Display real-time telemetry in OBS Studio:
from src.integrations import StreamingOverlay
overlay = StreamingOverlay(port=5000)
overlay.start() # Access at http://localhost:5000
# Update telemetry data
overlay.update_telemetry({
'speed': 120.5,
'rpm': 6500,
'gear': 4,
'lap_time': 98.456
})
Automatic backup to Google Drive or Dropbox:
from src.integrations import GoogleDriveIntegration
gdrive = GoogleDriveIntegration('./credentials.json')
gdrive.auto_backup('./data/', folder_id='optional_folder_id')
Configuration:
Add to config.yaml:
integrations:
discord:
enabled: true
webhook_url: "${DISCORD_WEBHOOK_URL}"
notifications:
personal_best: true
session_summary: true
anomalies: true
telegram:
enabled: false
bot_token: "${TELEGRAM_BOT_TOKEN}"
chat_id: "${TELEGRAM_CHAT_ID}"
streaming:
enabled: false
overlay_port: 5000
update_rate: 10 # Hz
cloud_backup:
enabled: false
provider: google_drive
auto_backup: true
backup_interval: 3600 # seconds
credentials_path: ./credentials.json
Complete examples:
examples/discord_integration_example.pyexamples/telegram_integration_example.pyexamples/streaming_overlay_example.pyexamples/cloud_storage_example.pyexamples/integrated_system_example.pySee docs/integrations.md for complete integration documentation.
from src.visualization import TelemetryDashboard
# Create real-time web dashboard
dashboard = TelemetryDashboard(
host='127.0.0.1',
port=29999,
update_interval=100 # update every 100ms
)
# Run the dashboard server
dashboard.run(debug=True, port=8050)
# Open browser at http://localhost:8050
from src.visualization import (
LapComparator,
create_speed_vs_distance_plot,
create_track_map,
create_heatmap_plot
)
# Compare laps
comparator = LapComparator()
comparator.add_lap("Lap 1", lap1_telemetry)
comparator.add_lap("Lap 2", lap2_telemetry)
# Create comparison plots
fig = comparator.create_comparison_plot()
fig.write_html("lap_comparison.html")
# Create track map with speeds
track_fig = create_track_map(telemetry, show_speed_colors=True)
track_fig.write_html("track_map.html")
# Create heatmap
heatmap_fig = create_heatmap_plot(telemetry)
heatmap_fig.write_html("speed_heatmap.html")
For more information on visualization, see docs/visualization.md
The project includes comprehensive automated tests to ensure code quality:
# Run all tests
pytest
# Run tests with coverage
pytest --cov=src --cov-report=html
# Run specific tests
pytest tests/unit/connection/
pytest tests/integration/
InSim (Internet Simulator) is Live for Speedβs communication protocol that allows external applications to interact with the simulator.
| Packet | Description | Usage |
|---|---|---|
IS_ISI |
InSim Init | Initialize InSim connection |
IS_VER |
Version | InSim protocol version |
IS_TINY |
Tiny | Small control packets |
IS_SMALL |
Small | Small data packets |
IS_MCI |
Multi Car Info | Multiple car information |
IS_NLP |
Node and Lap | Node and lap information |
IS_MSO |
Message Out | Server messages |
IS_III |
InSim Info | Server information |
IS_STA |
State | Server state |
IS_NCN |
New Connection | New player connection |
IS_CNL |
Connection Leave | Player disconnect |
IS_CPR |
Connection Player Rename | Player name change |
IS_NPL |
New Player | New player on track |
IS_PLP |
Player Leave | Player leaves track |
IS_PIT |
Pit Stop | Pit stop |
IS_PSF |
Pit Stop Finish | Pit stop finish |
IS_LAP |
Lap Time | Lap time |
IS_SPX |
Split Time | Sector time |
IS_PEN |
Penalty | Penalty |
IS_TOC |
Take Over Car | Car control change |
IS_FLG |
Flag | Flag |
IS_RES |
Result | Results |
IS_REO |
Reorder | Car reordering |
IS_BTN |
Button | Interface buttons |
IS_BFN |
Button Function | Button functions |
IS_AXI |
Autocross Info | Autocross information |
IS_RIP |
Replay Info | Replay information |
Telemetry that can be collected includes:
docs/api_reference.mdContributions are welcome! If you want to contribute:
git checkout -b feature/new-feature)git commit -m 'Add new feature')git push origin feature/new-feature)To start contributing, see:
This project uses GitHub Actions for automated testing and quality checks:
main and develop
Install pre-commit hooks for local development:
pip install pre-commit
pre-commit install
This will automatically check your code before each commit.
This project is licensed under the MIT License. See the LICENSE file for more details.
If you have questions, suggestions, or ideas to improve the project, feel free to contact me!
Email: lfsplayer97@gmail.com
LFS-Ayats is an open-source project and your collaboration is very important. If you have ideas, find bugs, or want to contribute with new features:
Note: This project is under active development. Check the documentation and examples for more information on usage and available features.