Repository navigation
Configuration
Brian Rodriguez edited this page Dec 9, 2025
·
2 revisions
Configuration is done via .env file in the project root.
# Serial port for Modbus RTU communication
MODBUS_PORT=COM11 # Windows: COM1, COM2, etc.
# Linux: /dev/ttyUSB0, /dev/ttyS0, etc.
# macOS: /dev/cu.usbserial-*
# Modbus device address (1-247)
MODBUS_SLAVE_ID=1
# Serial communication parameters
MODBUS_BAUDRATE=9600 # Options: 9600, 19200, 38400, 57600, 115200
MODBUS_BYTESIZE=8 # Data bits: 5, 6, 7, 8
MODBUS_PARITY=N # N=None, E=Even, O=Odd
MODBUS_STOPBITS=1 # Stop bits: 1, 1.5, 2
MODBUS_TIMEOUT=1 # Timeout in seconds
# Modbus register addresses
MODBUS_FUNCTION_CODE=4 # 3=Holding, 4=Input registers
MODBUS_REGISTER_TEMP=1 # Temperature register address
MODBUS_REGISTER_HUMIDITY=2 # Humidity register address# SQLite database file path
DATABASE_FILE=src/modbus_sensor_data.db
# Data retention period (0 = keep forever)
DATA_RETENTION_DAYS=0 # 0 = infinite retention
# >0 = delete tables older than N daysNote: Database uses table-per-day partitioning (measurements_YYYYMMDD)
# Web interface host and port
APP_HOST=127.0.0.1 # 0.0.0.0 = all interfaces, 127.0.0.1 = localhost only
APP_PORT=8050 # Default port
# Debug settings
APP_DEBUG=False # Flask debug mode (not used with Waitress)
DEBUG_LOGGING=False # Enable detailed console output
# Localization
TIMEZONE=Europe/Amsterdam # Timezone for timestamp display
DEFAULT_LANGUAGE=EN # Default UI language: NL, EN, DE, FR, or ESProduction Server: Application uses Waitress WSGI server (not Flask dev server)
- 8 worker threads for concurrent requests
- Cross-platform (Windows/Linux/macOS)
- Production-ready with proper error handling
The XY-MD02 sensor typically uses:
- Baudrate: 9600
- Slave ID: 1
- Function Code: 4 (Input Registers)
- Temperature Register: 1
- Humidity Register: 2
- Data format: value * 10 (e.g., 235 = 23.5 degrees)
The application validates configuration on startup:
- Slave ID must be 1-247
- Parity must be N, E, or O
- Timeout must be positive
- Warns on unusual baudrate values
Invalid configuration will prevent startup with clear error message.
To monitor multiple sensors:
- Run separate instances on different ports
- Use different
.envfiles - Configure different MODBUS_SLAVE_ID values
Example:
# Terminal 1 - Sensor 1
PORT=8050 MODBUS_SLAVE_ID=1 python app.py
# Terminal 2 - Sensor 2
PORT=8051 MODBUS_SLAVE_ID=2 python app.py