WebSocket Streams

Real-time data streaming with WebSocket connections for live vehicle telemetry, system events, and analytics.

Available Streams

Vehicle Telemetry

Real-time vehicle sensor data and status updates

Available Events

  • location_update
  • speed_reading
  • battery_status
  • sensor_data

System Events

Platform events and status notifications

Available Events

  • system_alert
  • maintenance_required
  • status_change
  • error_notification

Analytics

Real-time analytics and metrics

Available Events

  • performance_metrics
  • usage_statistics
  • trend_analysis
  • anomaly_detection

Implementation Guide

JavaScript
import { LattisNexusClient } from '@lattis-nexus/sdk';

const client = new LattisNexusClient({
  apiKey: 'your_api_key'
});

// Subscribe to vehicle telemetry stream
client.stream.subscribe('vehicle_telemetry', {
  vehicleId: 'v123',
  events: ['location_update', 'speed_reading']
}, (data) => {
  console.log('Received telemetry:', data);
});

// Handle connection events
client.stream.on('connected', () => {
  console.log('Connected to WebSocket');
});

client.stream.on('error', (error) => {
  console.error('WebSocket error:', error);
});
Python
from lattis_nexus import Client
import asyncio

client = Client(api_key='your_api_key')

async def handle_telemetry(data):
    print(f"Received telemetry: {data}")

async def main():
    # Subscribe to vehicle telemetry stream
    await client.stream.subscribe(
        'vehicle_telemetry',
        vehicle_id='v123',
        events=['location_update', 'speed_reading'],
        callback=handle_telemetry
    )

    # Handle connection events
    client.stream.on_connected(lambda: print("Connected to WebSocket"))
    client.stream.on_error(lambda e: print(f"WebSocket error: {e}"))

    await client.stream.connect()

asyncio.run(main())

Best Practices

Connection Management

Implement proper reconnection logic with exponential backoff

Error Handling

Handle connection errors and data parsing failures gracefully

Data Processing

Process incoming data efficiently to prevent bottlenecks

State Management

Maintain proper state for subscribed streams and events

Try it Live

Experience real-time data streaming with our interactive WebSocket demo. Connect to a test stream and see live data in action.