Last Code Revision Date: 03-Sep-2025
This project logs Modbus TCP/IP device data into daily CSV files for historical storage and analysis. It uses pymodbus
for Modbus communication and is designed for reliability and ease of use.
Package | Version | Description |
---|---|---|
pymodbus | 3.11.1 | Modbus protocol implementation |
DD-MM-YYYY HH:MM:SS
for easy sorting and readabilityMODBUS_SLAVE_ID
in config)src/config.py
logs/<Year>/<Month>/<DD-MM-YYYY>.csv
modbus-csv-datalogger-03092025
├── src
│ ├── main.py # Main application logic
│ ├── modbus_client.py # Modbus TCP client wrapper
│ └── config.py # User configuration for Modbus/interval
├── requirements.txt # Python dependencies
├── README.md # Project documentation
git clone <repository-url>
cd modbus-csv-datalogger-03092025
pip install -r requirements.txt
Edit src/config.py
to set:
MODBUS_SLAVE_ID
) to target a specific deviceCSV_BASE_PATH
) for log storageExample (src/config.py
):
MODBUS_SERVER = '127.0.0.1'
MODBUS_PORT = 502
MODBUS_SLAVE_ID = 1 # Modbus slave ID to read from
MODBUS_READ_CONFIG = {
"holding_registers": {
"addresses": [0, 1, 2, 5, 6, 7]
}
}
UPDATE_INTERVAL = 5 # seconds
CSV_BASE_PATH = "logs"
To enable other data types (coils, discrete inputs, input registers), uncomment and configure them in MODBUS_READ_CONFIG
.
Start the datalogger:
python src/main.py
MODBUS_READ_CONFIG
as needed).main.py
for details on logging, reconnect logic, and interval handling.34.03$