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.
| 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 | π³ |
π 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
| Requirement | Description |
|---|---|
| Python | 3.8+ |
| OS | Windows/Linux/MacOS |
| Network | TCP/IP support |
| Memory | 2GB+ recommended |
| Storage | 1GB+ recommended |
| Docker | Optional, for containerized deployment |
- Clone the repository
git clone https://github.com/prairie-spark-iot/modbus-simulator.git
cd modbus-simulator- Create virtual environment
# Windows
python -m venv .venv
.venv\Scripts\activate
# Linux/MacOS
python -m venv .venv
source .venv/bin/activate- Install dependencies
pip install -r requirements.txt- Run the project
python -m src.main- Clone the repository
git clone https://github.com/prairie-spark-iot/modbus-simulator.git
cd modbus-simulator- 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- Check container status
docker-compose ps
# or
docker ps- View logs
docker-compose logs -f
# or
docker logs -f modbus-simulator- Stop service
docker-compose down
# or
docker stop modbus-simulator| 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 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 | π |
| 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 |
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
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
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
| 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 |
This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions! Please ensure:
- Code follows project standards
- Add necessary tests
- Update documentation
- Provide clear commit messages
| Method | Content |
|---|---|
| Author | Your Name |
| your.email@example.com | |
| GitHub | prairie-spark-iot |
| Project | modbus-simulator |
Thanks to all contributors!
If this project helps you, please give it a βοΈ Star!