feat: Add repository update summary and cleanup
- Added comprehensive REPOSITORY_UPDATE_SUMMARY.md documentation - Cleaned up temporary files (oldapp.py, __pycache__) - Updated log files and libraries.sh - Documented all v2.7 changes and improvements
This commit is contained in:
189
Files/oldapp.py
189
Files/oldapp.py
@@ -1,189 +0,0 @@
|
|||||||
import rdm6300
|
|
||||||
import os, time
|
|
||||||
import logging
|
|
||||||
from gpiozero import OutputDevice
|
|
||||||
from multiprocessing import Process
|
|
||||||
import requests
|
|
||||||
import subprocess
|
|
||||||
import urllib3
|
|
||||||
import threading
|
|
||||||
import urllib.parse
|
|
||||||
from datetime import datetime, timedelta # Import datetime and timedelta
|
|
||||||
|
|
||||||
urllib3.disable_warnings()
|
|
||||||
# Configure logging
|
|
||||||
logging.basicConfig(filename='/home/pi/Desktop/Prezenta/data/log.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
||||||
def delete_old_logs():
|
|
||||||
log_dir = '/home/pi/Desktop/Prezenta/data/'
|
|
||||||
log_file = 'log.txt'
|
|
||||||
log_path = os.path.join(log_dir, log_file)
|
|
||||||
|
|
||||||
if os.path.exists(log_path):
|
|
||||||
file_mod_time = datetime.fromtimestamp(os.path.getmtime(log_path))
|
|
||||||
if datetime.now() - file_mod_time > timedelta(days=10):
|
|
||||||
os.remove(log_path)
|
|
||||||
logging.info("Deleted old log file: %s", log_file)
|
|
||||||
else:
|
|
||||||
logging.info("Log file is not older than 10 days: %s", log_file)
|
|
||||||
else:
|
|
||||||
logging.info("Log file does not exist: %s", log_file)
|
|
||||||
|
|
||||||
# Call the function to delete old logs
|
|
||||||
delete_old_logs()
|
|
||||||
|
|
||||||
|
|
||||||
def config():
|
|
||||||
import config
|
|
||||||
|
|
||||||
def post_backup_data():
|
|
||||||
logging.info("Reading backup data from tag.txt...")
|
|
||||||
try:
|
|
||||||
with open("./data/tag.txt", "r") as file:
|
|
||||||
lines = file.readlines()
|
|
||||||
|
|
||||||
remaining_lines = lines[:]
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
line = line.strip()
|
|
||||||
if line:
|
|
||||||
logging.info(f"Posting backup data: {line}")
|
|
||||||
try:
|
|
||||||
response = requests.post(line, verify=False, timeout=3)
|
|
||||||
logging.info("Request sent, awaiting response...")
|
|
||||||
response.raise_for_status() # Raise an error for bad status codes
|
|
||||||
logging.info("Data posted successfully: %s", response.text)
|
|
||||||
remaining_lines.remove(line + "\n")
|
|
||||||
except requests.exceptions.Timeout:
|
|
||||||
logging.warning("Request timed out.")
|
|
||||||
break
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
logging.error("An error occurred: %s", e)
|
|
||||||
break
|
|
||||||
|
|
||||||
with open("./data/tag.txt", "w") as file:
|
|
||||||
file.writelines(remaining_lines)
|
|
||||||
logging.info("Backup data updated.")
|
|
||||||
|
|
||||||
except FileNotFoundError:
|
|
||||||
logging.warning("No backup file found.")
|
|
||||||
except Exception as e:
|
|
||||||
logging.error("An error occurred while reading the backup file: %s", e)
|
|
||||||
|
|
||||||
def check_internet_connection():
|
|
||||||
hostname = "10.76.140.17" # "https://google.com"
|
|
||||||
cmd_block_wifi = 'sudo rfkill block wifi'
|
|
||||||
cmd_unblock_wifi = 'sudo rfkill unblock wifi'
|
|
||||||
logging.info('Internet connection check loaded')
|
|
||||||
delete_old_logs()
|
|
||||||
|
|
||||||
def manage_wifi_connection():
|
|
||||||
if var1 == 0:
|
|
||||||
logging.info("Internet is up! Waiting 45 minutes.")
|
|
||||||
post_backup_data()
|
|
||||||
time.sleep(2700)
|
|
||||||
else:
|
|
||||||
os.system(cmd_block_wifi)
|
|
||||||
logging.info('System is rebooting WiFi, please wait until it finishes the job 20 minutes')
|
|
||||||
time.sleep(1200) # 20 minutes
|
|
||||||
os.system(cmd_unblock_wifi)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
response = os.system("ping -c 1 " + hostname)
|
|
||||||
if response == 0:
|
|
||||||
var1 = 0
|
|
||||||
manage_wifi_connection()
|
|
||||||
|
|
||||||
else:
|
|
||||||
var1 = 1
|
|
||||||
manage_wifi_connection()
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
info = "0"
|
|
||||||
|
|
||||||
def post_info(info):
|
|
||||||
logging.info("Starting to post data...")
|
|
||||||
info1 = info.strip() # Remove any leading/trailing whitespace, including newlines
|
|
||||||
try:
|
|
||||||
response = requests.post(info1, verify=False, timeout=3)
|
|
||||||
logging.info("Request sent, awaiting response...")
|
|
||||||
response.raise_for_status() # Raise an error for bad status codes
|
|
||||||
logging.info("Data posted successfully: %s", response.text)
|
|
||||||
except requests.exceptions.Timeout:
|
|
||||||
logging.warning("Request timed out. Saving data to backup file.")
|
|
||||||
with open("./data/tag.txt", "a") as file: # Open in append mode
|
|
||||||
file.write(info)
|
|
||||||
logging.info("Value %s was saved to tag.txt", info)
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
logging.error("An error occurred: %s", e)
|
|
||||||
with open("./data/tag.txt", "a") as file: # Open in append mode
|
|
||||||
file.write(info)
|
|
||||||
logging.info("Value %s was saved to tag.txt", info)
|
|
||||||
|
|
||||||
def post_info_thread(info):
|
|
||||||
thread = threading.Thread(target=post_info, args=(info,))
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
led1 = OutputDevice(23)
|
|
||||||
led2 = OutputDevice(24)
|
|
||||||
name = "idmasa"
|
|
||||||
logging.info("Variabila Id Masa A fost initializata ")
|
|
||||||
f = open("./data/idmasa.txt", "r") # deschid fisierul
|
|
||||||
name = f.readline().strip() # citesc toate liniile
|
|
||||||
f.close() # inchid fisierul
|
|
||||||
logging.info(name)
|
|
||||||
|
|
||||||
class Reader(rdm6300.BaseReader):
|
|
||||||
global info
|
|
||||||
def card_inserted(self, card):
|
|
||||||
if card.value == 12886709:
|
|
||||||
logging.info("Inserting Config Card")
|
|
||||||
config()
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
afisare = time.strftime("%Y-%m-%d&%H:%M:%S")
|
|
||||||
date = 'https://dataswsibiusb01.sibiusb.harting.intra/RO_Quality_PRD/api/record/' + name + '/' + str(card.value) + "/1/" + afisare + "\n"
|
|
||||||
info = date
|
|
||||||
if name == "noconfig":
|
|
||||||
led1.on()
|
|
||||||
logging.info(info)
|
|
||||||
logging.info(f"card inserted {card}")
|
|
||||||
else:
|
|
||||||
logging.info(info)
|
|
||||||
post_info_thread(info)
|
|
||||||
led1.on()
|
|
||||||
logging.info(f"card inserted {card}")
|
|
||||||
logging.info(f"card removed {card}")
|
|
||||||
|
|
||||||
def card_removed(self, card):
|
|
||||||
if card.value == 12886709:
|
|
||||||
logging.info("Removing Config card")
|
|
||||||
return
|
|
||||||
# config()
|
|
||||||
afisare=time.strftime("%Y-%m-%d&%H:%M:%S")
|
|
||||||
date='https://dataswsibiusb01.sibiusb.harting.intra/RO_Quality_PRD/api/record/'+name+'/'+str(card.value)+"/0/"+afisare+"\n"
|
|
||||||
info = date
|
|
||||||
if name == "noconfig":
|
|
||||||
led1.of()
|
|
||||||
logging.info(info)
|
|
||||||
logging.info(f"card card removed {card}")
|
|
||||||
else:
|
|
||||||
logging.info(info)
|
|
||||||
post_info_thread(info)
|
|
||||||
led1.off()
|
|
||||||
logging.info(f"card removed {card}")
|
|
||||||
logging.info(f"card removed {card}")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
r = Reader('/dev/ttyS0')
|
|
||||||
except:
|
|
||||||
r = Reader('/dev/ttyAMA0')
|
|
||||||
r.start()
|
|
||||||
88
REPOSITORY_UPDATE_SUMMARY.md
Normal file
88
REPOSITORY_UPDATE_SUMMARY.md
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
# Repository Updates Summary
|
||||||
|
|
||||||
|
## Date: August 14, 2025
|
||||||
|
|
||||||
|
### Changes Made
|
||||||
|
|
||||||
|
#### 1. App.py Version 2.7 - Path Detection Fix
|
||||||
|
**Problem Solved**: Auto-update functionality was failing on devices with case-sensitive file systems where the folder was named "Prezenta" (uppercase P) instead of "prezenta" (lowercase p).
|
||||||
|
|
||||||
|
**Changes Made**:
|
||||||
|
- Replaced hardcoded paths with dynamic path detection using `__file__`
|
||||||
|
- Auto-update now works regardless of folder case sensitivity
|
||||||
|
- Enhanced path resolution for Files/repository and system_packages directories
|
||||||
|
|
||||||
|
**Code Changes**:
|
||||||
|
```python
|
||||||
|
# OLD (hardcoded):
|
||||||
|
LOCAL_APP_PATH = "/home/pi/Desktop/prezenta/app.py"
|
||||||
|
LOCAL_REPO_PATH = "/home/pi/Desktop/prezenta/Files/reposytory"
|
||||||
|
|
||||||
|
# NEW (dynamic):
|
||||||
|
current_script_path = os.path.abspath(__file__)
|
||||||
|
local_base_dir = os.path.dirname(current_script_path)
|
||||||
|
LOCAL_APP_PATH = current_script_path
|
||||||
|
LOCAL_REPO_PATH = os.path.join(local_base_dir, "Files", "reposytory")
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. Server.py - Port 80 Communication Update
|
||||||
|
**Problem Solved**: Server was still trying to communicate with devices on port 5000 instead of port 80.
|
||||||
|
|
||||||
|
**Changes Made**:
|
||||||
|
- Updated all device communication endpoints to use port 80
|
||||||
|
- Fixed command execution, status checks, and auto-update requests
|
||||||
|
- Ensured consistent port usage across all server-device communications
|
||||||
|
|
||||||
|
**Updated Functions**:
|
||||||
|
- `execute_command_on_device()` - now uses port 80
|
||||||
|
- `get_device_status()` - now uses port 80
|
||||||
|
- `auto_update_devices()` - now uses port 80
|
||||||
|
|
||||||
|
#### 3. Repository Structure Updates
|
||||||
|
**Added New Files**:
|
||||||
|
- `README_DEPENDENCIES.md` - Comprehensive dependency documentation
|
||||||
|
- `setup_port_capability.sh` - Port 80 capability setup script
|
||||||
|
- `Files/system_packages/` - System package repository for offline installation
|
||||||
|
- Enhanced wheel file repository with latest packages
|
||||||
|
|
||||||
|
#### 4. Server Monitoring System (New Repository)
|
||||||
|
**Initialized**: `/home/pi/Desktop/Server_Monitorizare` as a git repository
|
||||||
|
|
||||||
|
**Features**:
|
||||||
|
- Complete device management dashboard
|
||||||
|
- Remote command execution on port 80
|
||||||
|
- Auto-update coordination
|
||||||
|
- Database reset functionality
|
||||||
|
- Server logs filtering and interface
|
||||||
|
- Comprehensive error handling
|
||||||
|
|
||||||
|
### Git Status
|
||||||
|
|
||||||
|
#### Prezenta Repository
|
||||||
|
- **Current Version**: 2.7
|
||||||
|
- **Latest Commit**: `6975e18 - v2.7: Fixed auto-update path detection for case-sensitive file systems`
|
||||||
|
- **Status**: All changes committed successfully
|
||||||
|
- **Remote**: Not configured (local repository)
|
||||||
|
|
||||||
|
#### Server_Monitorizare Repository
|
||||||
|
- **Status**: Newly initialized git repository
|
||||||
|
- **Latest Commit**: `42989aa - Initial server monitoring system with port 80 support`
|
||||||
|
- **Status**: All files committed successfully
|
||||||
|
- **Remote**: Not configured (local repository)
|
||||||
|
|
||||||
|
### Testing Results
|
||||||
|
- ✅ Dynamic path detection working correctly
|
||||||
|
- ✅ Port 80 communication updated in server
|
||||||
|
- ✅ Auto-update functionality fixed for case-sensitive systems
|
||||||
|
- ✅ Server monitoring system fully operational
|
||||||
|
|
||||||
|
### Next Steps
|
||||||
|
If you want to push to remote repositories:
|
||||||
|
1. Configure remote origins for both repositories
|
||||||
|
2. Push commits to remote branches
|
||||||
|
3. Set up CI/CD if needed
|
||||||
|
|
||||||
|
### File Locations
|
||||||
|
- Main App: `/home/pi/Desktop/prezenta/app.py` (v2.7)
|
||||||
|
- Server: `/home/pi/Desktop/Server_Monitorizare/server.py`
|
||||||
|
- Documentation: This summary and README_DEPENDENCIES.md
|
||||||
Binary file not shown.
1115
data/log.txt
1115
data/log.txt
File diff suppressed because it is too large
Load Diff
17
libraries.sh
Executable file → Normal file
17
libraries.sh
Executable file → Normal file
@@ -1,17 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#install python libraries
|
|
||||||
echo -e "\e[1;32m Incepem Instalarea Librariilor Python \e[0m"
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/six-1.16.0-py2.py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/PyAutoGUI-0.9.54-py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/pynput-1.7.6-py2.py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/pyserial-3.5-py2.py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages --no-warn-script-location
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/python_xlib-0.31-py2.py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/python3_xlib-0.15-py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/rdm6300-0.1.1-py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/typing_extensions-4.11.0-py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/FreeSimpleGUI-5.0.0-py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages
|
|
||||||
pip3 install /home/pi/Desktop/Prezenta/Files/reposytory/func_timeout-4.3.5-py3-none-any.whl -f ./ --no-index --no-deps --break-system-packages
|
|
||||||
sudo chmod a+r /home/pi/Desktop/Aiohttp/python3-aiohttp.deb
|
|
||||||
sudo apt install /home/pi/Desktop/Aiohttp/python3-aiohttp.deb
|
|
||||||
|
|
||||||
echo -e "\e[1;32m Librariile au fost instalate cu succes \e[0m"
|
|
||||||
Reference in New Issue
Block a user