Last Code Revision Date: 02-Sep-2025
This project logs Modbus TCP/IP device data into an SQLite database for historical storage and analysis. It uses pymodbus
for Modbus communication and Python’s built-in sqlite3
for database operations.
Package | Version | Description |
---|---|---|
pymodbus | 3.11.1 | Modbus protocol implementation |
sqlite3 | builtin | SQLite database for Python |
src/config.py
modbus-sqlite-datalogger-02092025
├── src
│ ├── main.py # Main application logic
│ ├── modbus_client.py # Modbus TCP client wrapper
│ ├── sqlite_logger.py # SQLite logger for Modbus data
│ ├── modbus_data.db # SQLite database file (created at runtime)
│ └── config.py # User configuration for Modbus/database/interval
├── requirements.txt # Python dependencies
├── README.md # Project documentation
git clone <repository-url>
cd modbus-sqlite-datalogger-02092025
powershell or CMD
pip install -r requirements.txt
Edit src/config.py
to set:
Example (src/config.py
):
SQLITE_DB_NAME = 'modbus_data.db'
MODBUS_SERVER = '127.0.0.1'
MODBUS_PORT = 502
MODBUS_SLAVE_ID = 1
MODBUS_READ_CONFIG = {
"holding_registers": {
"addresses": [0, 1, 2, 5, 6, 7]
}
# "coils": {"addresses": [0, 1, 2]},
# "discrete_inputs": {"addresses": [0, 1, 2]},
# "input_registers": {"addresses": [0, 1, 2]},
}
UPDATE_INTERVAL = 5 # seconds
To enable other data types (coils, discrete inputs, input registers), uncomment and configure them in MODBUS_READ_CONFIG
.
Start the datalogger:
powershell or CMD
python src/main.py
modbus_data.db
database.MODBUS_READ_CONFIG
as needed).34.03$