From 7682472bd55a9d948f40046cba4647d8d76c11c9 Mon Sep 17 00:00:00 2001 From: ske087 Date: Fri, 28 Feb 2025 09:09:38 +0200 Subject: [PATCH] start from 0 --- app.py | 151 ---------------------------- cert.sh | 28 ------ config.py | 271 --------------------------------------------------- idmasa.txt | 1 - libraries.sh | 14 --- tag.txt | Bin 1024 -> 0 bytes 6 files changed, 465 deletions(-) delete mode 100644 app.py delete mode 100644 cert.sh delete mode 100644 config.py delete mode 100644 idmasa.txt delete mode 100644 libraries.sh delete mode 100644 tag.txt diff --git a/app.py b/app.py deleted file mode 100644 index 6acc844..0000000 --- a/app.py +++ /dev/null @@ -1,151 +0,0 @@ -import rdm6300 -import os, time -from gpiozero import OutputDevice -from multiprocessing import Process -import requests -import subprocess -import urllib3 -import threading -import urllib.parse -urllib3.disable_warnings() - -def config(): - import config - -def post_backup_data(): - print("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: - print(f"Posting backup data: {line}") - try: - response = requests.post(line, verify=False, timeout=3) - print("Request sent, awaiting response...") - response.raise_for_status() # Raise an error for bad status codes - print("Data posted successfully:", response.text) - remaining_lines.remove(line + "\n") - except requests.exceptions.Timeout: - print("Request timed out.") - break - except requests.exceptions.RequestException as e: - print("An error occurred:", e) - break - - with open("./data/tag.txt", "w") as file: - file.writelines(remaining_lines) - print("Backup data updated.") - - except FileNotFoundError: - print("No backup file found.") - except Exception as e: - print(f"An error occurred while reading the backup file: {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' - print('Internet connection check loaded') - - def manage_wifi_connection(): - if var1 == 0: - print("Internet is up! Whaiting 45 minutes.") - post_backup_data() - time.sleep(2700) - else: - os.system(cmd_block_wifi) - print('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): - print("Starting to post data...") - info1 = info.strip() # Remove any leading/trailing whitespace, including newlines - try: - response = requests.post(info1, verify=False, timeout=3) - print("Request sent, awaiting response...") - response.raise_for_status() # Raise an error for bad status codes - print("Data posted successfully:", response.text) - except requests.exceptions.Timeout: - print("Request timed out. Saving data to backup file.") - with open("./data/tag.txt", "a") as file: # Open in append mode - file.write(info) - print("Value", info, "was saved to tag.txt") - except requests.exceptions.RequestException as e: - print("An error occurred:", e) - with open("./data/tag.txt", "a") as file: # Open in append mode - file.write(info) - print("Value", info, "was saved to tag.txt") - -def post_info_thread(info): - thread = threading.Thread(target=post_info, args=(info,)) - thread.start() - - -led1 = OutputDevice(23) -led2 = OutputDevice(24) -name = "Ionut" -print(name) -f = open("./data/idmasa.txt", "r") # deschid fisierul -name = f.readline().strip() # citesc toate liniile -f.close() # inchid fisierul -print(name) - -class Reader(rdm6300.BaseReader): - global info - def card_inserted(self, card): - if card.value == 12886709: - print("Inserting 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) + "/1/" + afisare + "\n" - info = date - print(info) - post_info_thread(info) - led1.on() - print(f"card inserted {card}") - - def card_removed(self, card): - if card.value == 12886709: - print("Remouving 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 - print(info) - post_info_thread(info) - led1.off() - print("Card remove") - - -try: - r = Reader('/dev/ttyS0') -except: - r = Reader('/dev/ttyAMA0') -r.start() diff --git a/cert.sh b/cert.sh deleted file mode 100644 index eafede4..0000000 --- a/cert.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# Instalare certificate -echo -e "\e[1;32m Copiem si instalam certificatele Harting \e[0m" -sudo mkdir /usr/local/share/ca-certificates/Harting -sudo cp -R /home/pi/Desktop/Prezenta/Files/reposytory/Harting/ /usr/local/share/ca-certificates/Harting/ - -sudo update-ca-certificates -sleep 3 -echo -e "\e[1;32m Instalam Libnss3-tool ca sa actualizam certificatele in Browser \e[0m" -sudo apt install libnss3-tools -echo -e "\e[1;32m Libnss3-tools este instalat \e[0m" -echo -e "\e[1;32m Cream baza de date pentru certutil \e[0m" -#sudo mkdir -p $HOME/.pki/nssdb -#sudo certutil -d $HOME/.pki/nssdb -N --empty-password -echo -e "\e[1;32m Baza de date a fost creata \e[0m" -echo -e "\e[1;32m Actualizam Certificate \e[0m" -certutil -d sql:$HOME/.pki/nssdb -A -t "CT,C,C" -n HA_MWG_new_cert -i /etc/ssl/certs/HA_MWG_new_cert.pem -echo "cert 1 ok" -sleep 3 -certutil -d sql:$HOME/.pki/nssdb -A -t "CT,C,C" -n HartingIssuingCA1.pem -i /etc/ssl/certs/HartingIssuingCA1.pem -echo "cert 2 Ok" -sleep 3 -certutil -d sql:$HOME/.pki/nssdb -A -t "CT,C,C" -n HartingRootCA.pem -i /etc/ssl/certs/HartingRootCA.pem -echo "cert 3 ok" -echo -e "\e[1;32m Certificatele au fost instalate \e[0m" -sleep 3 -certutil -d sql:$HOME/.pki/nssdb -L -sleep 3 \ No newline at end of file diff --git a/config.py b/config.py deleted file mode 100644 index 7e9078a..0000000 --- a/config.py +++ /dev/null @@ -1,271 +0,0 @@ -# config py este gandit pentru a verifica configurarile raspberiului -# verifica hostname-ul si il afiseaza -# verifica ce nume are masa si o afiseaza -# verifica daca masa este configurata cu sistem de prezenta operator -# verifica daca imprimanta este instalata corespunzator - -import os, time, socket, cups, subprocess -import FreeSimpleGUI as psg -import FreeSimpleGUI as sg -from multiprocessing import Process - - - -# import socket -host = socket.gethostname() # luam numele de host -def set_printer(): # importam codul python pentru printer - print("Cheking printer") - # acest segment acceseaza fisierul local idmas.txt si verifica ce informatii sunt acolo - # in mod normal acolo salvam numele mesei care trebuie sa corespunda cu numele imprimantei - f = open("/home/pi/Desktop/Prezenta/Files/idmasa.txt","r") # deschid fisierul in care am salvat numele printerului - test = f.readlines() # citesc toate liniile - f.close() - # in cazul in care avem fisier corupt il resetam la original - try: - idmasa = test[0] - - except IndexError: - idmasa = "0" - print(idmasa) - # citim lista de printere disponibila - conn = cups.Connection () - printers = conn.getPrinters () - printer_stat=0 - for printer in printers: - print (printer, printers[printer]["device-uri"]) - if printer == idmasa: - printer_stat = 1 - - - if printer_stat == 1: - print("Printer is Ok") - else: - print("Printer is not ok") - p_Name = idmasa - print("Installing the new printer") - time.sleep(2) - cmd = "sudo /usr/sbin/lpadmin -p "+idmasa+" -E -v usb://CITIZEN/CT-S310II?serial=00000000 -m CTS310II.ppd" - os.popen(cmd) - time.sleep(2) - print("Printer Was Installed") - conn = cups.Connection() - printers = conn.getPrinters() - for printer in printers: - print(printer, printers[printer]["device-uri"]) - time.sleep(1) - print("Printerwas seted to "+idmasa+"") - print("Test printer App Closed") -# partea acesata se ocupa de verificarea existentei celor doua fisiere pentru a nu avea erori -# verificam daca exista fisierul care identifica masa -path = '/home/pi/Desktop/Prezenta/Files/idmasa.txt' -isFile = os.path.isfile(path) #verifica existenta fisierului prin bolean Tru/false - -if not isFile: -# print(path)# nu se face nimic pentru ca exista fisierul -#else: - fp = open('/home/pi/Desktop/Prezenta/Files/idmasa.txt', 'w') # cream fisier - fp.write('Initial') # scriem in fisier prima line pentru a avea un punct de pornire - fp.close() # inchidem fisierul -# print("created file") -# verificam fisierul de prezenta pe baza acestuia stim daca locul de munca este configurat cu card de prezenta sau nu -path1 = '/home/pi/Desktop/Prezenta/Files/prezenta.txt' #verificare existenta al doilea fisier -isFile = os.path.isfile(path1)# verifica existenta fisierului -#print(path) - -if not isFile: -# print(path1)#nu se face nimic -#else: - fp = open('/home/pi/Desktop/Prezenta/Files/prezenta.txt', 'w')# daca nu exista cream fisierul - fp.write("0")# scriem in fisier 0 default pentru Prezenta masa nu exista - fp.close() #Inchidem fisierul -# print("created file") -# se termina partea de verificare a fisierelor - - -#urmeaza sa citim fisierele pentru a crea cateva variabile -# prima variabila este idmasa -f = open("/home/pi/Desktop/Prezenta/Files/idmasa.txt","r") # deschid fisierul -name = f.readlines() # citesc toate liniile -f.close() # inchid fisierul -try: - idmasa = name[0]# se verifica daca exista informatie in text - -except IndexError: - idmasa = "Initial"# daca nu exista informatie in text setam variabila - -# avem o prima variabila idmasa care ne va ajuta sa identificam postul de lucru - -# urmeaza sa verificam ce-a de a doua variabila -#cea care ne zice daca este configurat slotul pentru prezenta card -f = open("/home/pi/Desktop/Prezenta/Files/prezenta.txt","r") # deschid fisierul -test = f.readlines() # citesc toate liniile -f.close() - -try: - prezenta = test[0] - -except IndexError: - prezenta = "0" -# avem statusul petntru slotul de card numita prezenta -#aceasta variabila poate sa fie 0 ( absent) sau 1 (prezent) - -#incepem sa definim primele functii din configurare -def notokfunction(): # este functie pentru butonul cancel din formular - -# f = open("/home/pi/Desktop/Prezenta/Files/idmasa.txt","w") # deschidem fisierul idmasa si scriem ce am citit -# L = idmasa -# f.write(L) -# f.close() - msg1 = "Id masa a fost actualizat la: "+ idmasa +"" ## pregatim mesajul pentru fereastra pop up -# f=open("/home/pi/Desktop/Prezenta/Files/prezenta.txt","w") -# L1 = prezenta -# f.write(L1) -# f.close() - msg2 = "Slotul Pentru cartela este configurat by default" # pregatim mesajul pentru fereastra pop up - layout = [[sg.Text(msg1)], [sg.Text(msg2)], [sg.Button("Ok")]] - window = sg.Window("Configurari", layout) - while True: - event, values = window.read() - # End program if user closes window or - # presses the OK button - if event == "Ok" or event == sg.WIN_CLOSED: - - break - - window.close() -#am inchis functia notok - -#functia pentru butonul ok din formular -def okfunction(): - if idmasa == config1: # variabila config 1 este preluata din formular - msg1 = "Masa este setat corect: "+ idmasa +"" # se printeaza mesaj ca nu se actualizeaza id de masa - # print(msg1) - else: - f = open("/home/pi/Desktop/Prezenta/Files/idmasa.txt","w") # deschidem fisierul config in mod scriere - L = config1 - f.write(L) # actualizam linia cu noua valuare din config - f.close() # inchidem fisierul - msg1 = "Id masa a fost actualizat la: "+ config1 +"" # pregatim mesajul pentru fereastra pop up - -# print(msg1) - if prezenta == config2: # verificam cea de a doua variabila - if config2 == "0": # daca e zero trimitem mesaj ca slotul e configurat ca absent - msg2 = "Slotul Pentru cartela este configurat ca absent" # pregatim mesajul pentru fereastra pop up - else: # daca e 1 trimitem mesaj ca slotul e configurat ca prezent - msg2 = "Slotul pentru cartela este configurat ca prezent" # pregatim mesajul pentru fereastra pop up - - else: # daca variabila perzenta nu e egala cu config 2 - f=open("/home/pi/Desktop/Prezenta/Files/prezenta.txt","w") # deschidem fisierul prezenta si scriem noua informatie - L1 = config2 - f.write(L1) # infrrmatia este luata din form - f.close() - if config2 == "0": # daca e 0 trimitem mesaj ca e 0 - msg2 = "Slotul Pentru cartela este configurat ca absent" # mesaj ca e absent slotul pentru cartela - else: - msg2 = "Slotul pentru cartela este configurat ca prezent" # mesaj ca e prezent slotul de cartela - - # definim fereastra pentru ok asemena cu functia notok - layout = [[sg.Text(msg1)], [sg.Text(msg2)],[sg.Output(size=(40, 15))], [sg.Button("Ok")]] - - window = sg.Window("Configurari", layout) - while True: - event, values = window.read() - # End program if user closes window or - # presses the OK button - if event == "Ok" or event == sg.WIN_CLOSED: - - break - if nook == 1: - notokfunction() - time.sleep(2) - #asteptam 10 secunde si pornim functia de setare printer - set_printer() - #verificam daca hostul corespunde cu ce este in formular - time.sleep(2) - if host == host_conf: - print("Host name ok") - else: - print("Host name not ok") - time.sleep(2) - print("Update Hostname" ) - cmd = "sudo hostnamectl set-hostname "+host_conf+"" # comanda sa schimbam hostnameul - os.popen(cmd) - print("Os hostname updated") - time.sleep(2) - print("System will reboot in 5 seconds") - time.sleep(1) - print("System will reboot in 4 seconds") - time.sleep(1) - print("System will reboot in 3 seconds") - time.sleep(1) - print("System will reboot in 2 seconds") - time.sleep(1) - print("System will reboot in 1 seconds") - time.sleep(3) - - - - window.close() -# incepem initializarea feresteri ptrincipale gui - -sg.theme('dark grey 9') #alegem tema dark grey -psg.set_options(font=('Arial Bold', 16)) # setam fontul -#setarile de layout -layout = [ - [sg.Text('Host_Name', size=(20,1)),sg.InputText(default_text= ""+host+"" , enable_events=False)], - [sg.Text('Loc De Munca', size=(20,1)),sg.InputText(default_text=""+idmasa+"", enable_events=False)], - [psg.Text('Card Prezenta(0 nu, 1 da)', size=(20,1)), sg.Radio(" 0","press", key="0", size=(4, 0)), - sg.Radio(" 1", "press", key="1",size=(4, 0))], - [psg.Text('Se trece 0 in cazul in care nu exista slot de cartela si 1 in cazul in care slotul exista', size=(70,1), font=('Arial Bold', 12))], - [sg.Button('Ok'), sg.Button('Cancel')] -] -# setam window -window = psg.Window('Form', layout, size=(800,190),finalize=True) -# citim si configuram widgetul pentru butoanele 1 si 0 din randul -for key in ("0", "1"): - window[key].widget.configure(indicatoron=False) -while True: - nook = 0 # cream o variabila care sa ne spuna daca a fost setao butonul ok sau nu - event, values = window.read() # citim valorile intr-o lista numita values - host_conf= values[0] # atribuim primul item din lista variabilei Host config - # aceasta variabila o vom folosi pentru a scrie sa nu noul hostname - print(host_conf) - if event == sg.WIN_CLOSED or event == 'Cancel': - nook = 1 # daca se da cancel setam variabila nook la 1 - break - config1 = values[1] # atribuim lui config 1 valuarea din campul Loc de munca care a fost scris cu Id masa - config2 = prezenta # ramane egal cu prezenta - if values['0'] == True: # verificam valorile pentru 1 sau 0 - config2 = "0" # daca e bifat 0 scriem 0 in variabila config - - if values['1'] == True: - config2 = "1" # daca e bifat 1 scriem 1 in fisierul config - # pornim functi care scrie valorile config in fisiere ok function - okfunction() -# si inchidem formularul - - # semnalam ca s-a terminat afisarea formularului - break - - -#inchidem formularul -window.close() -# daca variabila nook este 1 -time.sleep(2) -os.system("sudo reboot now") - - - - - - - - - - - - - - - - diff --git a/idmasa.txt b/idmasa.txt deleted file mode 100644 index ca69680..0000000 --- a/idmasa.txt +++ /dev/null @@ -1 +0,0 @@ -41710031_EC \ No newline at end of file diff --git a/libraries.sh b/libraries.sh deleted file mode 100644 index 8f02d17..0000000 --- a/libraries.sh +++ /dev/null @@ -1,14 +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 -echo -e "\e[1;32m Librariile au fost instalate cu succes \e[0m" \ No newline at end of file diff --git a/tag.txt b/tag.txt deleted file mode 100644 index 06d7405020018ddf3cacee90fd4af10487da3d20..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 ScmZQz7zLvtFd70QH3R?z00031