updated to a html local

This commit is contained in:
2025-09-24 16:29:19 +03:00
parent db53ee6f99
commit 140ae25231
7 changed files with 186 additions and 61 deletions

9
Files/Screen.html Executable file
View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Your image title</title>
</head>
<body>
<img src="myimage.png" style="width:100%;height:100%;" alt="" />
</body>
</html>

BIN
Files/myimage.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 KiB

BIN
Files/myimage.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 794 KiB

164
app.py
View File

@@ -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 os
import sys import sys
import subprocess import subprocess
@@ -8,6 +8,9 @@ import stat
import pwd import pwd
import grp import grp
# Global configuration mode flag
CONFIGURATION_MODE = False
def install_package_from_wheel(wheel_path, package_name): def install_package_from_wheel(wheel_path, package_name):
""" """
Install a Python package from a wheel file Install a Python package from a wheel file
@@ -225,6 +228,113 @@ except ImportError as e:
import json 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(): def check_system_requirements():
""" """
Check and set up system requirements for the application Check and set up system requirements for the application
@@ -674,6 +784,15 @@ def log_info_with_server(message):
n_masa = read_name_from_file() # Read name (idmasa) from the file n_masa = read_name_from_file() # Read name (idmasa) from the file
formatted_message = f"{message} (n_masa: {n_masa})" # Format the message formatted_message = f"{message} (n_masa: {n_masa})" # Format the message
logging.info(formatted_message) # Log the formatted message logging.info(formatted_message) # Log the formatted message
# 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 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 # Function to execute system commands with proper security
@@ -1125,12 +1244,21 @@ def check_internet_connection():
log_info_with_server(f"An error occurred during internet check: {e}") log_info_with_server(f"An error occurred during internet check: {e}")
time.sleep(60) # Retry after 1 minute in case of an error time.sleep(60) # Retry after 1 minute in case of an error
# Start the internet connection check in a separate process # Start the internet connection check in a separate process (only if not in configuration mode)
internet_check_process = Process(target=check_internet_connection) if not CONFIGURATION_MODE:
internet_check_process.start() internet_check_process = Process(target=check_internet_connection)
url = "10.76.140.17/iweb_v2/index.php/traceability/production" # pentru cazul in care raspberiul nu are sistem de prezenta internet_check_process.start()
# Launch Chromium with the specified URLs print("✅ Internet connectivity monitoring started")
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) 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" info = "0"
#function to post info #function to post info
@@ -1217,25 +1345,21 @@ except Exception as e:
# Initialize table name/ID # Initialize table name/ID
print("Initializing device configuration...") print("Initializing device configuration...")
name = "idmasa" name = "idmasa"
logging.info("LED controls initialized")
logging.info("Variabila Id Masa A fost initializata ") logging.info("Variabila Id Masa A fost initializata ")
try: # 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", "r") as f: with open("./data/idmasa.txt", "r") as f:
name = f.readline().strip() or "noconfig" name = f.readline().strip() or "noconfig"
print(f"✓ Device name loaded: {name}") print(f"✓ Device name reloaded: {name}")
if not CONFIGURATION_MODE:
log_info_with_server(f"Device name initialized: {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
try:
with open("./data/idmasa.txt", "w") as f:
f.write("noconfig")
print("✓ Created default idmasa.txt file")
except Exception as e: except Exception as e:
print(f"Could not create idmasa.txt: {e}") print(f"Error reloading device name: {e}")
except Exception as e:
print(f"Error reading idmasa.txt: {e}")
name = "noconfig" name = "noconfig"
logging.info(name) logging.info(name)

View File

@@ -1 +1 @@
noconfig notconfig

View File

@@ -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-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.
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('<urllib3.connection.HTTPConnection object at 0xf5f1c5d0>: 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('<urllib3.connection.HTTPConnection object at 0xf5f24370>: 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.
* Running on all addresses (0.0.0.0) * Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5000 * Running on http://127.0.0.1:5000
* Running on http://192.168.1.237:5000 * Running on http://10.89.219.105:5000
2025-08-14 15:46:13,022 - INFO - Press CTRL+C to quit 2025-09-24 16:23:15,376 - 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-09-24 16:23:17,363 - 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-09-24 16:23:17,399 - 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-09-24 16:23:17,405 - 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-09-24 16:23:17,442 - 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-09-24 16:23:17,448 - 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-09-24 16:23:17,449 - 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-09-24 16:23:17,467 - INFO - Log successfully sent to server: LED controls initialized
2025-08-14 15:46:15,104 - INFO - Variabila Id Masa A fost initializata 2025-09-24 16:23:17,467 - INFO - LED controls initialized
2025-08-14 15:46:15,106 - INFO - Device name initialized: 2_15051100_10 (n_masa: 2_15051100_10) 2025-09-24 16:23:17,467 - INFO - Variabila Id Masa A fost initializata
2025-08-14 15:46:15,120 - INFO - Log successfully sent to server: Log file is not older than 10 days: log.txt 2025-09-24 16:23:17,469 - INFO - idmasa
2025-08-14 15:46:15,144 - INFO - Log successfully sent to server: Device name initialized: 2_15051100_10 2025-09-24 16:23:17,487 - INFO - Log successfully sent to server: Log file is not older than 10 days: log.txt
2025-08-14 15:46:15,145 - INFO - 2_15051100_10 2025-09-24 16:23:27,499 - INFO - Internet is down. Rebooting WiFi. (n_masa: 2_15051100_10)
2025-08-14 15:46:25,126 - 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-08-14 15:46:25,148 - 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

View File

@@ -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