Skip to content

Repository files navigation

Modbus Device Simulator 🏭


πŸ“‹ Project Introduction

A powerful Modbus device simulator designed for industrial automation testing, teaching demonstrations, and system integration testing. This project provides a complete solution including Modbus server, Web monitoring interface, and real-time data updates.

Industrial Automation Teaching Demo System Integration

✨ Key Features

Feature Description Icon
πŸš€ High Performance Async IO implementation, high concurrency support ⚑
πŸ”„ Real-time WebSocket data push, millisecond updates πŸ•’
πŸ“Š Visualization Intuitive Web interface, real-time data display πŸ“ˆ
πŸ”Œ Multi-device Support for 7 common industrial devices 🏭
πŸ›  Extensible Modular design, easy to add new devices πŸ”§
🐳 Docker Support Supports Docker deployment, one-click startup 🐳

Core Features

πŸš€ High Performance
  • Async IO implementation
  • High concurrency support
  • Low latency data updates
  • Optimized data processing
πŸ”„ Real-time
  • WebSocket real-time data push
  • Millisecond-level updates
  • Multi-client synchronization
  • Reliable data transmission
πŸ“Š Visualization
  • Intuitive Web interface
  • Real-time data display
  • Device status monitoring
  • Data trend analysis
🐳 Docker Support
  • One-click deployment
  • Environment isolation
  • Quick startup
  • Easy maintenance

πŸš€ Quick Start

Requirements

Requirement Description
Python 3.8+
OS Windows/Linux/MacOS
Network TCP/IP support
Memory 2GB+ recommended
Storage 1GB+ recommended
Docker Optional, for containerized deployment

Installation

Method 1: Direct Run

  1. Clone the repository
git clone https://github.com/prairie-spark-iot/modbus-simulator.git
cd modbus-simulator
  1. Create virtual environment
# Windows
python -m venv .venv
.venv\Scripts\activate

# Linux/MacOS
python -m venv .venv
source .venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Run the project
python -m src.main

Method 2: Docker Deployment

  1. Clone the repository
git clone https://github.com/prairie-spark-iot/modbus-simulator.git
cd modbus-simulator
  1. Build and start container
# Using docker-compose (recommended)
docker-compose up -d

# Or using docker commands
docker build -t modbus-simulator .
docker run -d -p 8000:8000 -p 502:502 --name modbus-simulator modbus-simulator
  1. Check container status
docker-compose ps
# or
docker ps
  1. View logs
docker-compose logs -f
# or
docker logs -f modbus-simulator
  1. Stop service
docker-compose down
# or
docker stop modbus-simulator

Access

Service Address Description
🌐 Web Interface http://localhost:8000 Device monitoring interface
πŸ“‘ Modbus Server localhost:502 Modbus communication service
πŸ“š API Docs http://localhost:8000/docs API documentation

πŸ“¦ Device Support

Device Type Slave ID Main Features Icon
Temperature & Humidity Sensor 1 Temperature, humidity data 🌑️
Energy Meter 2 Voltage, current, power, energy ⚑
AC Controller 3 Temperature, mode, switch status ❄️
Air Quality Sensor 4 PM2.5, CO2, TVOC data 🌫️
PLC/IO Module 5 Digital/Analog I/O πŸ”Œ
Smart Light Controller 6 Brightness, color temp, switch πŸ’‘
Smart Socket 7 Power, switch status, timing πŸ”‹

πŸ— System Architecture

Tech Stack

Layer Technology Description
Backend Python 3.8+ Core language
Backend pymodbus Modbus implementation
Backend FastAPI Web framework
Backend WebSocket Real-time communication
Backend asyncio Async processing
Frontend HTML5/CSS3 Interface structure
Frontend JavaScript Interaction logic
Frontend Bootstrap 5 UI framework
Frontend Chart.js Data visualization

System Layers

1. Modbus Server Layer
  • Modbus protocol communication
  • Device data management
  • Read/write request handling
  • Data validation
2. Data Management Layer
  • Data generation and simulation
  • Cache mechanism
  • State management
  • Data persistence
3. Web Service Layer
  • RESTful API
  • WebSocket service
  • Static resource service
  • Security authentication
4. Frontend Layer
  • Real-time data display
  • Device control interface
  • Status monitoring
  • Data visualization

πŸ“š Development Documentation

Project Structure

modbus-simulator/
β”œβ”€β”€ src/                    # Source code directory
β”‚   β”œβ”€β”€ core/              # Core functionality modules
β”‚   β”‚   β”œβ”€β”€ config.py      # Configuration management
β”‚   β”‚   └── logger.py      # Logging management
β”‚   β”œβ”€β”€ modbus/            # Modbus related modules
β”‚   β”‚   β”œβ”€β”€ modbus_cache.py        # Data caching
β”‚   β”‚   └── modbus_data_generator.py # Data generation
β”‚   β”œβ”€β”€ web/               # Web related modules
β”‚   β”‚   β”œβ”€β”€ modbus_client.py      # Modbus client
β”‚   β”‚   β”œβ”€β”€ routes.py             # Route definitions
β”‚   β”‚   β”œβ”€β”€ tasks.py              # Background tasks
β”‚   β”‚   └── websocket_manager.py  # WebSocket management
β”‚   β”œβ”€β”€ __init__.py        # Package initialization
β”‚   └── main.py            # Main program entry
β”œβ”€β”€ static/                # Static resources
β”‚   β”œβ”€β”€ css/              # CSS style files
β”‚   β”‚   └── style.css     # Main style file
β”‚   └── js/               # JavaScript files
β”‚       └── app.js        # Main script file
β”œβ”€β”€ templates/             # Template files
β”‚   └── index.html        # Main page template
β”œβ”€β”€ logs/                  # Log directory
β”œβ”€β”€ docs/                  # Documentation directory
β”œβ”€β”€ .editorconfig         # Editor configuration
β”œβ”€β”€ .gitignore            # Git ignore file
β”œβ”€β”€ .dockerignore         # Docker ignore file
β”œβ”€β”€ .pre-commit-config.yaml # Pre-commit hooks configuration
β”œβ”€β”€ docker-compose.yml    # Docker compose configuration
β”œβ”€β”€ Dockerfile            # Docker build file
β”œβ”€β”€ LICENSE               # License file
β”œβ”€β”€ mypy.ini             # Type checking configuration
β”œβ”€β”€ pyproject.toml       # Project configuration
β”œβ”€β”€ README.md            # Project documentation (Chinese)
β”œβ”€β”€ README_EN.md         # Project documentation (English)
β”œβ”€β”€ requirements.txt     # Dependencies list
└── uv.lock              # Dependencies lock file

❓ FAQ

Connection Issues

Q: Cannot connect to Modbus server?

  • Check if port 502 is available
  • Verify firewall settings
  • Check network connection
Display Issues

Q: Web interface not showing data?

  • Check WebSocket connection
  • Verify device ID configuration
  • Check browser console
Performance Issues

Q: Data updates not timely?

  • Check device update interval
  • Verify WebSocket connection
  • Check server load

⚠️ Notes

No. Note Description
1 Port Ensure port 502 is available
2 Firewall Check firewall settings
3 Python Ensure correct Python environment
4 Virtual Env Run in virtual environment
5 Logs Check logs regularly
6 Security Pay attention to data security

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘₯ Contributing

We welcome contributions! Please ensure:

  1. Code follows project standards
  2. Add necessary tests
  3. Update documentation
  4. Provide clear commit messages

πŸ“ž Contact

Method Content
Author Your Name
Email your.email@example.com
GitHub prairie-spark-iot
Project modbus-simulator

πŸ™ Acknowledgments

Thanks to all contributors!


If this project helps you, please give it a ⭐️ Star!

About

A powerful Modbus device simulator designed for industrial automation testing, teaching demonstrations, and system integration testing. This project provides a complete solution including Modbus server, Web monitoring interface, and real-time data updates.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages