NetBurner 3.5.6
PDF Version
Web Socket Console

WebSocket Console

A NetBurner NNDK application that provides WebSocket-based access to UART/serial ports and stdio console functionality.

Overview

This application creates WebSocket endpoints that allow web-based clients to communicate with:

  • Standard I/O (stdin/stdout/stderr) via WebSocket
  • Up to 10 UART/serial ports with configurable parameters

The application acts as a bridge between WebSocket connections and serial communication interfaces, enabling remote serial console access through a web browser.

Features

  • WebSocket Console Access: Connect to the device's standard I/O streams via WebSocket
  • UART Bridging: Access up to 10 UART ports through individual WebSocket connections
  • Configurable Serial Parameters: Set baud rate, data bits, parity, and stop bits per UART
  • Real-time Data Transfer: Bidirectional data flow between WebSocket and serial interfaces
  • Connection Management: Automatic cleanup on connection errors
  • Status Monitoring: Built-in diagnostics and connection status reporting

WebSocket Endpoints

Standard I/O Console

  • Endpoint: stdio*
  • Function: Redirects stdin, stdout, and stderr to the WebSocket connection
  • Usage: General console access and debugging

UART Access

  • Endpoint: uart*
  • Function: Provides WebSocket access to individual UART ports
  • Parameters (via query string):
    • uart: UART port number (0-9)
    • baud: Baud rate (1-230400)
    • data_bits: Data bits (5-8)
    • parity: Parity mode (0-2)
    • stop_bits: Stop bits (1-3)

Configuration Parameters

UART Configuration

  • Port Range: 0-9 (10 total ports supported)
  • Baud Rate Range: 1 to 230,400 bps
  • Data Bits: 5, 6, 7, or 8 bits
  • Parity: 0 (None), 1 (Odd), 2 (Even)
  • Stop Bits: 1, 2, or 3 bits

System Settings

  • Buffer Management: Automatic buffer allocation and cleanup
  • Connection Limit: One WebSocket connection per UART port
  • Error Handling: Automatic connection cleanup on errors

Usage Examples

Connecting to Standard I/O

ws://device-ip/stdio

Connecting to UART Port

ws://device-ip/uart?uart=0&baud=115200&data_bits=8&parity=0&stop_bits=1

This example connects to UART port 0 with:

  • 115,200 bps baud rate
  • 8 data bits
  • No parity
  • 1 stop bit

Application Architecture

Main Components

  1. WebSocket Handlers: Process incoming WebSocket connections
  2. UART Management: Handle serial port configuration and I/O
  3. Data Bridging: Transfer data between WebSocket and serial interfaces
  4. Connection Monitoring: Track active connections and handle errors

Key Functions

  • StdioWS(): Handles stdio WebSocket connections
  • UartWS(): Processes UART WebSocket requests
  • spliceToWS(): Transfers data from UART to WebSocket
  • spliceToUart(): Transfers data from WebSocket to UART
  • ParseUartConfig(): Validates and parses UART configuration parameters

Error Handling

The application includes robust error handling for:

  • Invalid UART configuration parameters
  • Port availability conflicts
  • WebSocket connection errors
  • Serial port communication failures
  • Buffer overflow conditions

HTTP Responses

  • 400 Bad Request: Invalid configuration parameters
  • 404 Not Found: Invalid WebSocket upgrade request
  • 503 Not Available: Port already in use or unavailable

System Requirements

  • NetBurner NNDK (NetBurner Real-Time Operating System)
  • Network connectivity (Ethernet with DHCP)
  • HTTP server support
  • WebSocket protocol support
  • Available UART hardware ports

Compilation Dependencies

Status Monitoring

The application provides real-time status information including:

  • Active WebSocket connections
  • UART port assignments
  • Buffer usage statistics
  • Connection health monitoring

Status updates are printed to the console every 10 seconds, showing:

  • Current socket file descriptors
  • UART port mappings
  • Memory buffer availability

Troubleshooting

Common Issues

  1. Port Already in Use: Ensure UART port is not already connected
  2. Invalid Parameters: Check baud rate and bit configuration ranges
  3. Connection Dropped: Monitor network stability and WebSocket client implementation
  4. Buffer Overflow: Monitor system buffer usage in high-throughput scenarios

Diagnostic Features

  • Built-in task stack checking (when NBRTOS_STACKCHECK is enabled)
  • Connection status reporting
  • Buffer usage monitoring
  • Automatic error detection and cleanup