Skip to content

ModBridge is a scalable Modbus TCP/RTU bridging service built with Elixir & Phoenix, designed for control and monitoring real-time industrial automation.

Notifications You must be signed in to change notification settings

yogspuuu/ModBridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 

Repository files navigation

πŸ”Œ ModBridge - Real-Time Modbus API & WebSocket Bridge

⚑ Real-time Modbus TCP/RTU API with WebSocket Updates

πŸ“Œ Overview

ModBridge is a scalable Modbus TCP/RTU bridging service built with Elixir & Phoenix, designed for real-time industrial automation.
It enables CRUD management of Modbus devices and supports:

βœ… Modbus TCP & RTU Communication
βœ… Bit-Level & Full Register Read/Write
βœ… Real-Time WebSocket Updates
βœ… Dynamic Device Configuration (No Static Settings)
βœ… Efficient Polling with GenServer

πŸ“‚ Folder Structure

modbridge/
│── lib/
β”‚   β”œβ”€β”€ modbus_bridge/
β”‚   β”‚   β”œβ”€β”€ devices/                   # Device management
β”‚   β”‚   β”‚   β”œβ”€β”€ device.ex              # Device schema (Ecto)
β”‚   β”‚   β”‚   β”œβ”€β”€ devices.ex             # CRUD functions
β”‚   β”‚   β”‚   β”œβ”€β”€ device_controller.ex   # REST API for managing devices
β”‚   β”‚   β”œβ”€β”€ modbus/                    # Modbus communication layer
β”‚   β”‚   β”‚   β”œβ”€β”€ modbus_client.ex       # Handles Modbus TCP/RTU read/write
β”‚   β”‚   β”‚   β”œβ”€β”€ modbus_polling.ex      # Polling mechanism for real-time updates
β”‚   β”‚   β”œβ”€β”€ websocket/                 # WebSocket for real-time streaming
β”‚   β”‚   β”‚   β”œβ”€β”€ modbus_channel.ex      # Handles WebSocket communication
β”‚   β”‚   β”œβ”€β”€ modbus_bridge.ex           # Main application module
│── config/                            # Configuration files
│── priv/repo/migrations/              # Database migrations
│── test/                              # Unit & integration tests
│── mix.exs                            # Dependencies & project config
│── README.md                          # Project documentation

πŸš€ Installation

1️⃣ Install dependencies

mix local.hex --force
mix archive.install hex phx_new
mix deps.get

2️⃣ Setup the database

mix ecto.create
mix ecto.migrate

3️⃣ Start the server

mix phx.server

πŸ›  API Endpoints

πŸ“ Create a Device

POST /api/devices
Content-Type: application/json
{
  "name": "PLC 1",
  "protocol": "TCP",
  "ip": "192.168.1.100",
  "port": 502,
  "type": "Holding Register",
  "address": 40001,
  "bit_address": null,
  "writable": true,
  "poll_interval": 1000
}

πŸ“ Read a Register

GET /api/devices/1/read

Response:

{ "device_id": 1, "value": 12345 }

πŸ“ Write to a Register

POST /api/devices/1/write
Content-Type: application/json
{
  "value": 54321
}

πŸ”₯ WebSocket Updates

let socket = new Phoenix.Socket("ws://localhost:4000/socket");
socket.connect();

let channel = socket.channel("modbus:updates", {});
channel.join();

channel.on("modbus_update", payload => {
  console.log("Modbus Update:", payload);
});

πŸ›  Features

  • πŸ“‘ Supports Modbus TCP & RTU
  • πŸ”„ Read & Write Registers (Bit-Level & Full Register)
  • ⚑ WebSocket for Real-Time Updates
  • πŸ“Š Polling Optimized with GenServer
  • πŸ›  REST API for Dynamic Device Configuration

πŸ“œ License

This project is licensed under the MIT License.

About

ModBridge is a scalable Modbus TCP/RTU bridging service built with Elixir & Phoenix, designed for control and monitoring real-time industrial automation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published