Update configuration: Change server addresses from rpi-ansible to 192.168.1.103 (local PC)

This commit is contained in:
Developer
2025-12-18 11:40:07 +02:00
parent 68f377e2b5
commit 651818f424

164
config_settings.py Normal file
View File

@@ -0,0 +1,164 @@
"""
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 and their wheel files
REQUIRED_PACKAGES = {
'rdm6300': 'rdm6300-0.1.1-py3-none-any.whl',
'gpiozero': None, # System package
'requests': 'requests-2.32.3-py3-none-any.whl',
'aiohttp': 'aiohttp-3.11.18-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl',
'flask': None, # Will try pip install if needed
'urllib3': 'urllib3-2.3.0-py3-none-any.whl',
'certifi': 'certifi-2025.1.31-py3-none-any.whl',
'charset_normalizer': 'charset_normalizer-3.4.1-py3-none-any.whl',
'idna': 'idna-3.10-py3-none-any.whl',
'multidict': 'multidict-6.4.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl',
'aiosignal': 'aiosignal-1.3.2-py2.py3-none-any.whl',
'frozenlist': 'frozenlist-1.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl',
'attrs': 'attrs-25.3.0-py3-none-any.whl',
'yarl': 'yarl-1.20.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl',
'aiohappyeyeballs': 'aiohappyeyeballs-2.6.1-py3-none-any.whl',
'propcache': 'propcache-0.3.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl'
}
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()