diff --git a/Files/Screen.html b/Files/Screen.html new file mode 100755 index 0000000..8a0d35a --- /dev/null +++ b/Files/Screen.html @@ -0,0 +1,9 @@ + + +
+
+
+
diff --git a/Files/myimage.jpg b/Files/myimage.jpg
new file mode 100755
index 0000000..cf64bf7
Binary files /dev/null and b/Files/myimage.jpg differ
diff --git a/Files/myimage.png b/Files/myimage.png
new file mode 100755
index 0000000..edbf8a0
Binary files /dev/null and b/Files/myimage.png differ
diff --git a/app.py b/app.py
index e0f0f84..03d51f1 100644
--- a/app.py
+++ b/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
diff --git a/data/idmasa.txt b/data/idmasa.txt
index 1f481bf..a247338 100644
--- a/data/idmasa.txt
+++ b/data/idmasa.txt
@@ -1 +1 @@
-noconfig
\ No newline at end of file
+notconfig
diff --git a/data/log.txt b/data/log.txt
index 697dc86..743e7d9 100644
--- a/data/log.txt
+++ b/data/log.txt
@@ -1,36 +1,30 @@
-2025-08-14 11:42:43,861 - INFO - Log file is not older than 10 days: log.txt (n_masa: 2_15051100_10)
-2025-08-14 11:42:43,871 - ERROR - Failed to send log to server: HTTPConnectionPool(host='rpi-ansible', port=80): Max retries exceeded with url: /logs (Caused by NewConnectionError('