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 @@ + + + + Your image title + + + + + 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(': Failed to establish a new connection: [Errno 111] Connection refused')) -2025-08-14 11:42:43,879 - INFO - Internet connection check loaded (n_masa: 2_15051100_10) -2025-08-14 11:42:43,886 - ERROR - Failed to send log to server: HTTPConnectionPool(host='rpi-ansible', port=80): Max retries exceeded with url: /logs (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) -2025-08-14 11:42:43,888 - INFO - Log file is not older than 10 days: log.txt (n_masa: 2_15051100_10) -2025-08-14 11:42:43,889 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. - * Running on all addresses (0.0.0.0) - * Running on http://127.0.0.1:80 - * Running on http://192.168.1.237:80 -2025-08-14 11:42:43,890 - INFO - Press CTRL+C to quit -2025-08-14 11:42:43,899 - INFO - 127.0.0.1 - - [14/Aug/2025 11:42:43] "POST /logs HTTP/1.1" 404 - -2025-08-14 11:42:43,900 - INFO - Variabila Id Masa A fost initializata -2025-08-14 11:42:43,900 - INFO - 2_15051100_10 -2025-08-14 11:42:43,902 - ERROR - Failed to send log to server: 404 Client Error: NOT FOUND for url: http://rpi-ansible:80/logs -2025-08-14 11:42:53,906 - INFO - Internet is down. Rebooting WiFi. (n_masa: 2_15051100_10) -2025-08-14 11:42:53,909 - INFO - 127.0.0.1 - - [14/Aug/2025 11:42:53] "POST /logs HTTP/1.1" 404 - -2025-08-14 11:42:53,910 - ERROR - Failed to send log to server: 404 Client Error: NOT FOUND for url: http://rpi-ansible:80/logs -2025-08-14 15:46:13,021 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. +2025-09-24 16:23:15,376 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:5000 - * Running on http://192.168.1.237:5000 -2025-08-14 15:46:13,022 - INFO - Press CTRL+C to quit -2025-08-14 15:46:15,010 - INFO - Log file is not older than 10 days: log.txt (n_masa: 2_15051100_10) -2025-08-14 15:46:15,036 - INFO - Log successfully sent to server: Log file is not older than 10 days: log.txt -2025-08-14 15:46:15,040 - INFO - Internet connection check loaded (n_masa: 2_15051100_10) -2025-08-14 15:46:15,071 - INFO - LED controls initialized (n_masa: 2_15051100_10) -2025-08-14 15:46:15,078 - INFO - Log successfully sent to server: Internet connection check loaded -2025-08-14 15:46:15,079 - INFO - Log file is not older than 10 days: log.txt (n_masa: 2_15051100_10) -2025-08-14 15:46:15,104 - INFO - Log successfully sent to server: LED controls initialized -2025-08-14 15:46:15,104 - INFO - Variabila Id Masa A fost initializata -2025-08-14 15:46:15,106 - INFO - Device name initialized: 2_15051100_10 (n_masa: 2_15051100_10) -2025-08-14 15:46:15,120 - INFO - Log successfully sent to server: Log file is not older than 10 days: log.txt -2025-08-14 15:46:15,144 - INFO - Log successfully sent to server: Device name initialized: 2_15051100_10 -2025-08-14 15:46:15,145 - INFO - 2_15051100_10 -2025-08-14 15:46:25,126 - INFO - Internet is down. Rebooting WiFi. (n_masa: 2_15051100_10) -2025-08-14 15:46:25,148 - INFO - Log successfully sent to server: Internet is down. Rebooting WiFi. + * Running on http://10.89.219.105:5000 +2025-09-24 16:23:15,376 - INFO - Press CTRL+C to quit +2025-09-24 16:23:17,363 - INFO - Log file is not older than 10 days: log.txt (n_masa: 2_15051100_10) +2025-09-24 16:23:17,399 - INFO - Log successfully sent to server: Log file is not older than 10 days: log.txt +2025-09-24 16:23:17,405 - INFO - Internet connection check loaded (n_masa: 2_15051100_10) +2025-09-24 16:23:17,442 - INFO - LED controls initialized (n_masa: 2_15051100_10) +2025-09-24 16:23:17,448 - INFO - Log successfully sent to server: Internet connection check loaded +2025-09-24 16:23:17,449 - INFO - Log file is not older than 10 days: log.txt (n_masa: 2_15051100_10) +2025-09-24 16:23:17,467 - INFO - Log successfully sent to server: LED controls initialized +2025-09-24 16:23:17,467 - INFO - LED controls initialized +2025-09-24 16:23:17,467 - INFO - Variabila Id Masa A fost initializata +2025-09-24 16:23:17,469 - INFO - idmasa +2025-09-24 16:23:17,487 - INFO - Log successfully sent to server: Log file is not older than 10 days: log.txt +2025-09-24 16:23:27,499 - INFO - Internet is down. Rebooting WiFi. (n_masa: 2_15051100_10) +2025-09-24 16:23:27,525 - INFO - Log successfully sent to server: Internet is down. Rebooting WiFi. +2025-09-24 16:26:42,776 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:5000 + * Running on http://10.89.219.105:5000 +2025-09-24 16:26:42,777 - INFO - Press CTRL+C to quit +2025-09-24 16:26:44,758 - INFO - Log file is not older than 10 days: log.txt (n_masa: notconfig) +2025-09-24 16:26:44,759 - INFO - Configuration mode: Server logging disabled +2025-09-24 16:26:44,793 - INFO - LED controls initialized (n_masa: notconfig) +2025-09-24 16:26:44,793 - INFO - Configuration mode: Server logging disabled +2025-09-24 16:26:44,794 - INFO - LED controls initialized +2025-09-24 16:26:44,794 - INFO - Variabila Id Masa A fost initializata +2025-09-24 16:26:44,799 - INFO - idmasa diff --git a/data/tag.txt b/data/tag.txt index 5c79a10..e69de29 100644 --- a/data/tag.txt +++ b/data/tag.txt @@ -1,2 +0,0 @@ -https://dataswsibiusb01.sibiusb.harting.intra/RO_Quality_PRD/api/record/notconfig/7955261/1/2025-05-28&16:37:20 -https://dataswsibiusb01.sibiusb.harting.intra/RO_Quality_PRD/api/record/notconfig/7955261/0/2025-05-28&16:37:29