updated to a html local
This commit is contained in:
172
app.py
172
app.py
@@ -1,4 +1,4 @@
|
||||
#App version 2.8 - Fixed auto-update path detection for case-sensitive file systems
|
||||
#App version 2.9 - Added configuration mode for "notconfig" devices
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
@@ -8,6 +8,9 @@ import stat
|
||||
import pwd
|
||||
import grp
|
||||
|
||||
# Global configuration mode flag
|
||||
CONFIGURATION_MODE = False
|
||||
|
||||
def install_package_from_wheel(wheel_path, package_name):
|
||||
"""
|
||||
Install a Python package from a wheel file
|
||||
@@ -225,6 +228,113 @@ except ImportError as e:
|
||||
|
||||
import json
|
||||
|
||||
# Early configuration mode detection (before heavy initialization)
|
||||
def early_launch_configuration_mode():
|
||||
"""
|
||||
Early launch of configuration mode with chromium displaying Screen.html
|
||||
"""
|
||||
try:
|
||||
print("🔧 Configuration mode detected - launching Screen.html in Chromium")
|
||||
|
||||
# Get absolute path to Screen.html
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
screen_html_path = os.path.join(current_dir, "Files", "Screen.html")
|
||||
|
||||
if not os.path.exists(screen_html_path):
|
||||
print(f"❌ Screen.html not found at: {screen_html_path}")
|
||||
return False
|
||||
|
||||
print(f"📄 Loading Screen.html from: {screen_html_path}")
|
||||
|
||||
# Launch chromium in kiosk mode with the local HTML file
|
||||
chromium_command = [
|
||||
'chromium-browser',
|
||||
'--kiosk',
|
||||
'--no-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-gpu',
|
||||
'--disable-software-rasterizer',
|
||||
'--disable-background-timer-throttling',
|
||||
'--disable-backgrounding-occluded-windows',
|
||||
'--disable-renderer-backgrounding',
|
||||
f'file://{screen_html_path}'
|
||||
]
|
||||
|
||||
print("🚀 Starting Chromium in configuration mode...")
|
||||
process = subprocess.Popen(chromium_command,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL)
|
||||
|
||||
print("✅ Configuration mode launched successfully")
|
||||
print("ℹ️ Network connectivity checks disabled")
|
||||
print("ℹ️ Server status messages disabled")
|
||||
print("🔧 Device running in configuration mode")
|
||||
print("🔧 To exit configuration mode, change idmasa.txt content to device name")
|
||||
|
||||
return True
|
||||
|
||||
except FileNotFoundError:
|
||||
print("❌ Chromium browser not found. Please install chromium-browser:")
|
||||
print(" sudo apt update && sudo apt install chromium-browser")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Error launching configuration mode: {e}")
|
||||
return False
|
||||
|
||||
# EARLY CONFIGURATION MODE DETECTION
|
||||
print("=" * 60)
|
||||
print("CONFIGURATION MODE DETECTION")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
with open("./data/idmasa.txt", "r") as f:
|
||||
name = f.readline().strip() or "noconfig"
|
||||
print(f"✓ Device name loaded: {name}")
|
||||
|
||||
# Check if device is in configuration mode
|
||||
if name.lower() == "notconfig":
|
||||
print("🔧 Device configured for setup mode (notconfig)")
|
||||
|
||||
# Launch configuration mode
|
||||
if early_launch_configuration_mode():
|
||||
print("🚀 Configuration mode active - application will run in setup mode")
|
||||
print("⚠️ Network connectivity checks are DISABLED")
|
||||
print("⚠️ Server status messages are DISABLED")
|
||||
print("🔧 Change idmasa.txt to device name to exit configuration mode")
|
||||
|
||||
# Set global flag for configuration mode
|
||||
CONFIGURATION_MODE = True
|
||||
|
||||
print("🔧 Configuration mode activated - continuing with RFID reader initialization")
|
||||
print("🔧 Network and server monitoring will remain disabled")
|
||||
else:
|
||||
print("❌ Failed to launch configuration mode, continuing with normal operation")
|
||||
CONFIGURATION_MODE = False
|
||||
else:
|
||||
print("✅ Device in normal operation mode")
|
||||
CONFIGURATION_MODE = False
|
||||
|
||||
except FileNotFoundError:
|
||||
print("Warning: idmasa.txt not found, using default 'noconfig'")
|
||||
name = "noconfig"
|
||||
CONFIGURATION_MODE = False
|
||||
# Create the file with default value
|
||||
try:
|
||||
os.makedirs("./data", exist_ok=True)
|
||||
with open("./data/idmasa.txt", "w") as f:
|
||||
f.write("noconfig")
|
||||
print("✓ Created default idmasa.txt file")
|
||||
except Exception as e:
|
||||
print(f"Could not create idmasa.txt: {e}")
|
||||
except Exception as e:
|
||||
print(f"Error reading idmasa.txt: {e}")
|
||||
name = "noconfig"
|
||||
CONFIGURATION_MODE = False
|
||||
|
||||
print("=" * 60)
|
||||
print("CONTINUING WITH NORMAL INITIALIZATION" if not CONFIGURATION_MODE else "CONFIGURATION MODE ACTIVE")
|
||||
print("=" * 60)
|
||||
|
||||
def check_system_requirements():
|
||||
"""
|
||||
Check and set up system requirements for the application
|
||||
@@ -674,7 +784,16 @@ def log_info_with_server(message):
|
||||
n_masa = read_name_from_file() # Read name (idmasa) from the file
|
||||
formatted_message = f"{message} (n_masa: {n_masa})" # Format the message
|
||||
logging.info(formatted_message) # Log the formatted message
|
||||
send_log_to_server(message, n_masa, hostname, device_ip) # Send the original message to the server
|
||||
|
||||
# Only send to server if not in configuration mode
|
||||
try:
|
||||
if not CONFIGURATION_MODE:
|
||||
send_log_to_server(message, n_masa, hostname, device_ip) # Send the original message to the server
|
||||
else:
|
||||
logging.info("Configuration mode: Server logging disabled")
|
||||
except NameError:
|
||||
# CONFIGURATION_MODE not defined yet (during initialization)
|
||||
send_log_to_server(message, n_masa, hostname, device_ip) # Send the original message to the server
|
||||
|
||||
# Function to execute system commands with proper security
|
||||
def execute_system_command(command):
|
||||
@@ -1125,12 +1244,21 @@ def check_internet_connection():
|
||||
log_info_with_server(f"An error occurred during internet check: {e}")
|
||||
time.sleep(60) # Retry after 1 minute in case of an error
|
||||
|
||||
# Start the internet connection check in a separate process
|
||||
internet_check_process = Process(target=check_internet_connection)
|
||||
internet_check_process.start()
|
||||
url = "10.76.140.17/iweb_v2/index.php/traceability/production" # pentru cazul in care raspberiul nu are sistem de prezenta
|
||||
# Launch Chromium with the specified URLs
|
||||
subprocess.Popen(["chromium", "--test-type", "--noerrors", "--kiosk", "--start-fullscreen", "--unsafely-treat-insecure-origin-as-secure=http://10.76.140.17", url], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, start_new_session=True)
|
||||
# Start the internet connection check in a separate process (only if not in configuration mode)
|
||||
if not CONFIGURATION_MODE:
|
||||
internet_check_process = Process(target=check_internet_connection)
|
||||
internet_check_process.start()
|
||||
print("✅ Internet connectivity monitoring started")
|
||||
else:
|
||||
print("🔧 Configuration mode: Internet connectivity monitoring DISABLED")
|
||||
|
||||
# Launch Chromium with the specified URLs (only if not in configuration mode)
|
||||
if not CONFIGURATION_MODE:
|
||||
url = "10.76.140.17/iweb_v2/index.php/traceability/production" # pentru cazul in care raspberiul nu are sistem de prezenta
|
||||
subprocess.Popen(["chromium", "--test-type", "--noerrors", "--kiosk", "--start-fullscreen", "--unsafely-treat-insecure-origin-as-secure=http://10.76.140.17", url], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, start_new_session=True)
|
||||
print("✅ Main application browser launched")
|
||||
else:
|
||||
print("🔧 Configuration mode: Main application browser launch DISABLED")
|
||||
|
||||
info = "0"
|
||||
#function to post info
|
||||
@@ -1217,26 +1345,22 @@ except Exception as e:
|
||||
# Initialize table name/ID
|
||||
print("Initializing device configuration...")
|
||||
name = "idmasa"
|
||||
logging.info("LED controls initialized")
|
||||
|
||||
logging.info("Variabila Id Masa A fost initializata ")
|
||||
|
||||
try:
|
||||
with open("./data/idmasa.txt", "r") as f:
|
||||
name = f.readline().strip() or "noconfig"
|
||||
print(f"✓ Device name loaded: {name}")
|
||||
log_info_with_server(f"Device name initialized: {name}")
|
||||
except FileNotFoundError:
|
||||
print("Warning: idmasa.txt not found, using default 'noconfig'")
|
||||
name = "noconfig"
|
||||
# Create the file with default value
|
||||
# Device name is already loaded during early configuration detection
|
||||
# Use the existing name variable or reload if needed
|
||||
if 'name' not in globals():
|
||||
try:
|
||||
with open("./data/idmasa.txt", "w") as f:
|
||||
f.write("noconfig")
|
||||
print("✓ Created default idmasa.txt file")
|
||||
with open("./data/idmasa.txt", "r") as f:
|
||||
name = f.readline().strip() or "noconfig"
|
||||
print(f"✓ Device name reloaded: {name}")
|
||||
if not CONFIGURATION_MODE:
|
||||
log_info_with_server(f"Device name initialized: {name}")
|
||||
except Exception as e:
|
||||
print(f"Could not create idmasa.txt: {e}")
|
||||
except Exception as e:
|
||||
print(f"Error reading idmasa.txt: {e}")
|
||||
name = "noconfig"
|
||||
print(f"Error reloading device name: {e}")
|
||||
name = "noconfig"
|
||||
|
||||
logging.info(name)
|
||||
#clasa reader
|
||||
|
||||
Reference in New Issue
Block a user