Skip to content

neurabytelabs/rustbridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŒ‰ RustBridge

CI Release Rust License: MIT Docker

Industrial Protocol Bridge - Modbus TCP/RTU to JSON/MQTT Gateway

RustBridge is a high-performance, lightweight gateway that bridges industrial Modbus devices to modern IoT infrastructure. Built with Rust for reliability, speed, and minimal resource usage.

🏭 "Connecting legacy PLCs to the cloud, one register at a time."

🌐 Live Demo

Try the API without installing anything:

# Health check
curl https://rustbridge.mustafasarac.com/health

# API info
curl https://rustbridge.mustafasarac.com/api/info

# Prometheus metrics
curl https://rustbridge.mustafasarac.com/metrics

Demo URL: rustbridge.mustafasarac.com

✨ Features

  • πŸš€ High Performance β€” Handles 1000+ registers per second
  • πŸ”Œ Dual Protocol β€” Modbus TCP and RTU (serial) support
  • πŸ“‘ MQTT Publisher β€” Real-time data streaming to any MQTT broker
  • 🌐 REST API β€” JSON endpoints for integration
  • πŸ“Š WebSocket β€” Real-time updates for dashboards
  • πŸ“ˆ Prometheus Metrics β€” Production-ready monitoring
  • 🐳 Docker Ready β€” Single command deployment
  • ⚑ Edge Optimized β€” Runs on Raspberry Pi, industrial gateways

πŸ“š Documentation

Document Description
Getting Started Quick installation and first steps
Configuration Complete configuration reference
API Reference REST API and WebSocket documentation
Modbus Guide Modbus protocol deep dive
MQTT Integration MQTT broker setup and topics
Prometheus Metrics Monitoring and alerting
Deployment Production deployment strategies
Troubleshooting Common issues and solutions
Examples Real-world use cases

πŸš€ Quick Start

Option 1: Docker (Recommended)

# Simple run
docker run -d \
  -p 3000:3000 \
  -v ./config.yaml:/app/config.yaml \
  ghcr.io/neurabytelabs/rustbridge:latest

# With Docker Compose (includes MQTT broker)
docker compose up -d

Option 2: Download Binary

Download the latest release for your platform from GitHub Releases:

  • Linux x86_64: rustbridge-x86_64-unknown-linux-gnu
  • Linux ARM64: rustbridge-aarch64-unknown-linux-gnu
  • macOS Intel: rustbridge-x86_64-apple-darwin
  • macOS Apple Silicon: rustbridge-aarch64-apple-darwin
chmod +x rustbridge-*
./rustbridge-x86_64-unknown-linux-gnu

Option 3: From Source

git clone https://github.com/neurabytelabs/rustbridge.git
cd rustbridge
cargo build --release
./target/release/rustbridge

πŸ“ Configuration

Create a config.yaml file:

server:
  host: "0.0.0.0"
  port: 3000
  metrics_enabled: true

mqtt:
  enabled: true
  host: "localhost"
  port: 1883
  client_id: "rustbridge"
  topic_prefix: "rustbridge"
  qos: 1
  retain: false

# API Authentication (optional)
auth:
  enabled: true
  api_keys:
    - "your-secret-key-1"
    - "your-secret-key-2"
  exclude_paths:
    - "/health"
    - "/metrics"

devices:
  # Modbus TCP device
  - id: "plc-01"
    name: "Main PLC"
    device_type: tcp
    connection:
      host: "192.168.1.100"
      port: 502
      unit_id: 1
    poll_interval_ms: 1000
    registers:
      - name: "temperature"
        address: 0
        register_type: holding
        count: 1
        data_type: u16
        unit: "Β°C"
        scale: 0.1

  # Modbus RTU (Serial) device
  - id: "sensor-01"
    name: "RTU Sensor"
    device_type: rtu
    connection:
      port: "/dev/ttyUSB0"
      baud_rate: 9600
      data_bits: 8
      stop_bits: 1
      parity: "none"
      unit_id: 1
    poll_interval_ms: 2000
    registers:
      - name: "humidity"
        address: 0
        register_type: input
        count: 1
        data_type: u16
        unit: "%"

πŸ“– See Configuration Reference for all options.

πŸ”Œ API Endpoints

Endpoint Method Description
/health GET Health check
/metrics GET Prometheus metrics
/api/info GET API information
/api/devices GET List all devices
/api/devices/:id GET Get device details
/api/devices/:id/registers GET Get all register values
/api/devices/:id/registers/:name GET/POST Get/Write register
/ws WebSocket Real-time updates

Example Response

{
  "name": "temperature",
  "value": 72.4,
  "raw": [724],
  "unit": "Β°C",
  "timestamp": "2025-12-26T23:15:00Z"
}

πŸ“– See API Reference for full documentation.

πŸ“‘ MQTT Topics

Data is published to: {prefix}/{device_id}/{register_name}

Example: rustbridge/plc-01/temperature

{
  "value": 72.4,
  "raw": [724],
  "unit": "Β°C",
  "timestamp": "2025-12-26T23:15:00Z"
}

πŸ“– See MQTT Integration for broker setup.

πŸ“Š Prometheus Metrics

Available at /metrics when metrics_enabled: true:

Metric Type Description
rustbridge_register_reads_total Counter Total register read attempts
rustbridge_read_duration_seconds Histogram Read latency distribution
rustbridge_register_value Gauge Current register values
rustbridge_errors_total Counter Error count by type
rustbridge_device_connected Gauge Device connection status
rustbridge_poll_cycle_seconds Histogram Poll cycle duration

πŸ“– See Prometheus Metrics for Grafana dashboards and alerting.

🚒 Production Deployment

Docker Compose (Recommended)

# Production stack
docker compose up -d

# With monitoring (Prometheus + Grafana)
docker compose --profile monitoring up -d

# With Modbus simulator for testing
docker compose --profile dev up -d

Access:

systemd Service (Bare Metal)

# Install
cd deploy
sudo ./install.sh

# Control
sudo systemctl start rustbridge
sudo systemctl status rustbridge
sudo journalctl -u rustbridge -f

Kubernetes / Helm

# Coming soon - Helm chart
helm repo add rustbridge https://neurabytelabs.github.io/rustbridge
helm install rustbridge rustbridge/rustbridge

πŸ“– See Deployment Guide for HA setup, edge devices, and more.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        RUSTBRIDGE                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Modbus  │───▢│ Polling  │───▢│Broadcast│──▢│  MQTT   β”‚  β”‚
β”‚  β”‚TCP/RTU  β”‚    β”‚ Engine   β”‚    β”‚ Channel β”‚   β”‚Publisherβ”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                      β”‚                      β”‚
β”‚                                      β–Ό                      β”‚
β”‚                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚                      β”‚      REST API + WS       β”‚          β”‚
β”‚                      β”‚    (/api, /ws, /metrics) β”‚          β”‚
β”‚                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚                                      β”‚                      β”‚
β”‚                                      β–Ό                      β”‚
β”‚                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚                      β”‚   Prometheus + Grafana   β”‚          β”‚
β”‚                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Development

# Run tests
cargo test

# Run with logging
RUST_LOG=debug cargo run

# Build release
cargo build --release

# Run clippy
cargo clippy

# Format code
cargo fmt

πŸ“ Project Structure

rustbridge/
β”œβ”€β”€ docs/                # πŸ“š Documentation
β”‚   β”œβ”€β”€ getting-started.md
β”‚   β”œβ”€β”€ configuration.md
β”‚   β”œβ”€β”€ api-reference.md
β”‚   β”œβ”€β”€ modbus-guide.md
β”‚   β”œβ”€β”€ mqtt-integration.md
β”‚   β”œβ”€β”€ prometheus-metrics.md
β”‚   β”œβ”€β”€ deployment.md
β”‚   β”œβ”€β”€ troubleshooting.md
β”‚   └── examples.md
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs          # Entry point
β”‚   β”œβ”€β”€ lib.rs           # Library exports
β”‚   β”œβ”€β”€ config.rs        # Configuration parsing
β”‚   β”œβ”€β”€ bridge.rs        # Main orchestration
β”‚   β”œβ”€β”€ api/             # REST API + WebSocket
β”‚   β”œβ”€β”€ modbus/          # Modbus TCP/RTU client
β”‚   β”œβ”€β”€ mqtt/            # MQTT publisher
β”‚   └── metrics/         # Prometheus metrics
β”œβ”€β”€ deploy/
β”‚   β”œβ”€β”€ mosquitto/       # MQTT broker config
β”‚   β”œβ”€β”€ prometheus/      # Prometheus config
β”‚   β”œβ”€β”€ grafana/         # Grafana provisioning
β”‚   β”œβ”€β”€ systemd/         # systemd service file
β”‚   β”œβ”€β”€ install.sh       # Installation script
β”‚   └── uninstall.sh     # Uninstallation script
β”œβ”€β”€ config.yaml          # Example configuration
β”œβ”€β”€ Dockerfile           # Multi-stage build
└── docker-compose.yml   # Full stack deployment

πŸ”’ Security

  • πŸ”‘ API Key Authentication β€” Secure endpoints with X-API-Key header
  • Non-root Docker container
  • systemd security hardening
  • TLS support for MQTT connections
  • Rate limiting (coming soon)

API Authentication

Enable API key authentication in your config.yaml:

auth:
  enabled: true
  api_keys:
    - "your-secret-api-key"
  exclude_paths:
    - "/health"
    - "/metrics"

Then include the key in requests:

curl -H "X-API-Key: your-secret-api-key" https://rustbridge.example.com/api/devices

πŸ“– See API Reference for authentication details.

πŸ“œ License

MIT License - See LICENSE for details.

🀝 Contributing

Contributions are welcome! Please read our contributing guidelines.

πŸ“ž Support


Built with ❀️ by NeuraByte Labs

Part of the Conatus Protocol - Industrial Edge AI Initiative

About

🏭 RustBridge β€” Modbus TCP/RTU to JSON/MQTT Gateway for Industry 4.0

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages