β‘ Real-time Modbus TCP/RTU API with WebSocket Updates
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
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
mix local.hex --force
mix archive.install hex phx_new
mix deps.get
mix ecto.create
mix ecto.migrate
mix phx.server
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
}
GET /api/devices/1/read
Response:
{ "device_id": 1, "value": 12345 }
POST /api/devices/1/write
Content-Type: application/json
{
"value": 54321
}
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);
});
- π‘ 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
This project is licensed under the MIT License.