REMOVED: - aiohttp, multidict, aiosignal, frozenlist, attrs, yarl, propcache (Flask async dependencies) - flask, chart (not needed for headless device) - selenium (web automation not needed) KEPT (7 core dependencies only): - rdm6300: RFID reader library - requests: HTTP communication to server - gpiozero: GPIO/system access - urllib3, certifi, charset_normalizer, idna: requests dependencies IMPROVEMENTS: - Skip trying to install wrong-architecture wheels (aarch64) - Let pip download correct ARM32/ARM64 version for device - Much faster startup on resource-constrained Raspberry Pi - Pure Python wheels installed from local repository - Removes 11+ unnecessary packages
157 lines
5.4 KiB
Python
157 lines
5.4 KiB
Python
"""
|
|
Configuration settings for Prezenta Work application
|
|
All server addresses and credentials are managed here
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# Base directories
|
|
BASE_DIR = Path(__file__).parent
|
|
DATA_DIR = BASE_DIR / "data"
|
|
FILES_DIR = BASE_DIR / "Files"
|
|
LOGS_DIR = DATA_DIR
|
|
|
|
# Ensure directories exist
|
|
DATA_DIR.mkdir(exist_ok=True)
|
|
FILES_DIR.mkdir(exist_ok=True)
|
|
LOGS_DIR.mkdir(exist_ok=True)
|
|
|
|
# ============================================================================
|
|
# SERVER CONFIGURATION
|
|
# ============================================================================
|
|
|
|
# Monitoring Server (Server_Monitorizare)
|
|
MONITORING_SERVER_HOST = os.environ.get('MONITORING_SERVER_HOST', '192.168.1.103')
|
|
MONITORING_SERVER_PORT = int(os.environ.get('MONITORING_SERVER_PORT', 80))
|
|
MONITORING_SERVER_URL = f"http://{MONITORING_SERVER_HOST}:{MONITORING_SERVER_PORT}/logs"
|
|
|
|
# Auto-Update Server
|
|
AUTO_UPDATE_SERVER_HOST = os.environ.get('AUTO_UPDATE_SERVER_HOST', '192.168.1.103')
|
|
AUTO_UPDATE_SERVER_USER = os.environ.get('AUTO_UPDATE_SERVER_USER', 'pi')
|
|
AUTO_UPDATE_SERVER_PASSWORD = os.environ.get('AUTO_UPDATE_SERVER_PASSWORD', 'Initial01!')
|
|
AUTO_UPDATE_SERVER_APP_PATH = "/home/pi/Desktop/prezenta/app.py"
|
|
AUTO_UPDATE_SERVER_REPO_PATH = "/home/pi/Desktop/prezenta/Files/reposytory"
|
|
|
|
# Network Connectivity Check
|
|
CONNECTIVITY_CHECK_HOST = os.environ.get('CONNECTIVITY_CHECK_HOST', '192.168.1.103')
|
|
CONNECTIVITY_CHECK_INTERVAL = 2700 # 45 minutes in seconds
|
|
|
|
# ============================================================================
|
|
# LOCAL CONFIGURATION
|
|
# ============================================================================
|
|
|
|
# File paths
|
|
DEVICE_INFO_FILE = DATA_DIR / "device_info.txt"
|
|
ID_MASA_FILE = DATA_DIR / "idmasa.txt"
|
|
TAG_FILE = DATA_DIR / "tag.txt"
|
|
LOG_FILE = LOGS_DIR / "log.txt"
|
|
|
|
# Logging
|
|
LOG_FILENAME = str(LOG_FILE)
|
|
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
|
|
LOG_RETENTION_DAYS = 10
|
|
|
|
# ============================================================================
|
|
# FLASK APPLICATION CONFIGURATION
|
|
# ============================================================================
|
|
|
|
# Try to use FLASK_PORT from environment, default to 80
|
|
FLASK_PORT = int(os.environ.get('FLASK_PORT', 80))
|
|
FLASK_HOST = '0.0.0.0'
|
|
FLASK_DEBUG = False
|
|
FLASK_USE_RELOADER = False
|
|
|
|
# Preferred ports for fallback (in order of preference)
|
|
PREFERRED_PORTS = [
|
|
FLASK_PORT,
|
|
80,
|
|
5000,
|
|
8080,
|
|
3000
|
|
]
|
|
|
|
# ============================================================================
|
|
# REQUEST CONFIGURATION
|
|
# ============================================================================
|
|
|
|
REQUEST_TIMEOUT = 5 # seconds
|
|
UPDATE_TIMEOUT = 30 # seconds for version check
|
|
REPO_SYNC_TIMEOUT = 60 # seconds for repository sync
|
|
|
|
# ============================================================================
|
|
# HARDWARE CONFIGURATION
|
|
# ============================================================================
|
|
|
|
# Serial devices for RFID reader (in order of preference)
|
|
SERIAL_DEVICES = [
|
|
'/dev/ttyS0', # Raspberry Pi default
|
|
'/dev/ttyAMA0', # Alternative Pi UART
|
|
'/dev/ttyUSB0', # USB serial adapter
|
|
'/dev/ttyACM0' # USB CDC ACM device
|
|
]
|
|
|
|
# GPIO devices
|
|
GPIO_DEVICES = ['/dev/gpiomem', '/dev/mem']
|
|
|
|
# ============================================================================
|
|
# SYSTEM CONFIGURATION
|
|
# ============================================================================
|
|
|
|
# Commands allowed to execute via /execute_command endpoint
|
|
ALLOWED_COMMANDS = [
|
|
"sudo apt update",
|
|
"sudo apt upgrade -y",
|
|
"sudo apt autoremove -y",
|
|
"sudo apt autoclean",
|
|
"sudo reboot",
|
|
"sudo shutdown -h now",
|
|
"df -h",
|
|
"free -m",
|
|
"uptime",
|
|
"systemctl status",
|
|
"sudo systemctl restart networking",
|
|
"sudo systemctl restart ssh"
|
|
]
|
|
|
|
# Command execution timeout
|
|
COMMAND_TIMEOUT = 300 # 5 minutes
|
|
|
|
# ============================================================================
|
|
# RFID READER CONFIGURATION
|
|
# ============================================================================
|
|
|
|
# Special card IDs
|
|
CONFIG_CARD_ID = 12886709 # Card used for configuration
|
|
|
|
# ============================================================================
|
|
# DEPENDENCIES
|
|
# ============================================================================
|
|
|
|
# Required Python packages - MINIMAL for headless RFID client
|
|
# Flask and aiohttp dependencies removed since we're now a headless collector
|
|
REQUIRED_PACKAGES = {
|
|
'rdm6300': 'rdm6300-0.1.1-py3-none-any.whl', # RFID reader library
|
|
'requests': 'requests-2.32.3-py3-none-any.whl', # HTTP requests to server
|
|
'gpiozero': None, # GPIO/system interaction (apt package)
|
|
'urllib3': 'urllib3-2.3.0-py3-none-any.whl', # Requests dependency
|
|
'certifi': 'certifi-2025.1.31-py3-none-any.whl', # SSL certificates
|
|
'charset_normalizer': 'charset_normalizer-3.4.1-py3-none-any.whl', # Requests dependency
|
|
'idna': 'idna-3.10-py3-none-any.whl' # Requests dependency
|
|
}
|
|
|
|
REPOSITORY_PATH = FILES_DIR / "reposytory"
|
|
|
|
def load_from_env_file():
|
|
"""Load configuration from .env file if it exists"""
|
|
env_file = BASE_DIR / '.env'
|
|
if env_file.exists():
|
|
try:
|
|
from dotenv import load_dotenv
|
|
load_dotenv(env_file)
|
|
except ImportError:
|
|
print("Warning: python-dotenv not installed, skipping .env file")
|
|
|
|
# Load environment variables at startup
|
|
load_from_env_file()
|