Compare commits
94 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d1e9467395 | |||
| 5f952faad7 | |||
| c6f3f7a50a | |||
| d449d60e09 | |||
| 3caeebcffa | |||
| 1288b3f119 | |||
| 8323373e78 | |||
| b19c153466 | |||
| d97eb23b5e | |||
| fd1a74986e | |||
| 6cfc850276 | |||
| a7c3312574 | |||
| 802c748e56 | |||
| 727c03ac7f | |||
| 0835f942ee | |||
| aeab49bbc7 | |||
| db5bb9f2e1 | |||
| 8b1d297068 | |||
| 7387c51631 | |||
| 2198f01425 | |||
| 1f31183e8d | |||
| 4752bf6fcf | |||
| cb914a4f56 | |||
| 328a5fe540 | |||
| 1c1344ea63 | |||
| d09977f17a | |||
| 7eaf82a248 | |||
| 6bb6e8b4f9 | |||
| 66fd0f417c | |||
| 69540243d4 | |||
| 4b6d7b415c | |||
| c859db736f | |||
| b8c24f8458 | |||
| 40f50c27c2 | |||
| eddc8af40b | |||
| 63f5a41628 | |||
| 3d1f8eaf7b | |||
| 29d6fb7917 | |||
| 683370a8c0 | |||
| a1db884838 | |||
| b5a20dca80 | |||
| 08eeacebde | |||
| fb653f2f67 | |||
| 7b99b448d5 | |||
| 5d9d7a76e7 | |||
| d94cf7d08b | |||
| 4e9857a5eb | |||
| 0bbcd78de3 | |||
| f0772e9111 | |||
| dc3a155975 | |||
| af9b889be5 | |||
| 1ab052a489 | |||
| 372f93de45 | |||
| e98621e524 | |||
| bf2291c399 | |||
| e9acec7774 | |||
| a663dabaca | |||
| 5b1a6235a7 | |||
| 71557f9336 | |||
| 0015d54f60 | |||
| 01926cca84 | |||
| 08893d7954 | |||
| 77a8602d40 | |||
| 31ecb827f2 | |||
| 6fedee77b2 | |||
| 14f48e4d5c | |||
| 42fa3db8be | |||
| 93eb3977a0 | |||
| f53fc4c53f | |||
| 0327246395 | |||
| 762b4f70ed | |||
| 55f40679b5 | |||
| 3b55637cd7 | |||
| 6b4ca6bd6c | |||
| 1620ba43d5 | |||
| 5fed4d1ef2 | |||
| f7cff6e969 | |||
| e124ebfd97 | |||
| e94c621b96 | |||
| 872f66eee4 | |||
| 1924809d0f | |||
| deca006214 | |||
| 9eb16e3e65 | |||
| 06e5d6ceb2 | |||
| 4ecc3070cc | |||
| 75e142f607 | |||
| f52348912a | |||
| 632a17a62c | |||
| 7ad9cf43ab | |||
| 9b74406d23 | |||
| 81ee1dacd6 | |||
| 90e3efb5cc | |||
| 79f217f250 | |||
| 6e27d14e7e |
@@ -0,0 +1,72 @@
|
||||
[id]
|
||||
idxMacchina = 0001
|
||||
#idxMacchina = SIMUL_01
|
||||
#numParams=8
|
||||
numParams=12
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.218/MP/RIOC/api/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/RIOC/api/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/RIOC/api/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.218/MP/IOC/api/IOB/sendReboot/
|
||||
URLINFO = http://10.74.82.218/MP/RIOC/api/IOB/setM2IOB/
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.10
|
||||
TIMEOUTSHORT = 0.50
|
||||
TIMEOUTLONG = 80
|
||||
SENDURLTIME = 0.10
|
||||
NMAXSEND = 5
|
||||
|
||||
[log]
|
||||
LOGLEVEL = 10
|
||||
LOGFILE = logfile.txt
|
||||
LOGREBO = logReboot.txt
|
||||
|
||||
[comm]
|
||||
port = /dev/ttyAMA0
|
||||
|
||||
[blink]
|
||||
MAX_COUNTER_BLINK = 30
|
||||
bit0 = 0
|
||||
bit1 = 0
|
||||
bit2 = 0
|
||||
bit3 = 0
|
||||
bit4 = 0
|
||||
bit5 = 0
|
||||
bit6 = 0
|
||||
bit7 = 0
|
||||
bit8 = 0
|
||||
bit9 = 0
|
||||
bit10 = 0
|
||||
bit11 = 0
|
||||
|
||||
[invert]
|
||||
bit0 = 0
|
||||
bit1 = 0
|
||||
bit2 = 0
|
||||
bit3 = 0
|
||||
bit4 = 0
|
||||
bit5 = 0
|
||||
bit6 = 0
|
||||
bit7 = 0
|
||||
bit8 = 0
|
||||
bit9 = 0
|
||||
bit10 = 0
|
||||
bit11 = 0
|
||||
|
||||
[filter]
|
||||
MAX_COUNTER_FILTER = 8
|
||||
bit0 = 0
|
||||
bit1 = 0
|
||||
bit2 = 0
|
||||
bit3 = 0
|
||||
bit4 = 0
|
||||
bit5 = 0
|
||||
bit6 = 0
|
||||
bit7 = 0
|
||||
bit8 = 0
|
||||
bit9 = 0
|
||||
bit10 = 0
|
||||
bit11 = 0
|
||||
+92
-1
@@ -1,3 +1,94 @@
|
||||
# Upgrade sw IOB-PI clienti
|
||||
|
||||
ATTENZIONE: se si copia dalla versione standard, SUL PI VA DATO un dos2unix * x tutti i files..
|
||||
ATTENZIONE: se si copia dalla versione standard, SUL PI VA DATO un dos2unix * x tutti i files..
|
||||
|
||||
## Salt install##
|
||||
|
||||
Se il minion è taggato come iop-pi bast dare state apply, poiché dallo stato top.sls è configurato di fare gli stati
|
||||
* iob-pi.sls
|
||||
* iob-setup.sls
|
||||
|
||||
altrimenti meglio dare
|
||||
* iob-pi-install
|
||||
* iob-pi-upgrade
|
||||
|
||||
va poi controllato il numero di inputs e va specificato all'inizio del file IOB.cfg a seconda che abbia 8 o 12 inputs
|
||||
|
||||
<code>
|
||||
#numParams=8
|
||||
|
||||
numParams=12
|
||||
</code>
|
||||
|
||||
|
||||
## Approfondimenti
|
||||
|
||||
Valutato python-rq x gestione code con redis tramite esecuzione workers python gestiti in autonomia:
|
||||
|
||||
<code>
|
||||
https://python-rq.org/
|
||||
|
||||
https://python-rq.org/docs/workers/
|
||||
</code>
|
||||
|
||||
Testato ma al momento non è rispondente ai requisiti del programma per cui si rischia un blocco inf ase di invio se server non OK, per ora implementata copia "manuale" della coda verso redis per salvaguardare dati accumulati (vers 2.6.x)
|
||||
|
||||
|
||||
## MD5 zip##
|
||||
|
||||
creazione MD5: da powershell
|
||||
|
||||
<code>
|
||||
Get-FileHash .\Mapo.zip -Algorithm MD5
|
||||
</code>
|
||||
|
||||
|
||||
## ReadParallela IOB-PI
|
||||
|
||||
### Panoramica
|
||||
`readParallela.py` è uno script di acquisizione dati ad alta frequenza progettato per Raspberry Pi. Interfaccia una scheda GPIO personalizzata per leggere 12 ingressi digitali paralleli, applica vari filtri di elaborazione del segnale e mette in coda gli eventi per la trasmissione asincrona a un server remoto tramite Redis e HTTP.
|
||||
|
||||
### Funzionalità Principali
|
||||
|
||||
#### 1. Acquisizione e Elaborazione Segnali
|
||||
Lo script interroga 12 pin GPIO a un intervallo configurabile (`SAMPLETIME`). Per ogni ingresso, applica una pipeline di elaborazione a tre stadi:
|
||||
* **Inversione:** Inverte la logica del segnale se configurata per un bit specifico.
|
||||
* **Filtraggio Segnali Brevi (Debounce):** Filtra i picchi elettrici o il rumore richiedendo che il segnale rimanga stabile per un numero specifico di cicli (`MAX_COUNTER_FILTER`).
|
||||
* **Gestione Blinking:** Rileva e gestisce segnali "blinking", permettendo il rilevamento di eventi basati su timing specifici.
|
||||
|
||||
#### 2. Impacchettamento Dati
|
||||
Una volta elaborati, i 12 bit vengono aggregati in un unico valore intero e convertiti in una stringa Esadecimale.
|
||||
|
||||
#### 3. Code e Trasmissione Eventi
|
||||
Per garantire che la lettura ad alta velocità non sia interrotta dalla latenza di rete:
|
||||
* **Coda Redis:** Le variazioni rilevate (e gli eventi di timeout) vengono datate e inserite in una lista Redis (`IOB`).
|
||||
* **Invio Asincrono:** Un thread dedicato in background (`svuotaCoda`) estrae periodicamente gli elementi dalla coda Redis e esegue richieste HTTP a un server centrale.
|
||||
* **Affidabilità:** Lo script implementa un meccanismo di "retry" e monitora la disponibilità del server (`URLALIVE`) per gestire i periodi offline.
|
||||
|
||||
#### 4. Gestione Timeout
|
||||
Lo script monitora due tipi di timeout:
|
||||
* **Timeout Breve:** Assicura che lo stato di un segnale venga registrato anche se cambia rapidamente.
|
||||
* **Timeout Lungo:** Fornisce un sistema di fallback per garantire la coerenza dello stato su periodi più lunghi.
|
||||
|
||||
### Dettagli di Implementazione (Versione Refactored)
|
||||
Lo script è stato modernizzato con i seguenti miglioramenti:
|
||||
* **Design Orientato agli Oggetti:** La logica è incapsulata all'interno della classe `ReadParallelaIOB`, eliminando la dipendenza da variabili globali pericolose.
|
||||
* **Operazioni Bitwise Efficienti:** Sostituzione dei controlli manuali `if` con operatori bitwise per una ricostruzione dei bit più veloce e ottimizzazione dell'accesso agli attributi nelle loop critiche.
|
||||
* **Networking Moderno:** Sostituzione di `urllib` con la libreria `requests` per una comunicazione HTTP più robusta e leggibile.
|
||||
* **Configurazione Ottimizzata:** Utilizzo di cicli per caricare le impostazioni per singolo bit dal file di configurazione.
|
||||
|
||||
### Configurazione
|
||||
Le impostazioni sono gestite tramite `IOB.cfg`, tra cui:
|
||||
* `[time]`: Frequenze di campionamento e timeout.
|
||||
* `[id]`: Identificativo macchina.
|
||||
* `[web]`: URL per la trasmissione dati e controlli di connettività.
|
||||
* `[blink]`, `[invert]`, `[filter]`: Configurazione per singolo bit per l'elaborazione dei segnali.
|
||||
* `[log]`: Livello di logging e percorsi dei file.
|
||||
|
||||
### Dipendenze
|
||||
* `RPi.GPIO`: Per l'interfacciamento hardware.
|
||||
* `redis`: Per la gestione della coda locale.
|
||||
* `requests`: Per la comunicazione web.
|
||||
* `configparser`: Per la gestione della configurazione.
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,248 @@
|
||||
#!/bin/bash
|
||||
|
||||
# script per update IOB-PI (filre readParallela) secondo la tipologia del raspberry tra 8 e 12 ingressi
|
||||
|
||||
revNum=`awk '/^Revision/ {sub("^1000", "", $3); print $3}' /proc/cpuinfo`
|
||||
anno=2000
|
||||
model='na'
|
||||
ram=0
|
||||
|
||||
# decodifica da questa tabella: https://elinux.org/RPi_HardwareHistory e https://ozzmaker.com/check-raspberry-software-hardware-version-command-line
|
||||
case $revNum in
|
||||
|
||||
0002 | 0003 | 0004 | 0005 | 0006)
|
||||
anno='2012'
|
||||
model='B'
|
||||
ram=256
|
||||
;;
|
||||
|
||||
0007 | 0008 | 0009)
|
||||
anno='2013'
|
||||
model='A'
|
||||
ram=256
|
||||
;;
|
||||
|
||||
000d | 000e | 000f)
|
||||
anno='2012'
|
||||
model='B'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0010)
|
||||
anno='2014'
|
||||
model='B+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0011)
|
||||
anno='2014'
|
||||
model='CM1'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0012)
|
||||
anno='2014'
|
||||
model='A+'
|
||||
ram=256
|
||||
;;
|
||||
|
||||
0013)
|
||||
anno='2015'
|
||||
model='B+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0014)
|
||||
anno='2014'
|
||||
model='CM1'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0015)
|
||||
anno='2014'
|
||||
model='A+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
a01040 | a01041 | a21042)
|
||||
anno='2015'
|
||||
model='2 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a22042)
|
||||
anno='2016'
|
||||
model='2 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
900021)
|
||||
anno='2016'
|
||||
model='A+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
900032)
|
||||
anno='2016'
|
||||
model='B+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
900092)
|
||||
anno='2015'
|
||||
model='Zero'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
900093 | 920093)
|
||||
anno='2016'
|
||||
model='Zero'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
9000c1)
|
||||
anno='2017'
|
||||
model='Zero W'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
a02082 | a22082 | a22082 | a32082)
|
||||
anno='2016'
|
||||
model='3 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a020a0)
|
||||
anno='2017'
|
||||
model='CM3'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a020d3)
|
||||
anno='2018'
|
||||
model='3 Model B+'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
9020e0)
|
||||
anno='2018'
|
||||
model='3 Model A+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
a02100)
|
||||
anno='2019'
|
||||
model='CM3'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a03111)
|
||||
anno='2019'
|
||||
model='4 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
b03111 | b03112)
|
||||
anno='2019'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
b03114)
|
||||
anno='2020'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
b03115)
|
||||
anno='2022'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
c03111 | c03112)
|
||||
anno='2019'
|
||||
model='4 Model B'
|
||||
ram=4096
|
||||
;;
|
||||
|
||||
c03114)
|
||||
anno='2020'
|
||||
model='4 Model B'
|
||||
ram=4096
|
||||
;;
|
||||
|
||||
c03115)
|
||||
anno='2022'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
d03114)
|
||||
anno='2020'
|
||||
model='4 Model B'
|
||||
ram=8192
|
||||
;;
|
||||
|
||||
d03115)
|
||||
anno='2022'
|
||||
model='4 Model B'
|
||||
ram=8192
|
||||
;;
|
||||
|
||||
|
||||
902120)
|
||||
anno='2021'
|
||||
model='Zero 2 W'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
*)
|
||||
anno='2000'
|
||||
model='Unknown'
|
||||
ram=128
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "RPI $anno | model $model | RAM $ram"
|
||||
echo "Revisione: $revNum"
|
||||
|
||||
# default a 8 IN...
|
||||
selIn=8
|
||||
# verifico anno/ram, se almeno 2014 e 1gb --> 12 bit...
|
||||
if [ $anno -gt 2015 ] && [ $ram -gt 512 ]; then
|
||||
selIn=12
|
||||
fi
|
||||
|
||||
echo "Scelta versione $selIn ingressi"
|
||||
|
||||
|
||||
# fermo esecuzione...
|
||||
/etc/init.d/MapoIOB stop
|
||||
echo "Arrestato servizio..."
|
||||
|
||||
# mv file readParallela.py corrente...
|
||||
mv readParallela.py readParallela_$(date -d "today" +"%Y%m%d").py
|
||||
|
||||
# secondo tipo copio il file corretto
|
||||
if [ $selIn -eq 8 ]; then
|
||||
cp -f readParallela_8.py readParallela.py
|
||||
else
|
||||
cp -f readParallela_12.py readParallela.py
|
||||
fi
|
||||
|
||||
# fix permessi
|
||||
chown pi: *
|
||||
chmod +x readP*
|
||||
|
||||
# riavvio esecuzione...
|
||||
/etc/init.d/MapoIOB restart
|
||||
echo "Modifiche effettuate..."
|
||||
|
||||
echo "Attenzione: verificare effettiva partenza servizio, per farlo digitare il comando"
|
||||
echo "/etc/init.d/MapoIOB restart"
|
||||
echo "--------------------------------"
|
||||
echo "In particolare il file IOB.cfg deve contenere NMAXSEND = 5 nella sezione [time]"
|
||||
echo "--------------------------------"
|
||||
echo "Inoltre verificare presenza sezioni [blink] [invert] [filter]"
|
||||
echo "--------------------------------"
|
||||
@@ -0,0 +1,287 @@
|
||||
#!/bin/bash
|
||||
|
||||
# script per update IOB-PI (file readParallela) secondo la tipologia del raspberry tra 8 e 12 ingressi
|
||||
|
||||
revNum=`awk '/^Revision/ {sub("^1000", "", $3); print $3}' /proc/cpuinfo`
|
||||
anno=2000
|
||||
model='na'
|
||||
ram=0
|
||||
|
||||
# decodifica da questa tabella: https://elinux.org/RPi_HardwareHistory e https://ozzmaker.com/check-raspberry-software-hardware-version-command-line
|
||||
case $revNum in
|
||||
|
||||
0002 | 0003 | 0004 | 0005 | 0006)
|
||||
anno='2012'
|
||||
model='B'
|
||||
ram=256
|
||||
;;
|
||||
|
||||
0007 | 0008 | 0009)
|
||||
anno='2013'
|
||||
model='A'
|
||||
ram=256
|
||||
;;
|
||||
|
||||
000d | 000e | 000f)
|
||||
anno='2012'
|
||||
model='B'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0010)
|
||||
anno='2014'
|
||||
model='B+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0011)
|
||||
anno='2014'
|
||||
model='CM1'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0012)
|
||||
anno='2014'
|
||||
model='A+'
|
||||
ram=256
|
||||
;;
|
||||
|
||||
0013)
|
||||
anno='2015'
|
||||
model='B+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0014)
|
||||
anno='2014'
|
||||
model='CM1'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0015)
|
||||
anno='2014'
|
||||
model='A+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
a01040 | a01041 | a21042)
|
||||
anno='2015'
|
||||
model='2 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a22042)
|
||||
anno='2016'
|
||||
model='2 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
900021)
|
||||
anno='2016'
|
||||
model='A+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
900032)
|
||||
anno='2016'
|
||||
model='B+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
900092)
|
||||
anno='2015'
|
||||
model='Zero'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
900093 | 920093)
|
||||
anno='2016'
|
||||
model='Zero'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
9000c1)
|
||||
anno='2017'
|
||||
model='Zero W'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
a02082 | a22082 | a22082 | a32082)
|
||||
anno='2016'
|
||||
model='3 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a020a0)
|
||||
anno='2017'
|
||||
model='CM3'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a020d3)
|
||||
anno='2018'
|
||||
model='3 Model B+'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
9020e0)
|
||||
anno='2018'
|
||||
model='3 Model A+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
a02100)
|
||||
anno='2019'
|
||||
model='CM3'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a03111)
|
||||
anno='2019'
|
||||
model='4 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
b03111 | b03112)
|
||||
anno='2019'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
b03114)
|
||||
anno='2020'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
b03115)
|
||||
anno='2022'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
c03111 | c03112)
|
||||
anno='2019'
|
||||
model='4 Model B'
|
||||
ram=4096
|
||||
;;
|
||||
|
||||
c03114)
|
||||
anno='2020'
|
||||
model='4 Model B'
|
||||
ram=4096
|
||||
;;
|
||||
|
||||
c03115)
|
||||
anno='2022'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
d03114)
|
||||
anno='2020'
|
||||
model='4 Model B'
|
||||
ram=8192
|
||||
;;
|
||||
|
||||
d03115)
|
||||
anno='2022'
|
||||
model='4 Model B'
|
||||
ram=8192
|
||||
;;
|
||||
|
||||
|
||||
902120)
|
||||
anno='2021'
|
||||
model='Zero 2 W'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
*)
|
||||
anno='2000'
|
||||
model='Unknown'
|
||||
ram=128
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "RPI $anno | model $model | RAM $ram"
|
||||
echo "Revisione: $revNum"
|
||||
|
||||
# default a 8 IN...
|
||||
selIn=8
|
||||
# verifico anno/ram, se almeno 2014 e 1gb --> 12 bit...
|
||||
if [ $anno -gt 2015 ] && [ $ram -gt 512 ]; then
|
||||
selIn=12
|
||||
fi
|
||||
|
||||
echo "Scelta versione $selIn ingressi"
|
||||
|
||||
|
||||
# fermo esecuzione...
|
||||
#/etc/init.d/MapoIOB stop
|
||||
systemctl stop MapoIOB
|
||||
echo "Arrestato servizio..."
|
||||
|
||||
#fix permessi
|
||||
chown pi:pi . -R
|
||||
|
||||
# mv file readParallela.py corrente...
|
||||
mv readParallela.py readParallela_$(date -d "today" +"%Y%m%d").py
|
||||
|
||||
# secondo tipo copio il file corretto
|
||||
if [ $selIn -eq 8 ]; then
|
||||
cp -f readParallela_8.py readParallela.py
|
||||
else
|
||||
cp -f readParallela_12.py readParallela.py
|
||||
fi
|
||||
|
||||
# fix permessi
|
||||
chown pi:pi . -R
|
||||
chmod +x readP*
|
||||
|
||||
# conf redis
|
||||
|
||||
# aggiunta passwd accesso se mancante
|
||||
file="/etc/redis/redis.conf"
|
||||
line="24068Seriate"
|
||||
|
||||
# Check if the line is missing
|
||||
if grep -q "$line" "$file"; then
|
||||
echo "requirepass ok!"
|
||||
else
|
||||
# execute the sed command
|
||||
echo "rquirepass missing! adding"
|
||||
sed -i '/#requirepass*/a\requirepass 24068Seriate' $file
|
||||
fi
|
||||
|
||||
|
||||
# aggiunta criterio save da num changes
|
||||
line="save 3600 1 600 10"
|
||||
if grep -q "$line" "$file"; then
|
||||
echo "save rdb OK"
|
||||
else
|
||||
# execute the sed command
|
||||
echo "save rdb not found: adding!"
|
||||
sed -i '/# save 3600*/a\save 3600 1 600 10 300 100 60 10000' $file
|
||||
fi
|
||||
|
||||
# riportare bind a solo localhost
|
||||
sed -i '/#bind 127.0.0.1*/c\bind 127.0.0.1 -::1' $file
|
||||
# rimozione bind a rete globale x test
|
||||
sed -i '/bind 0.0.0.0/c\#bind 0.0.0.0' $file
|
||||
|
||||
#riavvio redis
|
||||
systemctl restart redis
|
||||
|
||||
# riavvio esecuzione...
|
||||
systemctl restart MapoIOB
|
||||
echo "Modifiche effettuate..."
|
||||
|
||||
echo "Attenzione: verificare effettiva partenza servizio, per farlo digitare il comando"
|
||||
echo "/etc/init.d/MapoIOB restart"
|
||||
echo "--------------------------------"
|
||||
echo "In particolare il file IOB.cfg deve contenere NMAXSEND = 5 nella sezione [time]"
|
||||
echo "--------------------------------"
|
||||
echo "Inoltre verificare presenza sezioni [blink] [invert] [filter]"
|
||||
echo "------------------"
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
50249a64efeef80bad924f3f6351edbc
|
||||
@@ -1,8 +1,8 @@
|
||||
#! /bin/bash
|
||||
### BEGIN INIT INFO
|
||||
# Provides: MapoIOB: script Steamware per avvio driver IOB
|
||||
# Required-Start: $remote_fs $syslog ramlog
|
||||
# Required-Stop: $remote_fs $syslog ramlog
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Steamware's MapoIOB driver
|
||||
+3
-1
@@ -8,13 +8,15 @@ Conflicts=shutdown.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
Restart=no
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
TimeoutSec=5min
|
||||
IgnoreSIGPIPE=no
|
||||
KillMode=process
|
||||
GuessMainPID=no
|
||||
RemainAfterExit=yes
|
||||
SysVStartPriority=1
|
||||
ExecStartPre=/bin/sleep 5
|
||||
ExecStart=/etc/init.d/MapoIOB start
|
||||
ExecStop=/etc/init.d/MapoIOB stop
|
||||
|
||||
+37
-24
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# readParallela v. 2.5.1
|
||||
# readParallela v. 2.5.2 12 Ingressi
|
||||
# - single instance timer
|
||||
# - invio multiplo x send eventi accodati
|
||||
# - gestione segnali BLINKING
|
||||
@@ -12,6 +12,7 @@
|
||||
# - (2.4.8) versione adatta a raspberry PI vecchia generazione (GPIO corto, 8bit)
|
||||
# - (2.5) Fix (hope) ciclo "wait send to complete", gestione timeout (rety infinito se IO riparte in modo anomalo)
|
||||
# - (2.5.1) Fix numero versione 18.05.2023
|
||||
# - (2.5.2) Fix gestione eccezioni con report dettagliato
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# levare locking
|
||||
@@ -46,7 +47,7 @@ MAXRETRY = 10
|
||||
# numero campioni filtraggio segnale ballerino
|
||||
MAX_COUNTER_BLINK = 10
|
||||
|
||||
PROGRAM_NAME ="ReadPar IOB-pi v.2.5.1"
|
||||
PROGRAM_NAME ="ReadPar IOB-pi v.2.5.2"
|
||||
|
||||
# DA FILE CONF
|
||||
idxMacchina = "1001"
|
||||
@@ -214,7 +215,7 @@ def readParallelaFiltrata():
|
||||
|
||||
#ciclo per ogni segnale
|
||||
for i in xrange(12) :
|
||||
# print (i)
|
||||
#print (i)
|
||||
|
||||
# v2.1 gestione inversione bit ingresso
|
||||
|
||||
@@ -339,7 +340,9 @@ def readParallelaFiltrata():
|
||||
|
||||
current = hex( new_value ).replace ( "0x" , "" ).upper()
|
||||
|
||||
except:
|
||||
except Exception as e:
|
||||
print "Errore in readParallelaFiltrata \n\n"
|
||||
print str(e)
|
||||
pass
|
||||
|
||||
return current
|
||||
@@ -355,10 +358,9 @@ def accoda():
|
||||
|
||||
except Queue.Full:
|
||||
logPro.error( "Queue full" + `dtEve` + '#' + `value` + '#' + `cont` )
|
||||
except:
|
||||
except Exception as e:
|
||||
logPro.error( "NETWORK:Errore http-no com rete-timeout" + url )
|
||||
#print "Url aforte" , url
|
||||
|
||||
logPro.error(str(e))
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# svuotaCoda x invio dati al server
|
||||
@@ -450,16 +452,17 @@ def svuota_coda():
|
||||
sending = '0'
|
||||
to_retry = MAXRETRY
|
||||
logPro.info("END WAIT, reset to_retry var")
|
||||
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
except:
|
||||
except Exception as e:
|
||||
if onLine == '1':
|
||||
logPro.error("Server Non raggiungibile")
|
||||
logPro.error(str(e))
|
||||
#print "Non raggiungibile"
|
||||
|
||||
onLine = '0'
|
||||
@@ -496,8 +499,9 @@ def contatore():
|
||||
ctr +=1
|
||||
ctr = ctr % 10000 # round robin 10000 eventi x track
|
||||
cont = str(ctr)
|
||||
except:
|
||||
print("errore incremento contatore")
|
||||
except Exception as e:
|
||||
print("errore incremento contatore \n\n")
|
||||
print(str(e))
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# avvia porta parallela
|
||||
@@ -541,8 +545,9 @@ def avviaParallela():
|
||||
GPIO.setup(in_10, GPIO.IN) # input 10
|
||||
GPIO.setup(in_11, GPIO.IN) # input 11
|
||||
|
||||
except:
|
||||
print( "\n\n" + PROGRAM_NAME + " - Error 3 on RPi.GPIO ! \n\n")
|
||||
except Exception as e:
|
||||
print( "\n\n" + PROGRAM_NAME + " - Error 3 on RPi.GPIO ! \n\n")
|
||||
print str(e)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@@ -598,7 +603,7 @@ try:
|
||||
B_inverting[4] = config.getint ( 'invert' , 'bit4' )
|
||||
B_inverting[5] = config.getint ( 'invert' , 'bit5' )
|
||||
B_inverting[6] = config.getint ( 'invert' , 'bit6' )
|
||||
B_inverting[7] = config.getint ( 'invert' , 'bit7' )
|
||||
B_inverting[7] = config.getint ( 'invert' , 'bit7' )
|
||||
B_inverting[8] = config.getint ( 'invert' , 'bit8' )
|
||||
B_inverting[9] = config.getint ( 'invert' , 'bit9' )
|
||||
B_inverting[10] = config.getint ( 'invert' , 'bit10' )
|
||||
@@ -613,7 +618,7 @@ try:
|
||||
B_filter[4] = config.getint ( 'filter' , 'bit4' )
|
||||
B_filter[5] = config.getint ( 'filter' , 'bit5' )
|
||||
B_filter[6] = config.getint ( 'filter' , 'bit6' )
|
||||
B_filter[7] = config.getint ( 'filter' , 'bit7' )
|
||||
B_filter[7] = config.getint ( 'filter' , 'bit7' )
|
||||
B_filter[8] = config.getint ( 'filter' , 'bit8' )
|
||||
B_filter[9] = config.getint ( 'filter' , 'bit9' )
|
||||
B_filter[10] = config.getint ( 'filter' , 'bit10' )
|
||||
@@ -622,8 +627,9 @@ try:
|
||||
MAX_COUNTER_FILTER = config.getint ( 'filter' , 'MAX_COUNTER_FILTER' )
|
||||
|
||||
|
||||
except:
|
||||
except Exception as e:
|
||||
print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg'
|
||||
print str(e)
|
||||
sys.exit(1)
|
||||
|
||||
#--------------------------------------------
|
||||
@@ -642,10 +648,12 @@ try:
|
||||
logSnd = logging.getLogger('sendUrl')
|
||||
logPro = logging.getLogger('program')
|
||||
|
||||
except:
|
||||
except Exception as e:
|
||||
# manda mail o simili - FARE!!!
|
||||
print "LOG: Impossibile creare file log con nome "
|
||||
print "LOG: Impossibile creare file log con nome"
|
||||
print (LOGFILE)
|
||||
print "\n\n"
|
||||
print str(e)
|
||||
#--------------------------------------------
|
||||
|
||||
|
||||
@@ -699,8 +707,9 @@ try:
|
||||
import RPi.GPIO as GPIO
|
||||
except RuntimeError:
|
||||
print( "\n\n" + PROGRAM_NAME + " - Error 1 - you need superuser privileges")
|
||||
except:
|
||||
except Exception as e:
|
||||
print( "\n\n" + PROGRAM_NAME + " - Error 2 - you need superuser privileges. USE 'sudo' to run your script\n\n")
|
||||
print str(e)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@@ -726,8 +735,9 @@ while 1:
|
||||
|
||||
try:
|
||||
time.sleep (SAMPLETIME)
|
||||
except:
|
||||
logPro.info("First_SLEEP: errore attesa sampletime")
|
||||
except Exception as e:
|
||||
logPro.info("First_SLEEP: errore attesa sampletime")
|
||||
logPro.error(str(e))
|
||||
|
||||
# lettura dati da IOB
|
||||
value = readParallelaFiltrata()
|
||||
@@ -740,8 +750,9 @@ while 1:
|
||||
errormsglen = 0
|
||||
accoda()
|
||||
contatore()
|
||||
except:
|
||||
except Exception as e:
|
||||
logPro.error("URLBROWSER: errore registrazione valore e accoda")
|
||||
logPro.error(str(e))
|
||||
pass
|
||||
#enable e reset timer
|
||||
to_enable = True
|
||||
@@ -761,8 +772,9 @@ while 1:
|
||||
errormsglen = 0
|
||||
accoda()
|
||||
contatore()
|
||||
except:
|
||||
except Exception as e:
|
||||
logPro.error("URLBROWSER: errore registrazione valore e accoda TO_short")
|
||||
logPro.error(str(e))
|
||||
pass
|
||||
to_short = TIMEOUTSHORT
|
||||
to_enable = False # dopo un colpo il timer breve viene disabilitato
|
||||
@@ -777,7 +789,8 @@ while 1:
|
||||
errormsglen = 0
|
||||
accoda()
|
||||
contatore()
|
||||
except:
|
||||
except Exception as e:
|
||||
logPro.error("URLBROWSER: errore registrazione valore e accoda TO_long")
|
||||
logPro.error(str(e))
|
||||
pass
|
||||
to_long = TIMEOUTLONG
|
||||
+41
-36
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# sendReboot v. 1.8
|
||||
|
||||
# - (2.5.2) Fix gestione eccezioni con report dettagliato
|
||||
#---------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import time
|
||||
#---------------------------------------------------------------
|
||||
|
||||
# COSTANTI
|
||||
PROGRAM_NAME = "SendReboot IOB-pi v.1.8"
|
||||
SR_PROG_NAME = "SendReboot IOB-pi v.2.5.2"
|
||||
|
||||
# DA FILE CONF
|
||||
idxMacchina = "99"
|
||||
@@ -39,44 +39,48 @@ numTry = 1
|
||||
|
||||
def chiamaUrl(numTry):
|
||||
|
||||
try:
|
||||
urllib.urlopen ( url )
|
||||
numTry = numTry + 10
|
||||
except Exception, e:
|
||||
print e
|
||||
logging.info ( e )
|
||||
print "Url aforte" , url
|
||||
return numTry
|
||||
try:
|
||||
urllib.urlopen ( url )
|
||||
numTry = numTry + 10
|
||||
|
||||
except Exception as e:
|
||||
print("Errore in chiamaUrl")
|
||||
print(str(e))
|
||||
logging.info ( str(e) )
|
||||
|
||||
print("Url chiamato: " , url)
|
||||
return numTry
|
||||
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# Funzione di recupero mac address per poterlo inviare a MPIO
|
||||
#---------------------------------------------------------------
|
||||
def getMAC(interface):
|
||||
# Return the MAC address of interface
|
||||
try:
|
||||
str = open('/sys/class/net/' + interface + '/address').read()
|
||||
except:
|
||||
str = "00:00:00:00:00:00"
|
||||
return str[0:17]
|
||||
# Return the MAC address of interface
|
||||
try:
|
||||
str = open('/sys/class/net/' + interface + '/address').read()
|
||||
except:
|
||||
str = "00:00:00:00:00:00"
|
||||
return str[0:17]
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# MAIN
|
||||
#---------------------------------------------------------------
|
||||
|
||||
try:
|
||||
config = ConfigParser.RawConfigParser()
|
||||
config.read ( 'IOB.cfg' )
|
||||
config = ConfigParser.RawConfigParser()
|
||||
config.read ( 'IOB.cfg' )
|
||||
|
||||
idxMacchina = config.get ( 'id' , 'idxMacchina' )
|
||||
idxMacchina = config.get ( 'id' , 'idxMacchina' )
|
||||
|
||||
|
||||
URLREBO = config.get ( 'web' , 'URLREBO' )
|
||||
URLREBO = config.get ( 'web' , 'URLREBO' )
|
||||
|
||||
LOGFILE = config.get ( 'log' , 'LOGREBO' )
|
||||
except:
|
||||
print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg'
|
||||
sys.exit(1)
|
||||
LOGFILE = config.get ( 'log' , 'LOGREBO' )
|
||||
except Exception as e:
|
||||
print("\n\n" + SR_PROG_NAME + ' - Error 4 - in config file ' 'IOB.cfg')
|
||||
print(str(e))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
#--------------------------------------------
|
||||
@@ -84,26 +88,27 @@ except:
|
||||
#--------------------------------------------
|
||||
try:
|
||||
# log = Logger(LOGFILE)
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format='%(asctime)s %(name)-8s %(levelname)-8s %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
filename=LOGFILE,
|
||||
filemode='a')
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format='%(asctime)s %(name)-8s %(levelname)-8s %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
filename=LOGFILE,
|
||||
filemode='a')
|
||||
|
||||
except:
|
||||
# manda mail o simili - FARE!!!
|
||||
print "LOG: Impossibile creare file log con nome "
|
||||
print (LOGFILE)
|
||||
except Exception as e:
|
||||
# manda mail o simili - FARE!!!
|
||||
print("LOG: Impossibile creare file log con nome ")
|
||||
print(LOGFILE)
|
||||
print(str(e))
|
||||
#--------------------------------------------
|
||||
|
||||
|
||||
print "\n\n" + PROGRAM_NAME + "\n\n"
|
||||
print("\n\n" + SR_PROG_NAME + "\n\n")
|
||||
|
||||
global startstatus
|
||||
startstatus = 1
|
||||
|
||||
if startstatus == 1:
|
||||
logging.info("Avvio Programma " + PROGRAM_NAME)
|
||||
logging.info("Avvio Programma " + SR_PROG_NAME)
|
||||
|
||||
|
||||
# lettura file configurazione
|
||||
@@ -120,7 +125,7 @@ url = URLREBO + idxMacchina + "&mac=" + myMac
|
||||
|
||||
# modifica: cerco se ho inviato segnale altrimenti ritento invio...
|
||||
while (numTry < 11):
|
||||
logging.info("Tentativo invio URL: " + `numTry` )
|
||||
logging.info("Tentativo invio URL: $numTry" )
|
||||
numTry = chiamaUrl(numTry)
|
||||
time.sleep(3)
|
||||
numTry = numTry + 1
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user