From 10abf637fae1c836cf66e5a92ee9acee232b3799 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 6 Jun 2018 16:06:41 +0200 Subject: [PATCH] Conf Jetco x GD32 GLD25 --- IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg | 35 + .../167 - GLD25/steamware}/IOB.cfg.donati | 0 .../Jetco/167 - GLD25/steamware/IOB.cfg.jetco | 35 + .../167 - GLD25/steamware/IOB.cfg.steamware | 35 + .../{ => Jetco/167 - GLD25/steamware}/MapoIOB | 0 .../167 - GLD25/steamware}/MapoIOB_logrot | 0 .../167 - GLD25/steamware}/checkAlive.sh | 0 .../167 - GLD25/steamware}/cleanPython.sh | 0 .../167 - GLD25/steamware}/convertLogFile.py | 0 .../{ => Jetco/167 - GLD25/steamware}/crontab | 0 .../167 - GLD25/steamware}/install-RPI-IOB.sh | 0 .../Jetco/167 - GLD25/steamware/logReboot.txt | 9 + .../Jetco/167 - GLD25/steamware/logTemp.txt | 1 + .../Jetco/167 - GLD25/steamware/logfile.txt | 171 +++++ IOB-PI/Jetco/167 - GLD25/steamware/mppar | 2 + IOB-PI/Jetco/167 - GLD25/steamware/mpser | 2 + .../167 - GLD25/steamware}/readFile.py | 0 .../167 - GLD25/steamware}/readParallela.py | 0 .../167 - GLD25/steamware}/readSeriale.py | 0 .../167 - GLD25/steamware}/saveTemp.sh | 0 .../167 - GLD25/steamware}/sendReboot.py | 0 .../167 - GLD25/steamware}/sendRebootIOB | 0 .../steamware}/sendRebootIOB.service | 0 .../167 - GLD25/steamware}/setIobConf.sh | 0 IOB-PI/Jetco/167 - GLD25/steamware/test.py | 31 + .../{ => Jetco/167 - GLD25/steamware}/unix.py | 0 IOB-PI/Jetco/167 - GLD25/steamware/unix.pyc | Bin 0 -> 669 bytes .../{ => Jetco/167 - GLD25/steamware}/win.py | 0 IOB-PI/Jetco/167 - GLD25/steamware/win.pyc | Bin 0 -> 883 bytes IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg | 35 + IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.bck | 23 + .../168 - GD32/steamware/IOB.cfg.donati} | 0 .../Jetco/168 - GD32/steamware/IOB.cfg.jetco | 35 + .../168 - GD32/steamware/IOB.cfg.steamware | 35 + IOB-PI/Jetco/168 - GD32/steamware/MapoIOB | 41 ++ .../Jetco/168 - GD32/steamware/MapoIOB_logrot | 28 + .../Jetco/168 - GD32/steamware/checkAlive.sh | 20 + .../Jetco/168 - GD32/steamware/cleanPython.sh | 14 + .../168 - GD32/steamware/convertLogFile.py | 46 ++ IOB-PI/Jetco/168 - GD32/steamware/crontab | 1 + .../168 - GD32/steamware/install-RPI-IOB.sh | 51 ++ .../Jetco/168 - GD32/steamware/logReboot.txt | 11 + IOB-PI/Jetco/168 - GD32/steamware/logTemp.txt | 0 IOB-PI/Jetco/168 - GD32/steamware/logfile.txt | 29 + IOB-PI/Jetco/168 - GD32/steamware/mppar | 2 + IOB-PI/Jetco/168 - GD32/steamware/mpser | 2 + IOB-PI/Jetco/168 - GD32/steamware/readFile.py | 152 +++++ .../168 - GD32/steamware/readParallela.py | 608 ++++++++++++++++++ .../Jetco/168 - GD32/steamware/readSeriale.py | 363 +++++++++++ IOB-PI/Jetco/168 - GD32/steamware/saveTemp.sh | 17 + .../Jetco/168 - GD32/steamware/sendReboot.py | 130 ++++ .../Jetco/168 - GD32/steamware/sendRebootIOB | 33 + .../steamware/sendRebootIOB.service | 22 + .../Jetco/168 - GD32/steamware/setIobConf.sh | 26 + IOB-PI/Jetco/168 - GD32/steamware/test.py | 31 + IOB-PI/Jetco/168 - GD32/steamware/unix.py | 31 + IOB-PI/Jetco/168 - GD32/steamware/unix.pyc | Bin 0 -> 669 bytes IOB-PI/Jetco/168 - GD32/steamware/win.py | 32 + IOB-PI/Jetco/168 - GD32/steamware/win.pyc | Bin 0 -> 883 bytes IOB-PI/Jetco/std_v_2/IOB.cfg.donati | 35 + IOB-PI/Jetco/std_v_2/IOB.cfg.steamware | 35 + IOB-PI/Jetco/std_v_2/MapoIOB | 41 ++ IOB-PI/Jetco/std_v_2/MapoIOB_logrot | 28 + IOB-PI/Jetco/std_v_2/checkAlive.sh | 20 + IOB-PI/Jetco/std_v_2/cleanPython.sh | 14 + IOB-PI/Jetco/std_v_2/convertLogFile.py | 46 ++ IOB-PI/Jetco/std_v_2/crontab | 1 + IOB-PI/Jetco/std_v_2/install-RPI-IOB.sh | 51 ++ IOB-PI/Jetco/std_v_2/readFile.py | 152 +++++ IOB-PI/Jetco/std_v_2/readParallela.py | 608 ++++++++++++++++++ IOB-PI/Jetco/std_v_2/readSeriale.py | 363 +++++++++++ IOB-PI/Jetco/std_v_2/saveTemp.sh | 17 + IOB-PI/Jetco/std_v_2/sendReboot.py | 130 ++++ IOB-PI/Jetco/std_v_2/sendRebootIOB | 33 + IOB-PI/Jetco/std_v_2/sendRebootIOB.service | 22 + IOB-PI/Jetco/std_v_2/setIobConf.sh | 26 + IOB-PI/Jetco/std_v_2/unix.py | 31 + IOB-PI/Jetco/std_v_2/win.py | 32 + IOB-PI/README.md | 3 + IOB-PI/std_v_2/IOB.cfg | 35 + IOB-PI/std_v_2/IOB.cfg.donati | 35 + IOB-PI/{ => std_v_2}/IOB.cfg.steamware | 0 IOB-PI/std_v_2/MapoIOB | 41 ++ IOB-PI/std_v_2/MapoIOB_logrot | 28 + IOB-PI/std_v_2/checkAlive.sh | 20 + IOB-PI/std_v_2/cleanPython.sh | 14 + IOB-PI/std_v_2/convertLogFile.py | 46 ++ IOB-PI/std_v_2/crontab | 1 + IOB-PI/std_v_2/install-RPI-IOB.sh | 51 ++ IOB-PI/std_v_2/readFile.py | 152 +++++ IOB-PI/std_v_2/readParallela.py | 608 ++++++++++++++++++ IOB-PI/std_v_2/readSeriale.py | 363 +++++++++++ IOB-PI/std_v_2/saveTemp.sh | 17 + IOB-PI/std_v_2/sendReboot.py | 130 ++++ IOB-PI/std_v_2/sendRebootIOB | 33 + IOB-PI/std_v_2/sendRebootIOB.service | 22 + IOB-PI/std_v_2/setIobConf.sh | 26 + IOB-PI/std_v_2/unix.py | 31 + IOB-PI/std_v_2/win.py | 32 + 99 files changed, 5512 insertions(+) create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/IOB.cfg.donati (100%) create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.jetco create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.steamware rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/MapoIOB (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/MapoIOB_logrot (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/checkAlive.sh (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/cleanPython.sh (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/convertLogFile.py (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/crontab (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/install-RPI-IOB.sh (100%) create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/logReboot.txt create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/logTemp.txt create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/logfile.txt create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/mppar create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/mpser rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/readFile.py (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/readParallela.py (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/readSeriale.py (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/saveTemp.sh (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/sendReboot.py (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/sendRebootIOB (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/sendRebootIOB.service (100%) rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/setIobConf.sh (100%) create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/test.py rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/unix.py (100%) create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/unix.pyc rename IOB-PI/{ => Jetco/167 - GLD25/steamware}/win.py (100%) create mode 100644 IOB-PI/Jetco/167 - GLD25/steamware/win.pyc create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.bck rename IOB-PI/{IOB.cfg => Jetco/168 - GD32/steamware/IOB.cfg.donati} (100%) create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.jetco create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.steamware create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/MapoIOB create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/MapoIOB_logrot create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/checkAlive.sh create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/cleanPython.sh create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/convertLogFile.py create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/crontab create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/install-RPI-IOB.sh create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/logReboot.txt create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/logTemp.txt create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/logfile.txt create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/mppar create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/mpser create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/readFile.py create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/readParallela.py create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/readSeriale.py create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/saveTemp.sh create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/sendReboot.py create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/sendRebootIOB create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/sendRebootIOB.service create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/setIobConf.sh create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/test.py create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/unix.py create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/unix.pyc create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/win.py create mode 100644 IOB-PI/Jetco/168 - GD32/steamware/win.pyc create mode 100644 IOB-PI/Jetco/std_v_2/IOB.cfg.donati create mode 100644 IOB-PI/Jetco/std_v_2/IOB.cfg.steamware create mode 100644 IOB-PI/Jetco/std_v_2/MapoIOB create mode 100644 IOB-PI/Jetco/std_v_2/MapoIOB_logrot create mode 100644 IOB-PI/Jetco/std_v_2/checkAlive.sh create mode 100644 IOB-PI/Jetco/std_v_2/cleanPython.sh create mode 100644 IOB-PI/Jetco/std_v_2/convertLogFile.py create mode 100644 IOB-PI/Jetco/std_v_2/crontab create mode 100644 IOB-PI/Jetco/std_v_2/install-RPI-IOB.sh create mode 100644 IOB-PI/Jetco/std_v_2/readFile.py create mode 100644 IOB-PI/Jetco/std_v_2/readParallela.py create mode 100644 IOB-PI/Jetco/std_v_2/readSeriale.py create mode 100644 IOB-PI/Jetco/std_v_2/saveTemp.sh create mode 100644 IOB-PI/Jetco/std_v_2/sendReboot.py create mode 100644 IOB-PI/Jetco/std_v_2/sendRebootIOB create mode 100644 IOB-PI/Jetco/std_v_2/sendRebootIOB.service create mode 100644 IOB-PI/Jetco/std_v_2/setIobConf.sh create mode 100644 IOB-PI/Jetco/std_v_2/unix.py create mode 100644 IOB-PI/Jetco/std_v_2/win.py create mode 100644 IOB-PI/README.md create mode 100644 IOB-PI/std_v_2/IOB.cfg create mode 100644 IOB-PI/std_v_2/IOB.cfg.donati rename IOB-PI/{ => std_v_2}/IOB.cfg.steamware (100%) create mode 100644 IOB-PI/std_v_2/MapoIOB create mode 100644 IOB-PI/std_v_2/MapoIOB_logrot create mode 100644 IOB-PI/std_v_2/checkAlive.sh create mode 100644 IOB-PI/std_v_2/cleanPython.sh create mode 100644 IOB-PI/std_v_2/convertLogFile.py create mode 100644 IOB-PI/std_v_2/crontab create mode 100644 IOB-PI/std_v_2/install-RPI-IOB.sh create mode 100644 IOB-PI/std_v_2/readFile.py create mode 100644 IOB-PI/std_v_2/readParallela.py create mode 100644 IOB-PI/std_v_2/readSeriale.py create mode 100644 IOB-PI/std_v_2/saveTemp.sh create mode 100644 IOB-PI/std_v_2/sendReboot.py create mode 100644 IOB-PI/std_v_2/sendRebootIOB create mode 100644 IOB-PI/std_v_2/sendRebootIOB.service create mode 100644 IOB-PI/std_v_2/setIobConf.sh create mode 100644 IOB-PI/std_v_2/unix.py create mode 100644 IOB-PI/std_v_2/win.py diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg b/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg new file mode 100644 index 0000000..4a76d3d --- /dev/null +++ b/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg @@ -0,0 +1,35 @@ +[id] +idxMacchina = 3008 + +[web] +URLBASE = http://192.168.1.7/MP/IO/IOB/input/ +URLALIVE = http://192.168.1.7/MP/IO/IOB +URLENABLED = http://192.168.1.7/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://192.168.1.7/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/IOB.cfg.donati b/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.donati similarity index 100% rename from IOB-PI/IOB.cfg.donati rename to IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.donati diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.jetco b/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.jetco new file mode 100644 index 0000000..4a76d3d --- /dev/null +++ b/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.jetco @@ -0,0 +1,35 @@ +[id] +idxMacchina = 3008 + +[web] +URLBASE = http://192.168.1.7/MP/IO/IOB/input/ +URLALIVE = http://192.168.1.7/MP/IO/IOB +URLENABLED = http://192.168.1.7/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://192.168.1.7/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.steamware b/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.steamware new file mode 100644 index 0000000..9d9c1de --- /dev/null +++ b/IOB-PI/Jetco/167 - GLD25/steamware/IOB.cfg.steamware @@ -0,0 +1,35 @@ +[id] +idxMacchina = 0001 + +[web] +URLBASE = http://10.74.82.219/MP/IO/IOB/input/ +URLALIVE = http://10.74.82.219/MP/IO/IOB +URLENABLED = http://10.74.82.219/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/MapoIOB b/IOB-PI/Jetco/167 - GLD25/steamware/MapoIOB similarity index 100% rename from IOB-PI/MapoIOB rename to IOB-PI/Jetco/167 - GLD25/steamware/MapoIOB diff --git a/IOB-PI/MapoIOB_logrot b/IOB-PI/Jetco/167 - GLD25/steamware/MapoIOB_logrot similarity index 100% rename from IOB-PI/MapoIOB_logrot rename to IOB-PI/Jetco/167 - GLD25/steamware/MapoIOB_logrot diff --git a/IOB-PI/checkAlive.sh b/IOB-PI/Jetco/167 - GLD25/steamware/checkAlive.sh similarity index 100% rename from IOB-PI/checkAlive.sh rename to IOB-PI/Jetco/167 - GLD25/steamware/checkAlive.sh diff --git a/IOB-PI/cleanPython.sh b/IOB-PI/Jetco/167 - GLD25/steamware/cleanPython.sh similarity index 100% rename from IOB-PI/cleanPython.sh rename to IOB-PI/Jetco/167 - GLD25/steamware/cleanPython.sh diff --git a/IOB-PI/convertLogFile.py b/IOB-PI/Jetco/167 - GLD25/steamware/convertLogFile.py similarity index 100% rename from IOB-PI/convertLogFile.py rename to IOB-PI/Jetco/167 - GLD25/steamware/convertLogFile.py diff --git a/IOB-PI/crontab b/IOB-PI/Jetco/167 - GLD25/steamware/crontab similarity index 100% rename from IOB-PI/crontab rename to IOB-PI/Jetco/167 - GLD25/steamware/crontab diff --git a/IOB-PI/install-RPI-IOB.sh b/IOB-PI/Jetco/167 - GLD25/steamware/install-RPI-IOB.sh similarity index 100% rename from IOB-PI/install-RPI-IOB.sh rename to IOB-PI/Jetco/167 - GLD25/steamware/install-RPI-IOB.sh diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/logReboot.txt b/IOB-PI/Jetco/167 - GLD25/steamware/logReboot.txt new file mode 100644 index 0000000..21d1eea --- /dev/null +++ b/IOB-PI/Jetco/167 - GLD25/steamware/logReboot.txt @@ -0,0 +1,9 @@ +2018-06-06 13:46:50 root INFO Avvio Programma SendReboot IOB-pi v.1.8 +2018-06-06 13:46:50 root INFO Tentativo invio URL: 1 +2018-06-06 13:46:50 root INFO [Errno socket error] [Errno 101] Network is unreachable +2018-06-06 13:46:53 root INFO Tentativo invio URL: 2 +2018-06-06 13:46:53 root INFO [Errno socket error] [Errno 101] Network is unreachable +2018-06-06 13:46:56 root INFO Tentativo invio URL: 3 +2018-06-06 13:46:56 root INFO [Errno socket error] [Errno 101] Network is unreachable +2018-06-06 13:46:59 root INFO Tentativo invio URL: 4 +2018-06-06 13:46:59 root INFO [Errno socket error] [Errno 101] Network is unreachable diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/logTemp.txt b/IOB-PI/Jetco/167 - GLD25/steamware/logTemp.txt new file mode 100644 index 0000000..e3e6fe2 --- /dev/null +++ b/IOB-PI/Jetco/167 - GLD25/steamware/logTemp.txt @@ -0,0 +1 @@ +Wed Jun 6 14:00:01 UTC 2018 | CPU: temp=45.0 ºC | GPU: temp=44.0'C | LoadAvg: 0.00 0.00 0.00 1/118 6196 diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/logfile.txt b/IOB-PI/Jetco/167 - GLD25/steamware/logfile.txt new file mode 100644 index 0000000..4de1454 --- /dev/null +++ b/IOB-PI/Jetco/167 - GLD25/steamware/logfile.txt @@ -0,0 +1,171 @@ +2018-06-06 13:46:50 program INFO Avvio ProgrammaReadPar IOB-pi v.2.0 +2018-06-06 13:46:50 program INFO Start ReadPar IOB-pi v.2.0 +2018-06-06 13:46:50 program INFO Avvio loop principale +2018-06-06 13:46:50 queue INFO 3B [0] +2018-06-06 13:46:50 program ERROR Server Non raggiungibile +2018-06-06 13:46:51 queue INFO >3B [1] +2018-06-06 13:47:00 program INFO IOB ONLINE! +2018-06-06 13:47:00 sendUrl INFO 3B [0] R:OK +2018-06-06 13:47:00 sendUrl INFO 3B [1] R:OK +2018-06-06 13:47:01 program INFO Avvio ProgrammaReadPar IOB-pi v.2.0 +2018-06-06 13:47:01 program INFO Start ReadPar IOB-pi v.2.0 +2018-06-06 13:47:01 program INFO Avvio loop principale +2018-06-06 13:47:01 queue INFO 3B [0] +2018-06-06 13:47:01 sendUrl INFO 3B [0] R:OK +2018-06-06 13:47:01 queue INFO >3B [1] +2018-06-06 13:47:02 sendUrl INFO 3B [1] R:OK +2018-06-06 13:48:00 queue INFO >>3B [2] +2018-06-06 13:48:00 sendUrl INFO 3B [2] R:OK +2018-06-06 13:48:51 queue INFO >>3B [3] +2018-06-06 13:48:51 sendUrl INFO 3B [3] R:OK +2018-06-06 13:49:21 program INFO END Blink on bit 3 +2018-06-06 13:49:21 queue INFO 33 [4] +2018-06-06 13:49:21 sendUrl INFO 33 [4] R:OK +2018-06-06 13:49:21 queue INFO >33 [5] +2018-06-06 13:49:21 sendUrl INFO 33 [5] R:OK +2018-06-06 13:49:37 queue INFO 73 [6] +2018-06-06 13:49:37 sendUrl INFO 73 [6] R:OK +2018-06-06 13:49:37 queue INFO >73 [7] +2018-06-06 13:49:37 sendUrl INFO 73 [7] R:OK +2018-06-06 13:50:27 queue INFO >>73 [8] +2018-06-06 13:50:27 sendUrl INFO 73 [8] R:OK +2018-06-06 13:50:43 queue INFO 77 [9] +2018-06-06 13:50:44 sendUrl INFO 77 [9] R:OK +2018-06-06 13:50:44 queue INFO 57 [10] +2018-06-06 13:50:44 sendUrl INFO 57 [10] R:OK +2018-06-06 13:50:44 queue INFO >57 [11] +2018-06-06 13:50:44 sendUrl INFO 57 [11] R:OK +2018-06-06 13:50:44 queue INFO 77 [12] +2018-06-06 13:50:44 sendUrl INFO 77 [12] R:OK +2018-06-06 13:50:44 queue INFO >77 [13] +2018-06-06 13:50:44 sendUrl INFO 77 [13] R:OK +2018-06-06 13:51:26 queue INFO 37 [14] +2018-06-06 13:51:26 sendUrl INFO 37 [14] R:OK +2018-06-06 13:51:26 queue INFO >37 [15] +2018-06-06 13:51:26 sendUrl INFO 37 [15] R:OK +2018-06-06 13:51:35 queue INFO 77 [16] +2018-06-06 13:51:35 sendUrl INFO 77 [16] R:OK +2018-06-06 13:51:35 queue INFO >77 [17] +2018-06-06 13:51:35 sendUrl INFO 77 [17] R:OK +2018-06-06 13:51:43 queue INFO 73 [18] +2018-06-06 13:51:43 sendUrl INFO 73 [18] R:OK +2018-06-06 13:51:43 queue INFO >73 [19] +2018-06-06 13:51:43 sendUrl INFO 73 [19] R:OK +2018-06-06 13:51:52 queue INFO 77 [20] +2018-06-06 13:51:52 sendUrl INFO 77 [20] R:OK +2018-06-06 13:51:52 queue INFO 57 [21] +2018-06-06 13:51:52 sendUrl INFO 57 [21] R:OK +2018-06-06 13:51:52 queue INFO >57 [22] +2018-06-06 13:51:53 sendUrl INFO 57 [22] R:OK +2018-06-06 13:51:53 queue INFO 77 [23] +2018-06-06 13:51:53 sendUrl INFO 77 [23] R:OK +2018-06-06 13:51:53 queue INFO >77 [24] +2018-06-06 13:51:53 sendUrl INFO 77 [24] R:OK +2018-06-06 13:52:16 queue INFO 37 [25] +2018-06-06 13:52:16 sendUrl INFO 37 [25] R:OK +2018-06-06 13:52:16 queue INFO >37 [26] +2018-06-06 13:52:17 sendUrl INFO 37 [26] R:OK +2018-06-06 13:52:23 queue INFO 77 [27] +2018-06-06 13:52:23 sendUrl INFO 77 [27] R:OK +2018-06-06 13:52:23 queue INFO >77 [28] +2018-06-06 13:52:23 sendUrl INFO 77 [28] R:OK +2018-06-06 13:52:27 queue INFO 73 [29] +2018-06-06 13:52:27 sendUrl INFO 73 [29] R:OK +2018-06-06 13:52:27 queue INFO >73 [30] +2018-06-06 13:52:27 sendUrl INFO 73 [30] R:OK +2018-06-06 13:53:18 queue INFO >>73 [31] +2018-06-06 13:53:18 sendUrl INFO 73 [31] R:OK +2018-06-06 13:54:08 queue INFO >>73 [32] +2018-06-06 13:54:08 sendUrl INFO 73 [32] R:OK +2018-06-06 13:54:20 queue INFO 77 [33] +2018-06-06 13:54:20 sendUrl INFO 77 [33] R:OK +2018-06-06 13:54:20 queue INFO 57 [34] +2018-06-06 13:54:20 sendUrl INFO 57 [34] R:OK +2018-06-06 13:54:21 queue INFO >57 [35] +2018-06-06 13:54:21 sendUrl INFO 57 [35] R:OK +2018-06-06 13:54:21 queue INFO 77 [36] +2018-06-06 13:54:21 sendUrl INFO 77 [36] R:OK +2018-06-06 13:54:21 queue INFO >77 [37] +2018-06-06 13:54:21 sendUrl INFO 77 [37] R:OK +2018-06-06 13:54:44 queue INFO 37 [38] +2018-06-06 13:54:44 sendUrl INFO 37 [38] R:OK +2018-06-06 13:54:45 queue INFO >37 [39] +2018-06-06 13:54:45 sendUrl INFO 37 [39] R:OK +2018-06-06 13:54:51 queue INFO 77 [40] +2018-06-06 13:54:51 sendUrl INFO 77 [40] R:OK +2018-06-06 13:54:51 queue INFO >77 [41] +2018-06-06 13:54:51 sendUrl INFO 77 [41] R:OK +2018-06-06 13:54:55 queue INFO 73 [42] +2018-06-06 13:54:55 sendUrl INFO 73 [42] R:OK +2018-06-06 13:54:55 queue INFO >73 [43] +2018-06-06 13:54:56 sendUrl INFO 73 [43] R:OK +2018-06-06 13:55:21 queue INFO 77 [44] +2018-06-06 13:55:21 queue INFO 57 [45] +2018-06-06 13:55:21 sendUrl INFO 77 [44] R:OK +2018-06-06 13:55:21 sendUrl INFO 57 [45] R:OK +2018-06-06 13:55:22 queue INFO >57 [46] +2018-06-06 13:55:22 sendUrl INFO 57 [46] R:OK +2018-06-06 13:55:22 queue INFO 77 [47] +2018-06-06 13:55:22 sendUrl INFO 77 [47] R:OK +2018-06-06 13:55:22 queue INFO >77 [48] +2018-06-06 13:55:22 sendUrl INFO 77 [48] R:OK +2018-06-06 13:55:45 queue INFO 37 [49] +2018-06-06 13:55:45 sendUrl INFO 37 [49] R:OK +2018-06-06 13:55:46 queue INFO >37 [50] +2018-06-06 13:55:46 sendUrl INFO 37 [50] R:OK +2018-06-06 13:55:52 queue INFO 77 [51] +2018-06-06 13:55:52 sendUrl INFO 77 [51] R:OK +2018-06-06 13:55:52 queue INFO >77 [52] +2018-06-06 13:55:53 sendUrl INFO 77 [52] R:OK +2018-06-06 13:55:56 queue INFO 73 [53] +2018-06-06 13:55:56 sendUrl INFO 73 [53] R:OK +2018-06-06 13:55:57 queue INFO >73 [54] +2018-06-06 13:55:57 sendUrl INFO 73 [54] R:OK +2018-06-06 13:56:34 queue INFO 77 [55] +2018-06-06 13:56:34 queue INFO 57 [56] +2018-06-06 13:56:34 sendUrl INFO 77 [55] R:OK +2018-06-06 13:56:34 sendUrl INFO 57 [56] R:OK +2018-06-06 13:56:35 queue INFO >57 [57] +2018-06-06 13:56:35 sendUrl INFO 57 [57] R:OK +2018-06-06 13:56:35 queue INFO 77 [58] +2018-06-06 13:56:35 sendUrl INFO 77 [58] R:OK +2018-06-06 13:56:35 queue INFO >77 [59] +2018-06-06 13:56:35 sendUrl INFO 77 [59] R:OK +2018-06-06 13:56:58 queue INFO 37 [60] +2018-06-06 13:56:58 sendUrl INFO 37 [60] R:OK +2018-06-06 13:56:59 queue INFO >37 [61] +2018-06-06 13:56:59 sendUrl INFO 37 [61] R:OK +2018-06-06 13:57:05 queue INFO 77 [62] +2018-06-06 13:57:05 sendUrl INFO 77 [62] R:OK +2018-06-06 13:57:05 queue INFO >77 [63] +2018-06-06 13:57:05 sendUrl INFO 77 [63] R:OK +2018-06-06 13:57:09 queue INFO 73 [64] +2018-06-06 13:57:09 sendUrl INFO 73 [64] R:OK +2018-06-06 13:57:09 queue INFO >73 [65] +2018-06-06 13:57:10 sendUrl INFO 73 [65] R:OK +2018-06-06 13:58:00 queue INFO >>73 [66] +2018-06-06 13:58:00 sendUrl INFO 73 [66] R:OK +2018-06-06 13:58:50 queue INFO >>73 [67] +2018-06-06 13:58:50 sendUrl INFO 73 [67] R:OK +2018-06-06 13:59:24 queue INFO 77 [68] +2018-06-06 13:59:24 queue INFO 57 [69] +2018-06-06 13:59:24 sendUrl INFO 77 [68] R:OK +2018-06-06 13:59:24 sendUrl INFO 57 [69] R:OK +2018-06-06 13:59:24 queue INFO >57 [70] +2018-06-06 13:59:24 sendUrl INFO 57 [70] R:OK +2018-06-06 13:59:24 queue INFO 77 [71] +2018-06-06 13:59:25 sendUrl INFO 77 [71] R:OK +2018-06-06 13:59:25 queue INFO >77 [72] +2018-06-06 13:59:25 sendUrl INFO 77 [72] R:OK +2018-06-06 13:59:48 queue INFO 37 [73] +2018-06-06 13:59:48 sendUrl INFO 37 [73] R:OK +2018-06-06 13:59:48 queue INFO >37 [74] +2018-06-06 13:59:48 sendUrl INFO 37 [74] R:OK +2018-06-06 13:59:55 queue INFO 77 [75] +2018-06-06 13:59:55 sendUrl INFO 77 [75] R:OK +2018-06-06 13:59:55 queue INFO >77 [76] +2018-06-06 13:59:55 sendUrl INFO 77 [76] R:OK +2018-06-06 13:59:59 queue INFO 73 [77] +2018-06-06 13:59:59 sendUrl INFO 73 [77] R:OK +2018-06-06 13:59:59 queue INFO >73 [78] +2018-06-06 13:59:59 sendUrl INFO 73 [78] R:OK diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/mppar b/IOB-PI/Jetco/167 - GLD25/steamware/mppar new file mode 100644 index 0000000..b433a73 --- /dev/null +++ b/IOB-PI/Jetco/167 - GLD25/steamware/mppar @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/bin/python /home/pi/steamware/readParallela.py diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/mpser b/IOB-PI/Jetco/167 - GLD25/steamware/mpser new file mode 100644 index 0000000..444b459 --- /dev/null +++ b/IOB-PI/Jetco/167 - GLD25/steamware/mpser @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/bin/python /home/steamware/readSeriale.py diff --git a/IOB-PI/readFile.py b/IOB-PI/Jetco/167 - GLD25/steamware/readFile.py similarity index 100% rename from IOB-PI/readFile.py rename to IOB-PI/Jetco/167 - GLD25/steamware/readFile.py diff --git a/IOB-PI/readParallela.py b/IOB-PI/Jetco/167 - GLD25/steamware/readParallela.py similarity index 100% rename from IOB-PI/readParallela.py rename to IOB-PI/Jetco/167 - GLD25/steamware/readParallela.py diff --git a/IOB-PI/readSeriale.py b/IOB-PI/Jetco/167 - GLD25/steamware/readSeriale.py similarity index 100% rename from IOB-PI/readSeriale.py rename to IOB-PI/Jetco/167 - GLD25/steamware/readSeriale.py diff --git a/IOB-PI/saveTemp.sh b/IOB-PI/Jetco/167 - GLD25/steamware/saveTemp.sh similarity index 100% rename from IOB-PI/saveTemp.sh rename to IOB-PI/Jetco/167 - GLD25/steamware/saveTemp.sh diff --git a/IOB-PI/sendReboot.py b/IOB-PI/Jetco/167 - GLD25/steamware/sendReboot.py similarity index 100% rename from IOB-PI/sendReboot.py rename to IOB-PI/Jetco/167 - GLD25/steamware/sendReboot.py diff --git a/IOB-PI/sendRebootIOB b/IOB-PI/Jetco/167 - GLD25/steamware/sendRebootIOB similarity index 100% rename from IOB-PI/sendRebootIOB rename to IOB-PI/Jetco/167 - GLD25/steamware/sendRebootIOB diff --git a/IOB-PI/sendRebootIOB.service b/IOB-PI/Jetco/167 - GLD25/steamware/sendRebootIOB.service similarity index 100% rename from IOB-PI/sendRebootIOB.service rename to IOB-PI/Jetco/167 - GLD25/steamware/sendRebootIOB.service diff --git a/IOB-PI/setIobConf.sh b/IOB-PI/Jetco/167 - GLD25/steamware/setIobConf.sh similarity index 100% rename from IOB-PI/setIobConf.sh rename to IOB-PI/Jetco/167 - GLD25/steamware/setIobConf.sh diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/test.py b/IOB-PI/Jetco/167 - GLD25/steamware/test.py new file mode 100644 index 0000000..3145cbe --- /dev/null +++ b/IOB-PI/Jetco/167 - GLD25/steamware/test.py @@ -0,0 +1,31 @@ +import logging + +# set up logging to file - see previous section for more details +logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', + datefmt='%m-%d %H:%M', + filename='test.log', + filemode='w') +# define a Handler which writes INFO messages or higher to the sys.stderr +console = logging.StreamHandler() +console.setLevel(logging.INFO) +# set a format which is simpler for console use +formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') +# tell the handler to use this format +console.setFormatter(formatter) +# add the handler to the root logger +logging.getLogger('').addHandler(console) + +# Now, we can log to the root logger, or any other logger. First the root... +logging.info('Jackdaws love my big sphinx of quartz.') + +# Now, define a couple of other loggers which might represent areas in your +# application: + +logger1 = logging.getLogger('myapp.area1') +logger2 = logging.getLogger('myapp.area2') + +logger1.debug('Quick zephyrs blow, vexing daft Jim.') +logger1.info('How quickly daft jumping zebras vex.') +logger2.warning('Jail zesty vixen who grabbed pay from quack.') +logger2.error('The five boxing wizards jump quickly.') diff --git a/IOB-PI/unix.py b/IOB-PI/Jetco/167 - GLD25/steamware/unix.py similarity index 100% rename from IOB-PI/unix.py rename to IOB-PI/Jetco/167 - GLD25/steamware/unix.py diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/unix.pyc b/IOB-PI/Jetco/167 - GLD25/steamware/unix.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f260e0e0b5b34b2f662943ad64590abfd2dae251 GIT binary patch literal 669 zcma)3%Wl&^6g_urw~d>yV8dfkSz_arvquO)qLd;k2RW%)!lJU`Nto0bN1lmjQCXEA z;3N40J^=0veQX)~-Z}R%_sr1*zkBh|Ur#>Iak~WXZ`e%1uHv6i1G9Tfn9*HcU?xxr z{NRQFGC&pJhG243A>JKHfmMhqayim|)Fj>EvFZ=6d`=7`KSpRfxQNl7fQW32$(h~9Bz1gw+I1w3wlOwz z+eT`;%V2yyEJkmqw|H8d11wB5?o@%!O^imIi*(V|K@5AV!#M*T0%TJ|@pZ>%iWU&~hZw_06h zo2&c7hkUrlt;XqsctL?UpdLlSbU4oL=9_06#ffedn@)@>*G*!YS|wSQ#pWqjos5^s zN3~6qv8DbdlX4?lD^sVt@Qwkzw7OX?m0lK)T*8&4Q~GfG|CaD--BjCJzIJcpC3K0u KxU=7-i2efA4TIVM literal 0 HcmV?d00001 diff --git a/IOB-PI/win.py b/IOB-PI/Jetco/167 - GLD25/steamware/win.py similarity index 100% rename from IOB-PI/win.py rename to IOB-PI/Jetco/167 - GLD25/steamware/win.py diff --git a/IOB-PI/Jetco/167 - GLD25/steamware/win.pyc b/IOB-PI/Jetco/167 - GLD25/steamware/win.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ae9a11e6dca5bd435d4e6baf0fb24c05441229bd GIT binary patch literal 883 zcmbVJO>fgc5S_Kte3%vqR1h3M+XHGOq)3HZg%H$fA)>V-Cso=iQf0;4vc%c7ycM=3KTtxF`MC&Tz z2u%m=00iV8e34m)%9FWLQk`?H_^20kXQ-ecExC z8tq(o^p(*_-Ek}|sIlwDi`M0wBehO7Tc-~J>81-~wm}1SWSb!7qeo;O0e8z%mx3#i z^D~(X$E(vn=7lKvUe|0Of_LY$*@7Pk`(9@oJk+xy7dGYldNOq>LA!-0>t@i#*4$AD zg=R$YX_)N39xnA^au|hZ@9d)_j`okioG91l=V=wviz_yjbuZ10sHzRixoErURcgNM zTJ<~2+OSgv<_WZLdwgg_X~v?QrAp~>SD2~Q#rU8<5asxzRGngRU1tyMSCM7zx+=_P zn~>Yg_glcaXWU$!tA^$wZUI+XLKHVLooQ}#E_tWZ3Csg{_v7&0Ht)+hm&T^*v*0QA zXoZB2%u|3oL$c*pHF*?AJn0<{!rn0EQr&z4JU%9?11i3t{`^^5$OHyTZaHwvv+gC$ r;&SieleGU9@;_U7G1J*R7cX6Jb04tER@iE*wdS)mXaT#24F&8ksVTb- literal 0 HcmV?d00001 diff --git a/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg b/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg new file mode 100644 index 0000000..bdffa78 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg @@ -0,0 +1,35 @@ +[id] +idxMacchina = 3009 + +[web] +URLBASE = http://192.168.1.7/MP/IO/IOB/input/ +URLALIVE = http://192.168.1.7/MP/IO/IOB +URLENABLED = http://192.168.1.7/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://192.168.1.7/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.bck b/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.bck new file mode 100644 index 0000000..aeb9c8a --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.bck @@ -0,0 +1,23 @@ +[id] +idxMacchina = 3009 + +[web] +URLBASE = http://192.168.1.7/MP/IO/inputIOB.aspx?idxMacchina= +URLALIVE = http://192.168.1.7/MP/IO/Alive.aspx +URLENABLED = http://192.168.1.7/MP/IO/Enabled.aspx?idxMacchina= +URLADV1 = &valore= +URLREBO = http://192.168.1.7/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.20 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.50 + +[log] +LOGLEVEL = 10 +LOGFILE = logfile.txt +LOGREBO = logReboot.txt + +[comm] +port = /dev/ttyAMA0 diff --git a/IOB-PI/IOB.cfg b/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.donati similarity index 100% rename from IOB-PI/IOB.cfg rename to IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.donati diff --git a/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.jetco b/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.jetco new file mode 100644 index 0000000..bdffa78 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.jetco @@ -0,0 +1,35 @@ +[id] +idxMacchina = 3009 + +[web] +URLBASE = http://192.168.1.7/MP/IO/IOB/input/ +URLALIVE = http://192.168.1.7/MP/IO/IOB +URLENABLED = http://192.168.1.7/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://192.168.1.7/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.steamware b/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.steamware new file mode 100644 index 0000000..9d9c1de --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/IOB.cfg.steamware @@ -0,0 +1,35 @@ +[id] +idxMacchina = 0001 + +[web] +URLBASE = http://10.74.82.219/MP/IO/IOB/input/ +URLALIVE = http://10.74.82.219/MP/IO/IOB +URLENABLED = http://10.74.82.219/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/Jetco/168 - GD32/steamware/MapoIOB b/IOB-PI/Jetco/168 - GD32/steamware/MapoIOB new file mode 100644 index 0000000..c49ec0a --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/MapoIOB @@ -0,0 +1,41 @@ +### BEGIN INIT INFO +# Provides: MapoIOB: script Steamware per avvio driver IOB +# Required-Start: $remote_fs $syslog ramlog +# Required-Stop: $remote_fs $syslog ramlog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Steamware's MapoIOB driver +# Description: Steamware's MapoIOB driver, versione lettura porta parallela +### END INIT INFO + +#! /bin/sh +# /etc/init.d/MapoIOB + +export HOME +case "$1" in + start) + echo "Starting readParallela" + cd /home/pi/steamware + /usr/bin/python ./readParallela.py 2>&1 & + ;; + stop) + echo "Stopping readParallela" + RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'` + kill -9 $RS_PID + cd /home/pi/steamware + rm .lockfile + ;; + restart) + ## Stop the service and regardless of whether it was + ## running or not, start it again. + $0 stop + killall python + $0 start + ;; + *) + echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}" + exit 1 + ;; +esac +exit 0 + diff --git a/IOB-PI/Jetco/168 - GD32/steamware/MapoIOB_logrot b/IOB-PI/Jetco/168 - GD32/steamware/MapoIOB_logrot new file mode 100644 index 0000000..13410b9 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/MapoIOB_logrot @@ -0,0 +1,28 @@ +/var/log/MapoIOB.log { + size 8M + copytruncate + create 700 pi pi + dateext + rotate 100 + compress + maxage 366 + missingok +} +/var/log/logReboot.txt { + size 1M + copytruncate + create 700 pi pi + dateext + rotate 30 + compress + missingok +} +/var/log/logTemp.txt { + size 1M + copytruncate + create 700 pi pi + dateext + rotate 30 + compress + missingok +} diff --git a/IOB-PI/Jetco/168 - GD32/steamware/checkAlive.sh b/IOB-PI/Jetco/168 - GD32/steamware/checkAlive.sh new file mode 100644 index 0000000..aace73d --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/checkAlive.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia! + +DATE=`date +%Y-%m-%d` +cd /var/log +if [ -f MapoIOB.log ] + then + # controllo SE sia stato acceduto da meno di 2 minuti (=alive da log...) + trovato=`find . -name 'MapoIOB*' -cmin -1` + if [[ $trovato != './MapoIOB.log' ]] + then + /etc/init.d/MapoIOB restart + echo $date + "riavvio!" + fi +else + # in questo caso AVVIO il processo MapoIOB + /etc/init.d/MapoIOB start + echo $date + "file non trovato, avvio!" +fi diff --git a/IOB-PI/Jetco/168 - GD32/steamware/cleanPython.sh b/IOB-PI/Jetco/168 - GD32/steamware/cleanPython.sh new file mode 100644 index 0000000..c4f616a --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/cleanPython.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +DATE=`date +%Y-%m-%d_%T` +# log inizio pulizia +echo $DATE " - INIZIO pulizia processi python" >> clean.log +# effettua pulizia processi: killa tutti i processi python +killall python + +# avvia MapoIob +/etc/init.d/MapoIOB start + +# log fatto! +DATE=`date +%Y-%m-%d_%T` +echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log diff --git a/IOB-PI/Jetco/168 - GD32/steamware/convertLogFile.py b/IOB-PI/Jetco/168 - GD32/steamware/convertLogFile.py new file mode 100644 index 0000000..760c2a9 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/convertLogFile.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# readFile v. 0.1 +# - single instance timer +# - invio multiplo x send eventi accodati +#--------------------------------------------------------------- +import os, sys +import argparse +#-------------------------------------------------------------- + +# gestione parser argomenti in input +parser = argparse.ArgumentParser() +parser.add_argument("inFile") +parser.add_argument("outFile") +args = parser.parse_args() + +#with open('logfile.txt', 'r') as inf, open('persMem.dat',"w") as outf: +with open(args.inFile, 'r') as inf, open(args.outFile,"w") as outf: + data = inf.readlines() + + lastDt = "" + lastMs = 0 + stepMs = 200 + + for line in data: + words = line.split() + if words[2] == 'queue': + # recupero dataOra + newDt = words[0].replace("-","") + words[1].replace(":","") + + # verifico se data/ora identica... + if (lastDt == newDt): + # --> aggiungo stepMs + lastMs += stepMs + else: + lastMs = 0 + + lastDt = newDt + + newDt = newDt + '{:03d}'.format(lastMs) #str(lastMs) + #print words[0].replace("-","") + words[1].replace(":","") + " | " + newDt + "\n" + + # print words + # outf.write(words[0].replace("-","") + words[1].replace(":","") + '#' + words[4].replace(">","") + '#' + words[5].replace("[","").replace("]","") +'\n') + outf.write(newDt + '#' + words[4].replace(">","") + '#' + words[5].replace("[","").replace("]","") +'\n') \ No newline at end of file diff --git a/IOB-PI/Jetco/168 - GD32/steamware/crontab b/IOB-PI/Jetco/168 - GD32/steamware/crontab new file mode 100644 index 0000000..74fe381 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/crontab @@ -0,0 +1 @@ +* * * * * /bin/bash /home/pi/steamware/checkAlive.sh >> /home/pi/stdout 2>> /home/pi/stderr diff --git a/IOB-PI/Jetco/168 - GD32/steamware/install-RPI-IOB.sh b/IOB-PI/Jetco/168 - GD32/steamware/install-RPI-IOB.sh new file mode 100644 index 0000000..7de1dc1 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/install-RPI-IOB.sh @@ -0,0 +1,51 @@ +#|/bin/bash + +#installa il necessario per RPI-3-IOB partendo dal contenuto della folder /home/pi/steamware + +#step 1: creo file di log nuovi +rm /var/log/log*.txt +rm /var/log/MapoIOB* +rm /home/pi/steamware/log*.txt + +touch /var/log/logReboot.txt +touch /var/log/logTemp.txt +touch /var/log/MapoIOB.log + +ln -sf /var/log/logReboot.txt /home/pi/steamware/logReboot.txt +ln -sf /var/log/logTemp.txt /home/pi/steamware/logTemp.txt +ln -sf /var/log/MapoIOB.log /home/pi/steamware/logfile.txt + +chown pi:pi /home/pi -R +chmod 666 /var/log/log*.txt +chmod 666 /var/log/MapoIOB.log + +#step 2: copio files in /usr/local/bin +cd /home/pi/steamware +chmod +x *.sh +cp *.sh /usr/local/bin/ + +#step 3: copio files x logrotate... +cd /home/pi/steamware +cp MapoIOB_logrot /etc/logrotate.d/ + +# step 4: copio target systemd in avvio... +cp -f sendRebootIOB /etc/init.d/sendRebootIOB +cp -f sendRebootIOB.service /etc/systemd/system/sendRebootIOB.service +echo "" +echo "-----------------------------------------------" +echo "Completare registrazione servizio avvio: digitare i seguenti comandi" +echo "systemctl enable sendRebootIOB" +echo "systemctl daemon-reload" +echo "systemctl status sendRebootIOB" +echo "-----------------------------------------------" +echo "" +echo "" +echo "" +echo "-----------------------------------------------" +echo "Infine creare voce crontab che salvi temperatura CPU/GPU ogni 20 minuti..." +echo "crontab -e" +echo "*/20 * * * * /usr/local/bin/saveTemp.sh" +echo "-----------------------------------------------" + + + diff --git a/IOB-PI/Jetco/168 - GD32/steamware/logReboot.txt b/IOB-PI/Jetco/168 - GD32/steamware/logReboot.txt new file mode 100644 index 0000000..44de4d4 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/logReboot.txt @@ -0,0 +1,11 @@ +2018-06-06 13:59:28 root INFO Avvio Programma SendReboot IOB-pi v.1.8 +2018-06-06 13:59:28 root INFO Tentativo invio URL: 1 +2018-06-06 13:59:28 root INFO [Errno socket error] [Errno 101] Network is unreachable +2018-06-06 13:59:31 root INFO Tentativo invio URL: 2 +2018-06-06 13:59:31 root INFO [Errno socket error] [Errno 101] Network is unreachable +2018-06-06 13:59:34 root INFO Tentativo invio URL: 3 +2018-06-06 13:59:34 root INFO [Errno socket error] [Errno 101] Network is unreachable +2018-06-06 13:59:37 root INFO Tentativo invio URL: 4 +2018-06-06 13:59:37 root INFO [Errno socket error] [Errno 101] Network is unreachable +2018-06-06 13:59:40 root INFO Tentativo invio URL: 5 +2018-06-06 13:59:43 root INFO Inviato segnale di reboot!: http://192.168.1.7/MP/IO/sendReboot.aspx?idxMacchina=3009&mac=b8:27:eb:6b:c1:63 diff --git a/IOB-PI/Jetco/168 - GD32/steamware/logTemp.txt b/IOB-PI/Jetco/168 - GD32/steamware/logTemp.txt new file mode 100644 index 0000000..e69de29 diff --git a/IOB-PI/Jetco/168 - GD32/steamware/logfile.txt b/IOB-PI/Jetco/168 - GD32/steamware/logfile.txt new file mode 100644 index 0000000..5be4bc5 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/logfile.txt @@ -0,0 +1,29 @@ +2018-06-06 13:59:28 program INFO Avvio ProgrammaReadPar IOB-pi v.2.0 +2018-06-06 13:59:28 program INFO Start ReadPar IOB-pi v.2.0 +2018-06-06 13:59:28 program INFO Avvio loop principale +2018-06-06 13:59:28 queue INFO 17 [0] +2018-06-06 13:59:28 program ERROR Server Non raggiungibile +2018-06-06 13:59:29 queue INFO >17 [1] +2018-06-06 13:59:39 program INFO IOB ONLINE! +2018-06-06 13:59:39 sendUrl INFO 17 [0] R:OK +2018-06-06 13:59:39 sendUrl INFO 17 [1] R:OK +2018-06-06 13:59:44 queue INFO 57 [2] +2018-06-06 13:59:44 sendUrl INFO 57 [2] R:OK +2018-06-06 13:59:44 queue INFO >57 [3] +2018-06-06 13:59:44 sendUrl INFO 57 [3] R:OK +2018-06-06 13:59:58 queue INFO 53 [4] +2018-06-06 13:59:58 sendUrl INFO 53 [4] R:OK +2018-06-06 13:59:58 queue INFO >53 [5] +2018-06-06 13:59:59 sendUrl INFO 53 [5] R:OK +2018-06-06 14:00:00 queue INFO 57 [6] +2018-06-06 14:00:00 sendUrl INFO 57 [6] R:OK +2018-06-06 14:00:00 queue INFO >57 [7] +2018-06-06 14:00:00 sendUrl INFO 57 [7] R:OK +2018-06-06 14:00:01 queue INFO 77 [8] +2018-06-06 14:00:01 sendUrl INFO 77 [8] R:OK +2018-06-06 14:00:01 queue INFO >77 [9] +2018-06-06 14:00:02 sendUrl INFO 77 [9] R:OK +2018-06-06 14:00:02 queue INFO 57 [10] +2018-06-06 14:00:02 sendUrl INFO 57 [10] R:OK +2018-06-06 14:00:02 queue INFO >57 [11] +2018-06-06 14:00:03 sendUrl INFO 57 [11] R:OK diff --git a/IOB-PI/Jetco/168 - GD32/steamware/mppar b/IOB-PI/Jetco/168 - GD32/steamware/mppar new file mode 100644 index 0000000..b433a73 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/mppar @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/bin/python /home/pi/steamware/readParallela.py diff --git a/IOB-PI/Jetco/168 - GD32/steamware/mpser b/IOB-PI/Jetco/168 - GD32/steamware/mpser new file mode 100644 index 0000000..444b459 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/mpser @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/bin/python /home/steamware/readSeriale.py diff --git a/IOB-PI/Jetco/168 - GD32/steamware/readFile.py b/IOB-PI/Jetco/168 - GD32/steamware/readFile.py new file mode 100644 index 0000000..887118d --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/readFile.py @@ -0,0 +1,152 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# readFile v. 0.1 +# - single instance timer +# - invio multiplo x send eventi accodati + +#--------------------------------------------------------------- + +import time + +from datetime import datetime + +import urllib +import ConfigParser +import os, sys + +import logging +import logging.handlers +import Queue + +import argparse +#-------------------------------------------------------------- + +# gestione parser argomenti in input +parser = argparse.ArgumentParser() +parser.add_argument("memFile") +parser.add_argument("logFile") +args = parser.parse_args() + +#definizione variabili BASE +stepQueuePut=25000 +stepQueueGet=250 +NMAXSEND=500000 # limite invio file x fare prove... +idxMacchina = "2003" + +#-------------------------------------------------------------- +# Gestione coda (condivisa) x registrazione eventi ed invio URL +#print "Creazione coda illimitata" +Coda = Queue.Queue(0) + +#--------------------------------------------------------------- +#Funzione di scrittura su coda con try-except + +def accoda(valore): + + try: + Coda.put(valore) + except Queue.Full: + logPro.error( "Queue full" + dtEve + '#' + value + '#' + cont ) + except: + logPro.error( "NETWORK:Errore http-no com rete-timeout" + url ) + + +#-------------------------------------------------------------- +# svuotaCoda x invio dati al server +def svuota_coda(): + + global NMAXSEND + + try: + if not Coda.empty(): + # invio SOLO i primi NMAXSEND eventi... SE minore del num eventi... + if NMAXSEND > Coda.qsize(): + NMAXSEND = Coda.qsize() + + + i = 0 + + with open(args.logFile,"w") as outf: + while i <= NMAXSEND: + if not Coda.empty(): + + # formatto dataOra corrente + dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] + + #prendo primo elemento dalla coda + resp = Coda.get() + + # recupero valori da elemento coda! + dtEve = resp.split("#")[0] + value = resp.split("#")[1] + cnt = resp.split("#")[2] + url = URLBASE + idxMacchina + URLADV1 + value + url = url + '&dtCurr=' + dtCurr + '&dtEve=' + dtEve + '&cnt=' + cnt + # CHIAMO URL + response3 = urllib.urlopen ( url ) + answ3 = response3.read() + + # registro chiamata + risposta + # outf.write(url + " --> " + answ3 + "\n") + + # incremento e controllo se mostrare output + i += 1 + if (i % stepQueueGet) == 0: + print "Inviati %d valori..." % i + + print "Inviati %d valori..." % i + except: + print "Errore in svuotamento coda!" + + +#--------------------------------------------------------------- +# MAIN + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'IOB.cfg' ) + + # NMAXSEND = config.getint ( 'time' , 'NMAXSEND' ) + # idxMacchina = config.get ( 'id' , 'idxMacchina' ) + + + URLBASE = config.get ( 'web' , 'URLBASE' ) + URLADV1 = config.get ( 'web' , 'URLADV1' ) + + LOGFILE = config.get ( 'log' , 'LOGFILE' ) + LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' ) +except: + print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg' + sys.exit(1) + +#--------------------------------------------------------------- + +dtCurr = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] +print "Inizio elaborazione: %s" % dtCurr + +# Leggo il file! +i = 0 +with open(args.memFile, 'r') as inf, open(args.logFile,"w") as outf: + data = inf.readlines() + + print "Trovate %d da processare..." % len(data) + +# leggo e metto in QUEUE... + for line in data: + accoda(line) + i += 1 + if (i % stepQueuePut) == 0: + print "Accodati %d valori..." % i + +print "Completata lettura file! %d righe accodate da trasmettere" % Coda.qsize() + +dtCurr = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] +print "Inizio invio: %s" % dtCurr + + +# chiamo procedura x svuotare coda... +svuota_coda() + +dtCurr = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] +print "Completato invio: %s" % dtCurr \ No newline at end of file diff --git a/IOB-PI/Jetco/168 - GD32/steamware/readParallela.py b/IOB-PI/Jetco/168 - GD32/steamware/readParallela.py new file mode 100644 index 0000000..6e36bec --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/readParallela.py @@ -0,0 +1,608 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# readParallela v. 2.0 +# - single instance timer +# - invio multiplo x send eventi accodati +# - gestione segnali BLINKING + +#--------------------------------------------------------------- +# levare locking +# timer semplificata +# GPIO global + + +import time +import sys + + +from datetime import datetime + +import urllib +import ConfigParser +import os, sys + +import logging +import logging.handlers +import threading +import Queue + +from array import * + +#-------------------------------------------------------------- + +# COSTANTI +MSGLEN = 9 +TIMEOUTSERIALE = 10 +MAXRETRY = 3 + +# numero campioni filtraggio segnale ballerino +MAX_COUNTER_BLINK = 10 + +PROGRAM_NAME ="ReadPar IOB-pi v.2.0" + +# DA FILE CONF +idxMacchina = "1001" +SAMPLETIME = 0.1 +TIMEOUTSHORT = (SAMPLETIME*20) +TIMEOUTLONG = (SAMPLETIME*600) +SENDURLTIME = 0.08 +NMAXSEND = 5 # numero massimo di invii per singolo ciclo di svuotamento + +# VAR +to_enable = False +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG +to_serial = TIMEOUTSERIALE +to_retry = MAXRETRY +errormsglen = 0 + +# VAR + +out_0 = 24 +out_1 = 26 + +in_0 = 11 +in_1 = 12 +in_2 = 13 +in_3 = 15 +in_4 = 16 +in_5 = 18 +in_6 = 22 +in_7 = 7 + +# contatore: serve x match tra accoda ed invia x possibile controllo a posteriori... ogni volta che accodo incremento di 1, va da 0 a 9999 +cont = '0' + +# variabile stato online/offline della macchina +onLine = '1' + +# variabile stato seinding/waiting x la parte invio URL +sending = '0' + +# variabile stato timer thread busy +timer_busy = False + +# +# array per ingressi filtrati + +i_counters = array ( 'i',[0,0,0,0,0,0,0,0]) +B_blinking = array ( 'B',[0,0,0,0,0,0,0,0]) +B_previous = array ( 'B',[0,0,0,0,0,0,0,0]) +B_input = array ( 'B',[0,0,0,0,0,0,0,0]) +B_output = array ( 'B',[0,0,0,0,0,0,0,0]) + +#-------------------------------------------------------------- +# Gestione coda (condivisa) x registrazione eventi ed invio URL +#print "Creazione coda illimitata" + +Coda = Queue.Queue(0) + +#queueLock = threading.Lock() + +#--------------------------------------------------------------- +# lettura parallela +# ritorna il byte letto pulito ( due char hex ) + +def readParallelaFiltrata(): + + global in_0 + global in_1 + global in_2 + global in_3 + global in_4 + global in_5 + global in_6 + global in_7 + + global GPIO + + current = '' + + + try: + + if GPIO.input(in_0): + B_input[0] = 0 + else: + B_input[0] = 1 + + if GPIO.input(in_1): + B_input[1] = 0 + else: + B_input[1] = 1 + + if GPIO.input(in_2): + B_input[2] = 0 + else: + B_input[2] = 1 + + if GPIO.input(in_3): + B_input[3] = 0 + else: + B_input[3] = 1 + + if GPIO.input(in_4): + B_input[4] = 0 + else: + B_input[4] = 1 + + if GPIO.input(in_5): + B_input[5] = 0 + else: + B_input[5] = 1 + + if GPIO.input(in_6): + B_input[6] = 0 + else: + B_input[6] = 1 + + if GPIO.input(in_7): + B_input[7] = 0 + else: + B_input[7] = 1 + + #ciclo per ogni segnale + for i in xrange(8) : + # print (i) + # se non blinking, copia ingresso + if ( B_blinking[i] == 0 ) : + B_output[i] = B_input[i] + else: + # gestione segnale blinking + # se fronte del segnale + if ( B_previous[i] != B_input[i] ) : + B_previous[i] = B_input[i] + # se fronte di salita + if ( B_input[i] == 1 ) : + # subito uscita = 1 + B_output[i] = 1 + i_counters[i] = MAX_COUNTER_BLINK + #else : + # # loggo che ho rilevato un blink... + # logPro.info("Blink down on bit " + `i`) + else: + # no , segnale eguale a prima + # se input a 0 + if ( B_input[i] == 0 ) : + # E CONTEGGIO IN CORSO + if ( i_counters[i] > 0 ) : + i_counters[i] = i_counters[i] -1 + if ( i_counters[i] == 0 ) : + B_output[i] = 0 + logPro.info("END Blink on bit " + `i` ) + + #Rimettiamo insieme i bit + new_value = 0 + + if ( B_output[0] == 1 ) : + new_value = new_value + 1 + if ( B_output[1] == 1 ) : + new_value = new_value + 2 + if ( B_output[2] == 1 ) : + new_value = new_value + 4 + if ( B_output[3] == 1 ) : + new_value = new_value + 8 + if ( B_output[4] == 1 ) : + new_value = new_value + 16 + if ( B_output[5] == 1 ) : + new_value = new_value + 32 + if ( B_output[6] == 1 ) : + new_value = new_value + 64 + if ( B_output[7] == 1 ) : + new_value = new_value + 128 + + current = hex( new_value ).replace ( "0x" , "" ).upper() + + except: + pass + + return current + +#--------------------------------------------------------------- +#Funzione di scrittura su coda con try-except + +def accoda(): + + try: + dtEve = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] + Coda.put(dtEve + '#' + value + '#' + cont) + + except Queue.Full: + logPro.error( "Queue full" + `dtEve` + '#' + `value` + '#' + `cont` ) + except: + logPro.error( "NETWORK:Errore http-no com rete-timeout" + url ) +# print "Url aforte" , url + + +#-------------------------------------------------------------- +# svuotaCoda x invio dati al server +def svuota_coda(): + + global onLine + global sending + global timer_busy + global NMAXSEND + + #print "start timer " + + if ( timer_busy == False ): + timer_busy = True + #print "start timer ok " + + try: + if not Coda.empty(): + #print "coda da svuotare!" + response = urllib.urlopen(URLALIVE) + answ = response.read() + if answ == 'OK': + #print "OK alive" + response2 = urllib.urlopen(URLENABLED + idxMacchina) + answ2 = response2.read() + if answ2 == 'OK': + # aggiorno stato ad online + if onLine == '0': + logPro.info("IOB ONLINE!") + #print("IOB ONLINE") + + onLine = '1' # imposto comunque online + else: + if onLine == '1': + logPro.error("IOB offline") + #print("IOB offline") + + onLine = '0' + else: + if onLine == '1': + logPro.error("Server offline") + #print("Server offline") + + onLine = '0' + + # ora verifico SE si possa inviare (ovvero sia online server e NON ci siano altri send attivi...) + if onLine == '1': + if sending == '0': + #segnalo che sono in sending! + sending = '1' + + # SAM 2016.12.23: modifica x invio FINO A nMaxSend ELEMENTI ad ogni ciclo di svuotamento + i = NMAXSEND + + while i >= 0: + if not Coda.empty(): + + # formatto dataOra corrente + dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] + + #prendo primo elemento dalla coda + resp = Coda.get() + + # recupero valori da elemento coda! + dtEve = resp.split("#")[0] + value = resp.split("#")[1] + cnt = resp.split("#")[2] + url = URLBASE + idxMacchina + URLADV1 + value + url = url + '&dtCurr=' + dtCurr + '&dtEve=' + dtEve + '&cnt=' + cnt + # CHIAMO URL + response3 = urllib.urlopen ( url ) + answ3 = response3.read() + #print(url) + + # log valore inviato! + logSnd.info( value + ' ['+ cnt +']' + ' R:' + answ3 ) + #print "Valore smaltito dalla coda" + + # tolgo 1 al contatore + i -= 1 + + # completato invio, riporto sending a zero! + sending = '0' + else: + logPro.info("WAIT active send to complete") + + else: + pass + + else: + pass + + except: + if onLine == '1': + logPro.error("Server Non raggiungibile") + #print "Non raggiungibile" + + onLine = '0' + +# in ogni caso + + timer_busy = False + #print "end timer ok" + + + #print "end timer " + + +#--------------------------------------------------------------- +# funzione timer thread +#--------------------------------------------------------------- +def do_every (interval, worker_func, iterations = 0): + if iterations != 1: + threading.Timer ( + interval, + do_every, [interval, worker_func, 0 if iterations == 0 else iterations-1] + ).start (); + + worker_func (); + +#--------------------------------------------------------------- +# gestione contatore +#--------------------------------------------------------------- +def contatore(): + + try: + global cont + ctr = int(cont) + ctr +=1 + ctr = ctr % 10000 # round robin 10000 eventi x track + cont = str(ctr) + except: + print("errore incremento contatore") + +#--------------------------------------------------------------- +# avvia porta parallela +#--------------------------------------------------------------- +def avviaParallela(): + + global in_0 + global in_1 + global in_2 + global in_3 + global in_4 + global in_5 + global in_6 + global in_7 + + global GPIO + + try: + + GPIO.setmode(GPIO.BOARD) + + GPIO.setwarnings(False) + + #GPIO.setup(out_0, GPIO.OUT) # output 0 + #GPIO.setup(out_1, GPIO.OUT) # output 1 + + GPIO.setup(in_0, GPIO.IN) # input 0 + GPIO.setup(in_1, GPIO.IN) # input 1 + GPIO.setup(in_2, GPIO.IN) # input 2 + GPIO.setup(in_3, GPIO.IN) # input 3 + GPIO.setup(in_4, GPIO.IN) # input 4 + GPIO.setup(in_5, GPIO.IN) # input 5 + GPIO.setup(in_6, GPIO.IN) # input 6 + GPIO.setup(in_7, GPIO.IN) # input 7 + + except: + print( "\n\n" + PROGRAM_NAME + " - Error 3 on RPi.GPIO ! \n\n") + sys.exit(1) + + + print( "\n\n" + PROGRAM_NAME + " - init ok \n\n") + + +#--------------------------------------------------------------- +#--------------------------------------------------------------- +# MAIN + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'IOB.cfg' ) + + SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' ) + TIMEOUTSHORT = config.getfloat ( 'time' , 'TIMEOUTSHORT' ) + TIMEOUTLONG = config.getfloat ( 'time' , 'TIMEOUTLONG' ) + SENDURLTIME = config.getfloat ( 'time' , 'SENDURLTIME' ) + NMAXSEND = config.getint ( 'time' , 'NMAXSEND' ) + + idxMacchina = config.get ( 'id' , 'idxMacchina' ) + + + URLBASE = config.get ( 'web' , 'URLBASE' ) + URLENABLED = config.get('web' , 'URLENABLED') + URLALIVE = config.get ('web' , 'URLALIVE') + URLADV1 = config.get ( 'web' , 'URLADV1' ) + + LOGFILE = config.get ( 'log' , 'LOGFILE' ) + LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' ) + + B_blinking[0] = config.getint ( 'blink' , 'bit0' ) + B_blinking[1] = config.getint ( 'blink' , 'bit1' ) + B_blinking[2] = config.getint ( 'blink' , 'bit2' ) + B_blinking[3] = config.getint ( 'blink' , 'bit3' ) + B_blinking[4] = config.getint ( 'blink' , 'bit4' ) + B_blinking[5] = config.getint ( 'blink' , 'bit5' ) + B_blinking[6] = config.getint ( 'blink' , 'bit6' ) + B_blinking[7] = config.getint ( 'blink' , 'bit7' ) + + MAX_COUNTER_BLINK = config.getint ( 'blink' , 'MAX_COUNTER_BLINK' ) + + +except: + print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg' + sys.exit(1) + +#-------------------------------------------- +# oggetto Logger +#-------------------------------------------- +try: + 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' + ) + + # aggiungo 2 logger specifici x queue e send... + logQue = logging.getLogger('queue') + logSnd = logging.getLogger('sendUrl') + logPro = logging.getLogger('program') + +except: + # manda mail o simili - FARE!!! + print "LOG: Impossibile creare file log con nome " + print (LOGFILE) +#-------------------------------------------- + + +print "\n\n" + PROGRAM_NAME + "\n\n" + +global startstatus +startstatus = 1 + +if startstatus == 1: + logPro.info("Avvio Programma" + PROGRAM_NAME) + +## Verifica l'OS e di conseguenza carica il file relativo con metodo di lockfile appropriato + check singola istanza +if os.name == 'posix': + import unix +else: + import win + +logPro.info( "Start " + PROGRAM_NAME ) + + +# lettura file configurazione + +# [id] +# idxMacchina = 2001 +# [time] +# SAMPLETIME = 0.1 +# TIMEOUTSHORT = 200 +# TIMEOUTLONG = 6000 + + +print ( ' idxMacchina = %s' % ( idxMacchina ) ) +print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) ) +print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) ) +print ( ' TIMEOUTLONG = %4.2f' % ( TIMEOUTLONG ) ) +print ( ' SENDURLTIME = %4.2f' % ( SENDURLTIME ) ) +print ( ' URLBASE = %s' % ( URLBASE ) ) +print ( ' URLADV1 = %s' % ( URLADV1 ) ) +print ( ' LOGFILE = %s' % ( LOGFILE ) ) +print ( ' LOGLEVEL = %s' % ( LOGLEVEL ) ) + +# -sys.stdout.write ( 'idxMacchina ?' + idxMacchina + '\n') + +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG + + +#-------------------------------------------------------------- +# apertura parallela + +try: + import RPi.GPIO as GPIO +except RuntimeError: + print( "\n\n" + PROGRAM_NAME + " - Error 1 - you need superuser privileges") +except: + print( "\n\n" + PROGRAM_NAME + " - Error 2 - you need superuser privileges. USE 'sudo' to run your script\n\n") + sys.exit(1) + + +avviaParallela() + + +#-------------------------------------------------------------- +# MARCO: qui inserire avvio thread di "svuotaCoda" + +# avviaSvuotaCoda +#print "Avvia svuota coda" + +do_every ( SENDURLTIME , svuota_coda ); + +#--------------------------------------------------------------- +# ciclo forever and ever + +old = '' + +#print "Avvio ciclo" +logPro.info("Avvio loop principale") +while 1: + + try: + time.sleep (SAMPLETIME) + except: + logPro.info("First_SLEEP: errore attesa sampletime") + + # lettura dati da IOB + value = readParallelaFiltrata() + + if ( value != '' ) : + if value != old : + #loggo e invio dati + try: + logQue.info( value + ' ['+ cont +']') + errormsglen = 0 + accoda() + contatore() + except: + logPro.error("URLBROWSER: errore registrazione valore e accoda") + pass + #enable e reset timer + to_enable = True + to_short = TIMEOUTSHORT + to_long = TIMEOUTLONG + + old = value + + + # gestione timeout breve + if ( to_enable ) : + to_short = to_short - SAMPLETIME + if to_short <= 0: + #loggo e invio dati + try: + logQue.info( '>' + value + ' ['+ cont +']') + errormsglen = 0 + accoda() + contatore() + except: + logPro.error("URLBROWSER: errore registrazione valore e accoda TO_short") + pass + to_short = TIMEOUTSHORT + to_enable = False # dopo un colpo il timer breve viene disabilitato + to_long = TIMEOUTLONG + + # gestione timeout lungo + to_long = to_long - SAMPLETIME + if to_long <= 0: + #loggo e invio dati + try: + logQue.info( '>>' + value + ' ['+ cont +']') + errormsglen = 0 + accoda() + contatore() + except: + logPro.error("URLBROWSER: errore registrazione valore e accoda TO_long") + pass + to_long = TIMEOUTLONG diff --git a/IOB-PI/Jetco/168 - GD32/steamware/readSeriale.py b/IOB-PI/Jetco/168 - GD32/steamware/readSeriale.py new file mode 100644 index 0000000..3c00644 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/readSeriale.py @@ -0,0 +1,363 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +#--------------------------------------------------------------- + +import serial +import time +import sys +import datetime +import urllib +import ConfigParser +import os, sys + +#--------------------------------------------------------------- + +# COSTANTI +MSGLEN = 9 +TIMEOUTSERIALE = 10 +MAXRETRY = 3 + +# DA FILE CONF +idxMacchina = "2001" +SAMPLETIME = 0.1 +TIMEOUTSHORT = (SAMPLETIME*20) +TIMEOUTLONG = (SAMPLETIME*600) + +# VAR +to_enable = False +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG +to_serial = TIMEOUTSERIALE +to_retry = MAXRETRY +errormsglen = 0 + +#--------------------------------------------------------------- +# classe logger + +class Logger: + def __init__(self, filename): + try: + self.filename = filename + except: + logga("LOGGER: errore try su self.filename") + sys.exit(1) + def __call__(self, string): + try: + file = open(self.filename, 'a') + file.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + '] ') + file.write(string + '\n') + file.close() + except: + logga("LOGGER: errore try su scrittura") + sys.exit(1) + +#--------------------------------------------------------------- +# lettura buffer seriale e pulizia caratteri non stampabili +# ritorna '' se non c'è un messaggio buono o il messaggio pulito ( due bytes hex ) +# il messaggio ha il formato xxi00 00xxx + +def readSeriale(): + + global to_serial + global to_retry + global errormsglen + + ret = '' + current = '' + i = 0 + + # ritorna '' se non ci sono abbastanza caratteri + try: + if ser.inWaiting() < MSGLEN : +# +# to_serial = to_serial - 1 # se non mi risponde, faccio un ' altra richiesta.... +# if to_serial <= 0: +# try: +# requestData () +# except: +# logga("SERIALE: errore su requestData") +# sys.exit(1) +# to_serial = TIMEOUTSERIALE # ripristino timer +# to_retry = to_retry - 1 # contatore retry +# if to_retry <= 0: +# logga ( 'IOB not responding' ) +# return ret + logga("SERIALE: errore msglen < 9 char - Errore no. " + str(errormsglen)) + errormsglen = errormsglen +1 + avviaSeriale() + time.sleep(.2) + if errormsglen > 30: + sys.exit(1) + except: + if startstatus == 0: + logga ("Porta SERIALE non disponibile - ser.inWaiting error - exit... - Errore no. " + str(errormsglen)) + errormsglen = errormsglen +1 + avviaSeriale() + time.sleep(.2) + if errormsglen > 30: + sys.exit(1) + + # finchè c'è robba .. leggi e tieni i buoni + to_serial = TIMEOUTSERIALE + to_retry = MAXRETRY + try: + while ser.inWaiting() > 0 : + try: + c = ser.read(1) + except: + logga("SERIALE: errore su try ser.read") + sys.exit(1) + # filtra caratteri non stampabili + if c > ' ' : + current += c + #sys.stdout.write(current + '<<<<\n') + # ora il messaggio ha il formato xxxxxi00 00xxx : cerco la 'i' iniziale + try: + while i < len(current) and current[i] != 'i': + i = i + 1 + except: + logga("SERIALE: errore su ricerca i iniziale") + sys.exit(1) + # se non ho trovato la 'i' restituisco '' + if i == len(current)-1: + return ret + else: + current = current[i+1:i+3] + # richiesta dati ad IOB + requestData() + #sys.stdout.write ( current + '\n') + except: + if startstatus == 0: + logga ('Porta SERIALE non disponibile - ser.inWaiting e filtraggio error...exit') + sys.exit(1) + return current +#--------------------------------------------------------------- +# richiesta dati ad IOB : scrittura su seriale + +def requestData (): + try : + ser.write ("$i" + '\r\n') + ser.flush() + except : + if startstatus == 0: + logga ( "SERIAL: Errore di scrittura/flush") + + +#--------------------------------------------------------------- +#Funzione di scrittura su url con try-except + +def chiamaUrl(): + try: + url = URLBASE + idxMacchina + URLADV1 + value + urllib.urlopen ( url ) + except: + logga ( "NETWORK:Errore http-no com rete-timeout" + url ) + + +#--------------------------------------------------------------- +# Funzione che verifica possibilità di creare log e include testo corrente + +def logga(message) : + try: + log(message) + except : + pass + +#--------------------------------------------------------------- + + +def avviaSeriale(): + global ser + + try: + ser = serial.Serial( + port = comm_port , + baudrate = 9600 , + parity = serial.PARITY_NONE , + stopbits = serial.STOPBITS_ONE , + bytesize = serial.EIGHTBITS + ) + startstatus = 0 + except serial.serialutil.SerialException , e : + try: + if startstatus == 0: + logga ( "SERIAL:Errore apertura seriale - " + comm_port) + except: + pass + sys.stdout.write ( '\nErrore apertura seriale\n\n%s\n\n' % e ) + if errormsglen > 30: + sys.exit (1) + +#--------------------------------------------------------------- +#--------------------------------------------------------------- +# MAIN + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'readSeriale.cfg' ) + + SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' ) + TIMEOUTSHORT = config.getfloat ( 'time' , 'TIMEOUTSHORT' ) + TIMEOUTLONG = config.getfloat ( 'time' , 'TIMEOUTLONG' ) + + idxMacchina = config.get ( 'id' , 'idxMacchina' ) + comm_port = config.get ( 'comm' , 'port' ) + + URLBASE = config.get ( 'web' , 'URLBASE' ) + URLADV1 = config.get ( 'web' , 'URLADV1' ) + + LOGFILE = config.get ( 'log' , 'LOGFILE' ) + LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' ) +except: + sys.exit(1) + +# oggetto Logger +try: + log = Logger(LOGFILE) +except: + # manda mail o simili - FARE!!! + print "LOG: Impossibile creare file log con nome " + print (LOGFILE) + +print '\n\n Read seriale IOB v.0.2 !!!!\n' + +global startstatus +startstatus = 1 + +if startstatus == 1: + logga("Avvio Programma") + +# Verifica l'OS e di conseguenza carica il file relativo con metodo di lockfile appropriato + check singola istanza +if os.name == 'posix': + import unix +else: + import win + +logga ( "Start Read seriale IOB v.0.2") + + +# lettura file configurazione + +# [comm] +# port = /dev/ttyS0 +# [id] +# idxMacchina = 2001 +# [time] +# SAMPLETIME = 0.1 +# TIMEOUTSHORT = 200 +# TIMEOUTLONG = 6000 + +print ( ' comm_port = %s' % ( comm_port ) ) +print ( ' idxMacchina = %s' % ( idxMacchina ) ) +print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) ) +print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) ) +print ( ' TIMEOUTLONG = %4.2f' % ( TIMEOUTLONG ) ) +print ( ' URLBASE = %s' % ( URLBASE ) ) +print ( ' URLADV1 = %s' % ( URLADV1 ) ) +print ( ' LOGFILE = %s' % ( LOGFILE ) ) +print ( ' LOGLEVEL = %s' % ( LOGLEVEL ) ) + +# -sys.stdout.write ( 'idxMacchina ?' + idxMacchina + '\n') + +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG + + + +#-------------------------------------------------------------- + + +#--------------------------------------------------------------- +# apertura seriale + +avviaSeriale() + +#try: +# ser = serial.Serial( +# port = comm_port , +# baudrate = 9600 , +# parity = serial.PARITY_NONE , +# stopbits = serial.STOPBITS_ONE , +# bytesize = serial.EIGHTBITS +# ) +# print "Initialized!" +#except serial.serialutil.SerialException , e : +# try: +# logga ( "SERIAL:Errore apertura seriale - " + comm_port) +# except: +# pass +# sys.stdout.write ( '\nErrore apertura seriale\n\n%s\n\n' % e ) +# sys.exit (1) + +#--------------------------------------------------------------- +# ciclo forever and ever + +old = '' + +# richiesta dati ad IOB +try: + requestData() +except: + logga("SERIALE: errore sul try di requestData") + sys.exit(1) + + +while 1: + try: + time.sleep (SAMPLETIME) + except: + logga("SERIALE_SLEEP: errore attesa sampletime") + # lettura dati da IOB + try: + value = readSeriale() + except: + if startstatus == 0: + logga("errore PRIMA LETTURA SERIALE") + sys.exit(1) + if ( value != '' ) : + if value != old : + #loggo e invio dati + try: + logga ( value ) + errormsglen = 0 + chiamaUrl() + except: + logga("URLBROWSER: errore registrazione valore e chiamaUrl") + pass + #enable e reset timer + to_enable = True + to_short = TIMEOUTSHORT + to_long = TIMEOUTLONG + + old = value + + + # gestione timeout breve + if ( to_enable ) : + to_short = to_short - SAMPLETIME + if to_short <= 0: + #loggo e invio dati + try: + logga ( '>' + value ) + errormsglen = 0 + chiamaUrl() + except: + pass + to_short = TIMEOUTSHORT + to_enable = False # dopo un colpo il timer breve viene disabilitato + to_long = TIMEOUTLONG + + # gestione timeout lungo + to_long = to_long - SAMPLETIME + if to_long <= 0: + #loggo e invio dati + try: + logga ( '>>' + value ) + errormsglen = 0 + chiamaUrl() + except: + pass + to_long = TIMEOUTLONG + + diff --git a/IOB-PI/Jetco/168 - GD32/steamware/saveTemp.sh b/IOB-PI/Jetco/168 - GD32/steamware/saveTemp.sh new file mode 100644 index 0000000..a2cd2be --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/saveTemp.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +#salva la temperatura CPU e GPU su chiamata... + +# imposto logfile... +logFile="/var/log/logTemp.txt" + +cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp) +cpuTemp1=$(($cpuTemp0/1000)) +cpuTemp2=$(($cpuTemp0/100)) +cpuTempM=$(($cpuTemp2 % $cpuTemp1)) + +gpuTemp=`vcgencmd measure_temp` + +loadAvg=`cat /proc/loadavg` + +echo "$(date) | CPU: temp=$cpuTemp1.$cpuTempM ºC | GPU: $gpuTemp | LoadAvg: $loadAvg" >> $logFile diff --git a/IOB-PI/Jetco/168 - GD32/steamware/sendReboot.py b/IOB-PI/Jetco/168 - GD32/steamware/sendReboot.py new file mode 100644 index 0000000..021c400 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/sendReboot.py @@ -0,0 +1,130 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# sendReboot v. 1.8 + +#--------------------------------------------------------------- + + +import time +import sys + + +from datetime import datetime + +import urllib +import ConfigParser +import os, sys + +import logging + +import time + +#--------------------------------------------------------------- + +# COSTANTI +PROGRAM_NAME = "SendReboot IOB-pi v.1.8" + +# DA FILE CONF +idxMacchina = "99" + +# registro se ho fatto chiamata +global numTry +numTry = 1 + + +#--------------------------------------------------------------- +#Funzione di scrittura su url con try-except +#--------------------------------------------------------------- + +def chiamaUrl(numTry): + + try: + urllib.urlopen ( url ) + numTry = numTry + 10 + except Exception, e: + print e + logging.info ( e ) + print "Url aforte" , 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] + +#--------------------------------------------------------------- +# MAIN +#--------------------------------------------------------------- + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'IOB.cfg' ) + + idxMacchina = config.get ( 'id' , 'idxMacchina' ) + + + 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) + + +#-------------------------------------------- +# oggetto Logger +#-------------------------------------------- +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') + +except: + # manda mail o simili - FARE!!! + print "LOG: Impossibile creare file log con nome " + print (LOGFILE) +#-------------------------------------------- + + +print "\n\n" + PROGRAM_NAME + "\n\n" + +global startstatus +startstatus = 1 + +if startstatus == 1: + logging.info("Avvio Programma " + PROGRAM_NAME) + + +# lettura file configurazione +print ( ' idxMacchina = %s' % ( idxMacchina ) ) +print ( ' URLREBO = %s' % ( URLREBO ) ) +print ( ' LOGFILE = %s' % ( LOGFILE ) ) + +# lettura mac address +myMac = getMAC('eth0') +print ( ' MAC Address = %s' % ( myMac ) ) + +# configuro URL da inviare +url = URLREBO + idxMacchina + "&mac=" + myMac + +# modifica: cerco se ho inviato segnale altrimenti ritento invio... +while (numTry < 11): + logging.info("Tentativo invio URL: " + `numTry` ) + numTry = chiamaUrl(numTry) + time.sleep(3) + numTry = numTry + 1 + + +# registro che ho inviato! +logging.info("Inviato segnale di reboot!: " + url ) diff --git a/IOB-PI/Jetco/168 - GD32/steamware/sendRebootIOB b/IOB-PI/Jetco/168 - GD32/steamware/sendRebootIOB new file mode 100644 index 0000000..191bfff --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/sendRebootIOB @@ -0,0 +1,33 @@ +#!/bin/sh - +# +### BEGIN INIT INFO +# Provides: sendReboot +# Required-Start: $network $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Steamware's IOB reboot signal +# Description: Steamware's sendReboot segnalazione reboot dispositivo +### END INIT INFO + +#! /bin/sh +# /etc/init.d/sendReboot + + + +export HOME +case "$1" in + start) + cd /home/pi/steamware + echo "Starting sendReboot" + /usr/bin/python ./sendReboot.py 2>&1 & + echo "Verifica Rete e file IOB" + /usr/local/bin/setIobConf.sh + ;; + *) + echo "Usage: /etc/init.d/sendReboot {start}" + exit 1 + ;; +esac +exit 0 + diff --git a/IOB-PI/Jetco/168 - GD32/steamware/sendRebootIOB.service b/IOB-PI/Jetco/168 - GD32/steamware/sendRebootIOB.service new file mode 100644 index 0000000..48e3690 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/sendRebootIOB.service @@ -0,0 +1,22 @@ +[Unit] +SourcePath=/etc/init.d/sendRebootIOB +Description=LSB: Steamware's IOB reboot signal +Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target +Wants=network-online.target +After=network.target network-online.target auditd.service +Conflicts=shutdown.target + +[Service] +Type=forking +Restart=no +TimeoutSec=5min +IgnoreSIGPIPE=no +KillMode=process +GuessMainPID=no +RemainAfterExit=yes +SysVStartPriority=2 +ExecStart=/etc/init.d/sendRebootIOB start +ExecStop=/etc/init.d/sendRebootIOB stop + +[Install] +WantedBy=multi-user.target diff --git a/IOB-PI/Jetco/168 - GD32/steamware/setIobConf.sh b/IOB-PI/Jetco/168 - GD32/steamware/setIobConf.sh new file mode 100644 index 0000000..30b4781 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/setIobConf.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# verifico se sia rete donati o rete steamware o offline... +netStatus=`cat /sys/class/net/eth0/operstate` +iaddr=`ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1` + +cd /home/pi/steamware + +if [[ $netStatus != "up" ]] +then + echo "Siamo Offline, pagina demo!" +elif [[ $iaddr == "10.74.82"* ]] +then + cp IOB.cfg.steamware IOB.cfg -f + echo "Siamo in Steamware!" +elif [[ $iaddr == "192.168.51"* ]] +then + cp IOB.cfg.donati IOB.cfg -f + echo "Siamo a Passirano!" +else + echo "Siamo altrove, pagina demo!" +fi + +echo "$iaddr" + +chown pi:pi * \ No newline at end of file diff --git a/IOB-PI/Jetco/168 - GD32/steamware/test.py b/IOB-PI/Jetco/168 - GD32/steamware/test.py new file mode 100644 index 0000000..3145cbe --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/test.py @@ -0,0 +1,31 @@ +import logging + +# set up logging to file - see previous section for more details +logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', + datefmt='%m-%d %H:%M', + filename='test.log', + filemode='w') +# define a Handler which writes INFO messages or higher to the sys.stderr +console = logging.StreamHandler() +console.setLevel(logging.INFO) +# set a format which is simpler for console use +formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') +# tell the handler to use this format +console.setFormatter(formatter) +# add the handler to the root logger +logging.getLogger('').addHandler(console) + +# Now, we can log to the root logger, or any other logger. First the root... +logging.info('Jackdaws love my big sphinx of quartz.') + +# Now, define a couple of other loggers which might represent areas in your +# application: + +logger1 = logging.getLogger('myapp.area1') +logger2 = logging.getLogger('myapp.area2') + +logger1.debug('Quick zephyrs blow, vexing daft Jim.') +logger1.info('How quickly daft jumping zebras vex.') +logger2.warning('Jail zesty vixen who grabbed pay from quack.') +logger2.error('The five boxing wizards jump quickly.') diff --git a/IOB-PI/Jetco/168 - GD32/steamware/unix.py b/IOB-PI/Jetco/168 - GD32/steamware/unix.py new file mode 100644 index 0000000..12fb3dc --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/unix.py @@ -0,0 +1,31 @@ +import fcntl +import os +import logging + +#--------------------------------------------------------------- +# meccanismo di file lock per evitare multiple instances +# The function will try to lock the file specified , if it success, return True, else return False. +# The nice thing is that the lock will be dropped when the program terminates. +# >>>Use : +# if not lockFile(".lock.pod"): +# sys.exit(0) + +def lockFile ( lockfile ) : + + fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY ) + try: + # Request exclusive (EX) non-blocking (NB) advisory lock. + fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB ) + except IOError: + return False + + return True + +if not lockFile ( ".lockfile" ) : + print '\n noi non siamo soli ...\n' + logging.error( "LOCK: Piu istanze aperte") + #sys.exit ( 0 ) + +#- print '\n running alone ...\n' + + diff --git a/IOB-PI/Jetco/168 - GD32/steamware/unix.pyc b/IOB-PI/Jetco/168 - GD32/steamware/unix.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d8c62fae828461914e26706511ad1c8bc7e176e2 GIT binary patch literal 669 zcma)3%Wl&^6g_urw~d>yV8dfkSz_arvquO)qLd;k2RW%)!lJU`Nto0bN1lmjQCXFL z;1}8R0dQyNW6Rk0&bg1dXO1TL-HU(zdh&UW+a-8^!)6M075{`9nB8N-jPCLRGl5Fr z2R8(e0jdBu1e2o*@$N_ptU^?g%aQh@Cg~23ReyNpb7JV|BDNu$VHQ|mMY#S4gbxD@ zTsFkuM&LW)>Hs#vY6sWk!LIjvzD%e3F+$tHMU3_YL}X)3&g?!WspHGjt|M`@jj^HI zHd5PN2IKQ#F?u__#na*>AKE>iKP|@j@h9d47ISTDkLqTAvGC2uVIk0vcFM%V`aJiTDG#k)#@_a zT-_f&wR;;cp-cS5 Jo&7FF^cU=FgW~`I literal 0 HcmV?d00001 diff --git a/IOB-PI/Jetco/168 - GD32/steamware/win.py b/IOB-PI/Jetco/168 - GD32/steamware/win.py new file mode 100644 index 0000000..f679f60 --- /dev/null +++ b/IOB-PI/Jetco/168 - GD32/steamware/win.py @@ -0,0 +1,32 @@ +import win32api +print " Running on WINDOWS\n" +import os +#--------------------------------------------------------------- +# meccanismo di file lock per evitare multiple instances +# The function will try to lock the file specified , if it success, return True, else return False. +# The nice thing is that the lock will be dropped when the program terminates. +# >>>Use : +# if not lockFile(".lock.pod"): +# sys.exit(0) + +def lockFile ( lockfile ) : + try: + fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY ) + except: + logga("Errore nel file WIN.PY per FD") + try: + # Request exclusive (EX) non-blocking (NB) advisory lock. + #fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB ) + print " Dummy Method! Completa Lockfile\n" + except IOError: + return False + + return True +try: + if not lockFile ( ".lockfile" ) : + print '\n noi non siamo soli ...\n' + logga ( "LOCK: Piu istanze aperte") + sys.exit ( 0 ) +except: + logga("if not lockfile NON RIUSCITO in file WIN.PY") + sys.exit(1) diff --git a/IOB-PI/Jetco/168 - GD32/steamware/win.pyc b/IOB-PI/Jetco/168 - GD32/steamware/win.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ae9a11e6dca5bd435d4e6baf0fb24c05441229bd GIT binary patch literal 883 zcmbVJO>fgc5S_Kte3%vqR1h3M+XHGOq)3HZg%H$fA)>V-Cso=iQf0;4vc%c7ycM=3KTtxF`MC&Tz z2u%m=00iV8e34m)%9FWLQk`?H_^20kXQ-ecExC z8tq(o^p(*_-Ek}|sIlwDi`M0wBehO7Tc-~J>81-~wm}1SWSb!7qeo;O0e8z%mx3#i z^D~(X$E(vn=7lKvUe|0Of_LY$*@7Pk`(9@oJk+xy7dGYldNOq>LA!-0>t@i#*4$AD zg=R$YX_)N39xnA^au|hZ@9d)_j`okioG91l=V=wviz_yjbuZ10sHzRixoErURcgNM zTJ<~2+OSgv<_WZLdwgg_X~v?QrAp~>SD2~Q#rU8<5asxzRGngRU1tyMSCM7zx+=_P zn~>Yg_glcaXWU$!tA^$wZUI+XLKHVLooQ}#E_tWZ3Csg{_v7&0Ht)+hm&T^*v*0QA zXoZB2%u|3oL$c*pHF*?AJn0<{!rn0EQr&z4JU%9?11i3t{`^^5$OHyTZaHwvv+gC$ r;&SieleGU9@;_U7G1J*R7cX6Jb04tER@iE*wdS)mXaT#24F&8ksVTb- literal 0 HcmV?d00001 diff --git a/IOB-PI/Jetco/std_v_2/IOB.cfg.donati b/IOB-PI/Jetco/std_v_2/IOB.cfg.donati new file mode 100644 index 0000000..29c3d61 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/IOB.cfg.donati @@ -0,0 +1,35 @@ +[id] +idxMacchina = 2007 + +[web] +URLBASE = http://192.168.51.77/MP/IO/IOB/input/ +URLALIVE = http://192.168.51.77/MP/IO/IOB +URLENABLED = http://192.168.51.77/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://192.168.51.77/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/Jetco/std_v_2/IOB.cfg.steamware b/IOB-PI/Jetco/std_v_2/IOB.cfg.steamware new file mode 100644 index 0000000..9d9c1de --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/IOB.cfg.steamware @@ -0,0 +1,35 @@ +[id] +idxMacchina = 0001 + +[web] +URLBASE = http://10.74.82.219/MP/IO/IOB/input/ +URLALIVE = http://10.74.82.219/MP/IO/IOB +URLENABLED = http://10.74.82.219/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/Jetco/std_v_2/MapoIOB b/IOB-PI/Jetco/std_v_2/MapoIOB new file mode 100644 index 0000000..c49ec0a --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/MapoIOB @@ -0,0 +1,41 @@ +### BEGIN INIT INFO +# Provides: MapoIOB: script Steamware per avvio driver IOB +# Required-Start: $remote_fs $syslog ramlog +# Required-Stop: $remote_fs $syslog ramlog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Steamware's MapoIOB driver +# Description: Steamware's MapoIOB driver, versione lettura porta parallela +### END INIT INFO + +#! /bin/sh +# /etc/init.d/MapoIOB + +export HOME +case "$1" in + start) + echo "Starting readParallela" + cd /home/pi/steamware + /usr/bin/python ./readParallela.py 2>&1 & + ;; + stop) + echo "Stopping readParallela" + RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'` + kill -9 $RS_PID + cd /home/pi/steamware + rm .lockfile + ;; + restart) + ## Stop the service and regardless of whether it was + ## running or not, start it again. + $0 stop + killall python + $0 start + ;; + *) + echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}" + exit 1 + ;; +esac +exit 0 + diff --git a/IOB-PI/Jetco/std_v_2/MapoIOB_logrot b/IOB-PI/Jetco/std_v_2/MapoIOB_logrot new file mode 100644 index 0000000..13410b9 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/MapoIOB_logrot @@ -0,0 +1,28 @@ +/var/log/MapoIOB.log { + size 8M + copytruncate + create 700 pi pi + dateext + rotate 100 + compress + maxage 366 + missingok +} +/var/log/logReboot.txt { + size 1M + copytruncate + create 700 pi pi + dateext + rotate 30 + compress + missingok +} +/var/log/logTemp.txt { + size 1M + copytruncate + create 700 pi pi + dateext + rotate 30 + compress + missingok +} diff --git a/IOB-PI/Jetco/std_v_2/checkAlive.sh b/IOB-PI/Jetco/std_v_2/checkAlive.sh new file mode 100644 index 0000000..aace73d --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/checkAlive.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia! + +DATE=`date +%Y-%m-%d` +cd /var/log +if [ -f MapoIOB.log ] + then + # controllo SE sia stato acceduto da meno di 2 minuti (=alive da log...) + trovato=`find . -name 'MapoIOB*' -cmin -1` + if [[ $trovato != './MapoIOB.log' ]] + then + /etc/init.d/MapoIOB restart + echo $date + "riavvio!" + fi +else + # in questo caso AVVIO il processo MapoIOB + /etc/init.d/MapoIOB start + echo $date + "file non trovato, avvio!" +fi diff --git a/IOB-PI/Jetco/std_v_2/cleanPython.sh b/IOB-PI/Jetco/std_v_2/cleanPython.sh new file mode 100644 index 0000000..c4f616a --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/cleanPython.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +DATE=`date +%Y-%m-%d_%T` +# log inizio pulizia +echo $DATE " - INIZIO pulizia processi python" >> clean.log +# effettua pulizia processi: killa tutti i processi python +killall python + +# avvia MapoIob +/etc/init.d/MapoIOB start + +# log fatto! +DATE=`date +%Y-%m-%d_%T` +echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log diff --git a/IOB-PI/Jetco/std_v_2/convertLogFile.py b/IOB-PI/Jetco/std_v_2/convertLogFile.py new file mode 100644 index 0000000..760c2a9 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/convertLogFile.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# readFile v. 0.1 +# - single instance timer +# - invio multiplo x send eventi accodati +#--------------------------------------------------------------- +import os, sys +import argparse +#-------------------------------------------------------------- + +# gestione parser argomenti in input +parser = argparse.ArgumentParser() +parser.add_argument("inFile") +parser.add_argument("outFile") +args = parser.parse_args() + +#with open('logfile.txt', 'r') as inf, open('persMem.dat',"w") as outf: +with open(args.inFile, 'r') as inf, open(args.outFile,"w") as outf: + data = inf.readlines() + + lastDt = "" + lastMs = 0 + stepMs = 200 + + for line in data: + words = line.split() + if words[2] == 'queue': + # recupero dataOra + newDt = words[0].replace("-","") + words[1].replace(":","") + + # verifico se data/ora identica... + if (lastDt == newDt): + # --> aggiungo stepMs + lastMs += stepMs + else: + lastMs = 0 + + lastDt = newDt + + newDt = newDt + '{:03d}'.format(lastMs) #str(lastMs) + #print words[0].replace("-","") + words[1].replace(":","") + " | " + newDt + "\n" + + # print words + # outf.write(words[0].replace("-","") + words[1].replace(":","") + '#' + words[4].replace(">","") + '#' + words[5].replace("[","").replace("]","") +'\n') + outf.write(newDt + '#' + words[4].replace(">","") + '#' + words[5].replace("[","").replace("]","") +'\n') \ No newline at end of file diff --git a/IOB-PI/Jetco/std_v_2/crontab b/IOB-PI/Jetco/std_v_2/crontab new file mode 100644 index 0000000..74fe381 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/crontab @@ -0,0 +1 @@ +* * * * * /bin/bash /home/pi/steamware/checkAlive.sh >> /home/pi/stdout 2>> /home/pi/stderr diff --git a/IOB-PI/Jetco/std_v_2/install-RPI-IOB.sh b/IOB-PI/Jetco/std_v_2/install-RPI-IOB.sh new file mode 100644 index 0000000..7de1dc1 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/install-RPI-IOB.sh @@ -0,0 +1,51 @@ +#|/bin/bash + +#installa il necessario per RPI-3-IOB partendo dal contenuto della folder /home/pi/steamware + +#step 1: creo file di log nuovi +rm /var/log/log*.txt +rm /var/log/MapoIOB* +rm /home/pi/steamware/log*.txt + +touch /var/log/logReboot.txt +touch /var/log/logTemp.txt +touch /var/log/MapoIOB.log + +ln -sf /var/log/logReboot.txt /home/pi/steamware/logReboot.txt +ln -sf /var/log/logTemp.txt /home/pi/steamware/logTemp.txt +ln -sf /var/log/MapoIOB.log /home/pi/steamware/logfile.txt + +chown pi:pi /home/pi -R +chmod 666 /var/log/log*.txt +chmod 666 /var/log/MapoIOB.log + +#step 2: copio files in /usr/local/bin +cd /home/pi/steamware +chmod +x *.sh +cp *.sh /usr/local/bin/ + +#step 3: copio files x logrotate... +cd /home/pi/steamware +cp MapoIOB_logrot /etc/logrotate.d/ + +# step 4: copio target systemd in avvio... +cp -f sendRebootIOB /etc/init.d/sendRebootIOB +cp -f sendRebootIOB.service /etc/systemd/system/sendRebootIOB.service +echo "" +echo "-----------------------------------------------" +echo "Completare registrazione servizio avvio: digitare i seguenti comandi" +echo "systemctl enable sendRebootIOB" +echo "systemctl daemon-reload" +echo "systemctl status sendRebootIOB" +echo "-----------------------------------------------" +echo "" +echo "" +echo "" +echo "-----------------------------------------------" +echo "Infine creare voce crontab che salvi temperatura CPU/GPU ogni 20 minuti..." +echo "crontab -e" +echo "*/20 * * * * /usr/local/bin/saveTemp.sh" +echo "-----------------------------------------------" + + + diff --git a/IOB-PI/Jetco/std_v_2/readFile.py b/IOB-PI/Jetco/std_v_2/readFile.py new file mode 100644 index 0000000..887118d --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/readFile.py @@ -0,0 +1,152 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# readFile v. 0.1 +# - single instance timer +# - invio multiplo x send eventi accodati + +#--------------------------------------------------------------- + +import time + +from datetime import datetime + +import urllib +import ConfigParser +import os, sys + +import logging +import logging.handlers +import Queue + +import argparse +#-------------------------------------------------------------- + +# gestione parser argomenti in input +parser = argparse.ArgumentParser() +parser.add_argument("memFile") +parser.add_argument("logFile") +args = parser.parse_args() + +#definizione variabili BASE +stepQueuePut=25000 +stepQueueGet=250 +NMAXSEND=500000 # limite invio file x fare prove... +idxMacchina = "2003" + +#-------------------------------------------------------------- +# Gestione coda (condivisa) x registrazione eventi ed invio URL +#print "Creazione coda illimitata" +Coda = Queue.Queue(0) + +#--------------------------------------------------------------- +#Funzione di scrittura su coda con try-except + +def accoda(valore): + + try: + Coda.put(valore) + except Queue.Full: + logPro.error( "Queue full" + dtEve + '#' + value + '#' + cont ) + except: + logPro.error( "NETWORK:Errore http-no com rete-timeout" + url ) + + +#-------------------------------------------------------------- +# svuotaCoda x invio dati al server +def svuota_coda(): + + global NMAXSEND + + try: + if not Coda.empty(): + # invio SOLO i primi NMAXSEND eventi... SE minore del num eventi... + if NMAXSEND > Coda.qsize(): + NMAXSEND = Coda.qsize() + + + i = 0 + + with open(args.logFile,"w") as outf: + while i <= NMAXSEND: + if not Coda.empty(): + + # formatto dataOra corrente + dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] + + #prendo primo elemento dalla coda + resp = Coda.get() + + # recupero valori da elemento coda! + dtEve = resp.split("#")[0] + value = resp.split("#")[1] + cnt = resp.split("#")[2] + url = URLBASE + idxMacchina + URLADV1 + value + url = url + '&dtCurr=' + dtCurr + '&dtEve=' + dtEve + '&cnt=' + cnt + # CHIAMO URL + response3 = urllib.urlopen ( url ) + answ3 = response3.read() + + # registro chiamata + risposta + # outf.write(url + " --> " + answ3 + "\n") + + # incremento e controllo se mostrare output + i += 1 + if (i % stepQueueGet) == 0: + print "Inviati %d valori..." % i + + print "Inviati %d valori..." % i + except: + print "Errore in svuotamento coda!" + + +#--------------------------------------------------------------- +# MAIN + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'IOB.cfg' ) + + # NMAXSEND = config.getint ( 'time' , 'NMAXSEND' ) + # idxMacchina = config.get ( 'id' , 'idxMacchina' ) + + + URLBASE = config.get ( 'web' , 'URLBASE' ) + URLADV1 = config.get ( 'web' , 'URLADV1' ) + + LOGFILE = config.get ( 'log' , 'LOGFILE' ) + LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' ) +except: + print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg' + sys.exit(1) + +#--------------------------------------------------------------- + +dtCurr = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] +print "Inizio elaborazione: %s" % dtCurr + +# Leggo il file! +i = 0 +with open(args.memFile, 'r') as inf, open(args.logFile,"w") as outf: + data = inf.readlines() + + print "Trovate %d da processare..." % len(data) + +# leggo e metto in QUEUE... + for line in data: + accoda(line) + i += 1 + if (i % stepQueuePut) == 0: + print "Accodati %d valori..." % i + +print "Completata lettura file! %d righe accodate da trasmettere" % Coda.qsize() + +dtCurr = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] +print "Inizio invio: %s" % dtCurr + + +# chiamo procedura x svuotare coda... +svuota_coda() + +dtCurr = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] +print "Completato invio: %s" % dtCurr \ No newline at end of file diff --git a/IOB-PI/Jetco/std_v_2/readParallela.py b/IOB-PI/Jetco/std_v_2/readParallela.py new file mode 100644 index 0000000..6e36bec --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/readParallela.py @@ -0,0 +1,608 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# readParallela v. 2.0 +# - single instance timer +# - invio multiplo x send eventi accodati +# - gestione segnali BLINKING + +#--------------------------------------------------------------- +# levare locking +# timer semplificata +# GPIO global + + +import time +import sys + + +from datetime import datetime + +import urllib +import ConfigParser +import os, sys + +import logging +import logging.handlers +import threading +import Queue + +from array import * + +#-------------------------------------------------------------- + +# COSTANTI +MSGLEN = 9 +TIMEOUTSERIALE = 10 +MAXRETRY = 3 + +# numero campioni filtraggio segnale ballerino +MAX_COUNTER_BLINK = 10 + +PROGRAM_NAME ="ReadPar IOB-pi v.2.0" + +# DA FILE CONF +idxMacchina = "1001" +SAMPLETIME = 0.1 +TIMEOUTSHORT = (SAMPLETIME*20) +TIMEOUTLONG = (SAMPLETIME*600) +SENDURLTIME = 0.08 +NMAXSEND = 5 # numero massimo di invii per singolo ciclo di svuotamento + +# VAR +to_enable = False +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG +to_serial = TIMEOUTSERIALE +to_retry = MAXRETRY +errormsglen = 0 + +# VAR + +out_0 = 24 +out_1 = 26 + +in_0 = 11 +in_1 = 12 +in_2 = 13 +in_3 = 15 +in_4 = 16 +in_5 = 18 +in_6 = 22 +in_7 = 7 + +# contatore: serve x match tra accoda ed invia x possibile controllo a posteriori... ogni volta che accodo incremento di 1, va da 0 a 9999 +cont = '0' + +# variabile stato online/offline della macchina +onLine = '1' + +# variabile stato seinding/waiting x la parte invio URL +sending = '0' + +# variabile stato timer thread busy +timer_busy = False + +# +# array per ingressi filtrati + +i_counters = array ( 'i',[0,0,0,0,0,0,0,0]) +B_blinking = array ( 'B',[0,0,0,0,0,0,0,0]) +B_previous = array ( 'B',[0,0,0,0,0,0,0,0]) +B_input = array ( 'B',[0,0,0,0,0,0,0,0]) +B_output = array ( 'B',[0,0,0,0,0,0,0,0]) + +#-------------------------------------------------------------- +# Gestione coda (condivisa) x registrazione eventi ed invio URL +#print "Creazione coda illimitata" + +Coda = Queue.Queue(0) + +#queueLock = threading.Lock() + +#--------------------------------------------------------------- +# lettura parallela +# ritorna il byte letto pulito ( due char hex ) + +def readParallelaFiltrata(): + + global in_0 + global in_1 + global in_2 + global in_3 + global in_4 + global in_5 + global in_6 + global in_7 + + global GPIO + + current = '' + + + try: + + if GPIO.input(in_0): + B_input[0] = 0 + else: + B_input[0] = 1 + + if GPIO.input(in_1): + B_input[1] = 0 + else: + B_input[1] = 1 + + if GPIO.input(in_2): + B_input[2] = 0 + else: + B_input[2] = 1 + + if GPIO.input(in_3): + B_input[3] = 0 + else: + B_input[3] = 1 + + if GPIO.input(in_4): + B_input[4] = 0 + else: + B_input[4] = 1 + + if GPIO.input(in_5): + B_input[5] = 0 + else: + B_input[5] = 1 + + if GPIO.input(in_6): + B_input[6] = 0 + else: + B_input[6] = 1 + + if GPIO.input(in_7): + B_input[7] = 0 + else: + B_input[7] = 1 + + #ciclo per ogni segnale + for i in xrange(8) : + # print (i) + # se non blinking, copia ingresso + if ( B_blinking[i] == 0 ) : + B_output[i] = B_input[i] + else: + # gestione segnale blinking + # se fronte del segnale + if ( B_previous[i] != B_input[i] ) : + B_previous[i] = B_input[i] + # se fronte di salita + if ( B_input[i] == 1 ) : + # subito uscita = 1 + B_output[i] = 1 + i_counters[i] = MAX_COUNTER_BLINK + #else : + # # loggo che ho rilevato un blink... + # logPro.info("Blink down on bit " + `i`) + else: + # no , segnale eguale a prima + # se input a 0 + if ( B_input[i] == 0 ) : + # E CONTEGGIO IN CORSO + if ( i_counters[i] > 0 ) : + i_counters[i] = i_counters[i] -1 + if ( i_counters[i] == 0 ) : + B_output[i] = 0 + logPro.info("END Blink on bit " + `i` ) + + #Rimettiamo insieme i bit + new_value = 0 + + if ( B_output[0] == 1 ) : + new_value = new_value + 1 + if ( B_output[1] == 1 ) : + new_value = new_value + 2 + if ( B_output[2] == 1 ) : + new_value = new_value + 4 + if ( B_output[3] == 1 ) : + new_value = new_value + 8 + if ( B_output[4] == 1 ) : + new_value = new_value + 16 + if ( B_output[5] == 1 ) : + new_value = new_value + 32 + if ( B_output[6] == 1 ) : + new_value = new_value + 64 + if ( B_output[7] == 1 ) : + new_value = new_value + 128 + + current = hex( new_value ).replace ( "0x" , "" ).upper() + + except: + pass + + return current + +#--------------------------------------------------------------- +#Funzione di scrittura su coda con try-except + +def accoda(): + + try: + dtEve = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] + Coda.put(dtEve + '#' + value + '#' + cont) + + except Queue.Full: + logPro.error( "Queue full" + `dtEve` + '#' + `value` + '#' + `cont` ) + except: + logPro.error( "NETWORK:Errore http-no com rete-timeout" + url ) +# print "Url aforte" , url + + +#-------------------------------------------------------------- +# svuotaCoda x invio dati al server +def svuota_coda(): + + global onLine + global sending + global timer_busy + global NMAXSEND + + #print "start timer " + + if ( timer_busy == False ): + timer_busy = True + #print "start timer ok " + + try: + if not Coda.empty(): + #print "coda da svuotare!" + response = urllib.urlopen(URLALIVE) + answ = response.read() + if answ == 'OK': + #print "OK alive" + response2 = urllib.urlopen(URLENABLED + idxMacchina) + answ2 = response2.read() + if answ2 == 'OK': + # aggiorno stato ad online + if onLine == '0': + logPro.info("IOB ONLINE!") + #print("IOB ONLINE") + + onLine = '1' # imposto comunque online + else: + if onLine == '1': + logPro.error("IOB offline") + #print("IOB offline") + + onLine = '0' + else: + if onLine == '1': + logPro.error("Server offline") + #print("Server offline") + + onLine = '0' + + # ora verifico SE si possa inviare (ovvero sia online server e NON ci siano altri send attivi...) + if onLine == '1': + if sending == '0': + #segnalo che sono in sending! + sending = '1' + + # SAM 2016.12.23: modifica x invio FINO A nMaxSend ELEMENTI ad ogni ciclo di svuotamento + i = NMAXSEND + + while i >= 0: + if not Coda.empty(): + + # formatto dataOra corrente + dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] + + #prendo primo elemento dalla coda + resp = Coda.get() + + # recupero valori da elemento coda! + dtEve = resp.split("#")[0] + value = resp.split("#")[1] + cnt = resp.split("#")[2] + url = URLBASE + idxMacchina + URLADV1 + value + url = url + '&dtCurr=' + dtCurr + '&dtEve=' + dtEve + '&cnt=' + cnt + # CHIAMO URL + response3 = urllib.urlopen ( url ) + answ3 = response3.read() + #print(url) + + # log valore inviato! + logSnd.info( value + ' ['+ cnt +']' + ' R:' + answ3 ) + #print "Valore smaltito dalla coda" + + # tolgo 1 al contatore + i -= 1 + + # completato invio, riporto sending a zero! + sending = '0' + else: + logPro.info("WAIT active send to complete") + + else: + pass + + else: + pass + + except: + if onLine == '1': + logPro.error("Server Non raggiungibile") + #print "Non raggiungibile" + + onLine = '0' + +# in ogni caso + + timer_busy = False + #print "end timer ok" + + + #print "end timer " + + +#--------------------------------------------------------------- +# funzione timer thread +#--------------------------------------------------------------- +def do_every (interval, worker_func, iterations = 0): + if iterations != 1: + threading.Timer ( + interval, + do_every, [interval, worker_func, 0 if iterations == 0 else iterations-1] + ).start (); + + worker_func (); + +#--------------------------------------------------------------- +# gestione contatore +#--------------------------------------------------------------- +def contatore(): + + try: + global cont + ctr = int(cont) + ctr +=1 + ctr = ctr % 10000 # round robin 10000 eventi x track + cont = str(ctr) + except: + print("errore incremento contatore") + +#--------------------------------------------------------------- +# avvia porta parallela +#--------------------------------------------------------------- +def avviaParallela(): + + global in_0 + global in_1 + global in_2 + global in_3 + global in_4 + global in_5 + global in_6 + global in_7 + + global GPIO + + try: + + GPIO.setmode(GPIO.BOARD) + + GPIO.setwarnings(False) + + #GPIO.setup(out_0, GPIO.OUT) # output 0 + #GPIO.setup(out_1, GPIO.OUT) # output 1 + + GPIO.setup(in_0, GPIO.IN) # input 0 + GPIO.setup(in_1, GPIO.IN) # input 1 + GPIO.setup(in_2, GPIO.IN) # input 2 + GPIO.setup(in_3, GPIO.IN) # input 3 + GPIO.setup(in_4, GPIO.IN) # input 4 + GPIO.setup(in_5, GPIO.IN) # input 5 + GPIO.setup(in_6, GPIO.IN) # input 6 + GPIO.setup(in_7, GPIO.IN) # input 7 + + except: + print( "\n\n" + PROGRAM_NAME + " - Error 3 on RPi.GPIO ! \n\n") + sys.exit(1) + + + print( "\n\n" + PROGRAM_NAME + " - init ok \n\n") + + +#--------------------------------------------------------------- +#--------------------------------------------------------------- +# MAIN + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'IOB.cfg' ) + + SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' ) + TIMEOUTSHORT = config.getfloat ( 'time' , 'TIMEOUTSHORT' ) + TIMEOUTLONG = config.getfloat ( 'time' , 'TIMEOUTLONG' ) + SENDURLTIME = config.getfloat ( 'time' , 'SENDURLTIME' ) + NMAXSEND = config.getint ( 'time' , 'NMAXSEND' ) + + idxMacchina = config.get ( 'id' , 'idxMacchina' ) + + + URLBASE = config.get ( 'web' , 'URLBASE' ) + URLENABLED = config.get('web' , 'URLENABLED') + URLALIVE = config.get ('web' , 'URLALIVE') + URLADV1 = config.get ( 'web' , 'URLADV1' ) + + LOGFILE = config.get ( 'log' , 'LOGFILE' ) + LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' ) + + B_blinking[0] = config.getint ( 'blink' , 'bit0' ) + B_blinking[1] = config.getint ( 'blink' , 'bit1' ) + B_blinking[2] = config.getint ( 'blink' , 'bit2' ) + B_blinking[3] = config.getint ( 'blink' , 'bit3' ) + B_blinking[4] = config.getint ( 'blink' , 'bit4' ) + B_blinking[5] = config.getint ( 'blink' , 'bit5' ) + B_blinking[6] = config.getint ( 'blink' , 'bit6' ) + B_blinking[7] = config.getint ( 'blink' , 'bit7' ) + + MAX_COUNTER_BLINK = config.getint ( 'blink' , 'MAX_COUNTER_BLINK' ) + + +except: + print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg' + sys.exit(1) + +#-------------------------------------------- +# oggetto Logger +#-------------------------------------------- +try: + 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' + ) + + # aggiungo 2 logger specifici x queue e send... + logQue = logging.getLogger('queue') + logSnd = logging.getLogger('sendUrl') + logPro = logging.getLogger('program') + +except: + # manda mail o simili - FARE!!! + print "LOG: Impossibile creare file log con nome " + print (LOGFILE) +#-------------------------------------------- + + +print "\n\n" + PROGRAM_NAME + "\n\n" + +global startstatus +startstatus = 1 + +if startstatus == 1: + logPro.info("Avvio Programma" + PROGRAM_NAME) + +## Verifica l'OS e di conseguenza carica il file relativo con metodo di lockfile appropriato + check singola istanza +if os.name == 'posix': + import unix +else: + import win + +logPro.info( "Start " + PROGRAM_NAME ) + + +# lettura file configurazione + +# [id] +# idxMacchina = 2001 +# [time] +# SAMPLETIME = 0.1 +# TIMEOUTSHORT = 200 +# TIMEOUTLONG = 6000 + + +print ( ' idxMacchina = %s' % ( idxMacchina ) ) +print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) ) +print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) ) +print ( ' TIMEOUTLONG = %4.2f' % ( TIMEOUTLONG ) ) +print ( ' SENDURLTIME = %4.2f' % ( SENDURLTIME ) ) +print ( ' URLBASE = %s' % ( URLBASE ) ) +print ( ' URLADV1 = %s' % ( URLADV1 ) ) +print ( ' LOGFILE = %s' % ( LOGFILE ) ) +print ( ' LOGLEVEL = %s' % ( LOGLEVEL ) ) + +# -sys.stdout.write ( 'idxMacchina ?' + idxMacchina + '\n') + +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG + + +#-------------------------------------------------------------- +# apertura parallela + +try: + import RPi.GPIO as GPIO +except RuntimeError: + print( "\n\n" + PROGRAM_NAME + " - Error 1 - you need superuser privileges") +except: + print( "\n\n" + PROGRAM_NAME + " - Error 2 - you need superuser privileges. USE 'sudo' to run your script\n\n") + sys.exit(1) + + +avviaParallela() + + +#-------------------------------------------------------------- +# MARCO: qui inserire avvio thread di "svuotaCoda" + +# avviaSvuotaCoda +#print "Avvia svuota coda" + +do_every ( SENDURLTIME , svuota_coda ); + +#--------------------------------------------------------------- +# ciclo forever and ever + +old = '' + +#print "Avvio ciclo" +logPro.info("Avvio loop principale") +while 1: + + try: + time.sleep (SAMPLETIME) + except: + logPro.info("First_SLEEP: errore attesa sampletime") + + # lettura dati da IOB + value = readParallelaFiltrata() + + if ( value != '' ) : + if value != old : + #loggo e invio dati + try: + logQue.info( value + ' ['+ cont +']') + errormsglen = 0 + accoda() + contatore() + except: + logPro.error("URLBROWSER: errore registrazione valore e accoda") + pass + #enable e reset timer + to_enable = True + to_short = TIMEOUTSHORT + to_long = TIMEOUTLONG + + old = value + + + # gestione timeout breve + if ( to_enable ) : + to_short = to_short - SAMPLETIME + if to_short <= 0: + #loggo e invio dati + try: + logQue.info( '>' + value + ' ['+ cont +']') + errormsglen = 0 + accoda() + contatore() + except: + logPro.error("URLBROWSER: errore registrazione valore e accoda TO_short") + pass + to_short = TIMEOUTSHORT + to_enable = False # dopo un colpo il timer breve viene disabilitato + to_long = TIMEOUTLONG + + # gestione timeout lungo + to_long = to_long - SAMPLETIME + if to_long <= 0: + #loggo e invio dati + try: + logQue.info( '>>' + value + ' ['+ cont +']') + errormsglen = 0 + accoda() + contatore() + except: + logPro.error("URLBROWSER: errore registrazione valore e accoda TO_long") + pass + to_long = TIMEOUTLONG diff --git a/IOB-PI/Jetco/std_v_2/readSeriale.py b/IOB-PI/Jetco/std_v_2/readSeriale.py new file mode 100644 index 0000000..3c00644 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/readSeriale.py @@ -0,0 +1,363 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +#--------------------------------------------------------------- + +import serial +import time +import sys +import datetime +import urllib +import ConfigParser +import os, sys + +#--------------------------------------------------------------- + +# COSTANTI +MSGLEN = 9 +TIMEOUTSERIALE = 10 +MAXRETRY = 3 + +# DA FILE CONF +idxMacchina = "2001" +SAMPLETIME = 0.1 +TIMEOUTSHORT = (SAMPLETIME*20) +TIMEOUTLONG = (SAMPLETIME*600) + +# VAR +to_enable = False +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG +to_serial = TIMEOUTSERIALE +to_retry = MAXRETRY +errormsglen = 0 + +#--------------------------------------------------------------- +# classe logger + +class Logger: + def __init__(self, filename): + try: + self.filename = filename + except: + logga("LOGGER: errore try su self.filename") + sys.exit(1) + def __call__(self, string): + try: + file = open(self.filename, 'a') + file.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + '] ') + file.write(string + '\n') + file.close() + except: + logga("LOGGER: errore try su scrittura") + sys.exit(1) + +#--------------------------------------------------------------- +# lettura buffer seriale e pulizia caratteri non stampabili +# ritorna '' se non c'è un messaggio buono o il messaggio pulito ( due bytes hex ) +# il messaggio ha il formato xxi00 00xxx + +def readSeriale(): + + global to_serial + global to_retry + global errormsglen + + ret = '' + current = '' + i = 0 + + # ritorna '' se non ci sono abbastanza caratteri + try: + if ser.inWaiting() < MSGLEN : +# +# to_serial = to_serial - 1 # se non mi risponde, faccio un ' altra richiesta.... +# if to_serial <= 0: +# try: +# requestData () +# except: +# logga("SERIALE: errore su requestData") +# sys.exit(1) +# to_serial = TIMEOUTSERIALE # ripristino timer +# to_retry = to_retry - 1 # contatore retry +# if to_retry <= 0: +# logga ( 'IOB not responding' ) +# return ret + logga("SERIALE: errore msglen < 9 char - Errore no. " + str(errormsglen)) + errormsglen = errormsglen +1 + avviaSeriale() + time.sleep(.2) + if errormsglen > 30: + sys.exit(1) + except: + if startstatus == 0: + logga ("Porta SERIALE non disponibile - ser.inWaiting error - exit... - Errore no. " + str(errormsglen)) + errormsglen = errormsglen +1 + avviaSeriale() + time.sleep(.2) + if errormsglen > 30: + sys.exit(1) + + # finchè c'è robba .. leggi e tieni i buoni + to_serial = TIMEOUTSERIALE + to_retry = MAXRETRY + try: + while ser.inWaiting() > 0 : + try: + c = ser.read(1) + except: + logga("SERIALE: errore su try ser.read") + sys.exit(1) + # filtra caratteri non stampabili + if c > ' ' : + current += c + #sys.stdout.write(current + '<<<<\n') + # ora il messaggio ha il formato xxxxxi00 00xxx : cerco la 'i' iniziale + try: + while i < len(current) and current[i] != 'i': + i = i + 1 + except: + logga("SERIALE: errore su ricerca i iniziale") + sys.exit(1) + # se non ho trovato la 'i' restituisco '' + if i == len(current)-1: + return ret + else: + current = current[i+1:i+3] + # richiesta dati ad IOB + requestData() + #sys.stdout.write ( current + '\n') + except: + if startstatus == 0: + logga ('Porta SERIALE non disponibile - ser.inWaiting e filtraggio error...exit') + sys.exit(1) + return current +#--------------------------------------------------------------- +# richiesta dati ad IOB : scrittura su seriale + +def requestData (): + try : + ser.write ("$i" + '\r\n') + ser.flush() + except : + if startstatus == 0: + logga ( "SERIAL: Errore di scrittura/flush") + + +#--------------------------------------------------------------- +#Funzione di scrittura su url con try-except + +def chiamaUrl(): + try: + url = URLBASE + idxMacchina + URLADV1 + value + urllib.urlopen ( url ) + except: + logga ( "NETWORK:Errore http-no com rete-timeout" + url ) + + +#--------------------------------------------------------------- +# Funzione che verifica possibilità di creare log e include testo corrente + +def logga(message) : + try: + log(message) + except : + pass + +#--------------------------------------------------------------- + + +def avviaSeriale(): + global ser + + try: + ser = serial.Serial( + port = comm_port , + baudrate = 9600 , + parity = serial.PARITY_NONE , + stopbits = serial.STOPBITS_ONE , + bytesize = serial.EIGHTBITS + ) + startstatus = 0 + except serial.serialutil.SerialException , e : + try: + if startstatus == 0: + logga ( "SERIAL:Errore apertura seriale - " + comm_port) + except: + pass + sys.stdout.write ( '\nErrore apertura seriale\n\n%s\n\n' % e ) + if errormsglen > 30: + sys.exit (1) + +#--------------------------------------------------------------- +#--------------------------------------------------------------- +# MAIN + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'readSeriale.cfg' ) + + SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' ) + TIMEOUTSHORT = config.getfloat ( 'time' , 'TIMEOUTSHORT' ) + TIMEOUTLONG = config.getfloat ( 'time' , 'TIMEOUTLONG' ) + + idxMacchina = config.get ( 'id' , 'idxMacchina' ) + comm_port = config.get ( 'comm' , 'port' ) + + URLBASE = config.get ( 'web' , 'URLBASE' ) + URLADV1 = config.get ( 'web' , 'URLADV1' ) + + LOGFILE = config.get ( 'log' , 'LOGFILE' ) + LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' ) +except: + sys.exit(1) + +# oggetto Logger +try: + log = Logger(LOGFILE) +except: + # manda mail o simili - FARE!!! + print "LOG: Impossibile creare file log con nome " + print (LOGFILE) + +print '\n\n Read seriale IOB v.0.2 !!!!\n' + +global startstatus +startstatus = 1 + +if startstatus == 1: + logga("Avvio Programma") + +# Verifica l'OS e di conseguenza carica il file relativo con metodo di lockfile appropriato + check singola istanza +if os.name == 'posix': + import unix +else: + import win + +logga ( "Start Read seriale IOB v.0.2") + + +# lettura file configurazione + +# [comm] +# port = /dev/ttyS0 +# [id] +# idxMacchina = 2001 +# [time] +# SAMPLETIME = 0.1 +# TIMEOUTSHORT = 200 +# TIMEOUTLONG = 6000 + +print ( ' comm_port = %s' % ( comm_port ) ) +print ( ' idxMacchina = %s' % ( idxMacchina ) ) +print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) ) +print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) ) +print ( ' TIMEOUTLONG = %4.2f' % ( TIMEOUTLONG ) ) +print ( ' URLBASE = %s' % ( URLBASE ) ) +print ( ' URLADV1 = %s' % ( URLADV1 ) ) +print ( ' LOGFILE = %s' % ( LOGFILE ) ) +print ( ' LOGLEVEL = %s' % ( LOGLEVEL ) ) + +# -sys.stdout.write ( 'idxMacchina ?' + idxMacchina + '\n') + +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG + + + +#-------------------------------------------------------------- + + +#--------------------------------------------------------------- +# apertura seriale + +avviaSeriale() + +#try: +# ser = serial.Serial( +# port = comm_port , +# baudrate = 9600 , +# parity = serial.PARITY_NONE , +# stopbits = serial.STOPBITS_ONE , +# bytesize = serial.EIGHTBITS +# ) +# print "Initialized!" +#except serial.serialutil.SerialException , e : +# try: +# logga ( "SERIAL:Errore apertura seriale - " + comm_port) +# except: +# pass +# sys.stdout.write ( '\nErrore apertura seriale\n\n%s\n\n' % e ) +# sys.exit (1) + +#--------------------------------------------------------------- +# ciclo forever and ever + +old = '' + +# richiesta dati ad IOB +try: + requestData() +except: + logga("SERIALE: errore sul try di requestData") + sys.exit(1) + + +while 1: + try: + time.sleep (SAMPLETIME) + except: + logga("SERIALE_SLEEP: errore attesa sampletime") + # lettura dati da IOB + try: + value = readSeriale() + except: + if startstatus == 0: + logga("errore PRIMA LETTURA SERIALE") + sys.exit(1) + if ( value != '' ) : + if value != old : + #loggo e invio dati + try: + logga ( value ) + errormsglen = 0 + chiamaUrl() + except: + logga("URLBROWSER: errore registrazione valore e chiamaUrl") + pass + #enable e reset timer + to_enable = True + to_short = TIMEOUTSHORT + to_long = TIMEOUTLONG + + old = value + + + # gestione timeout breve + if ( to_enable ) : + to_short = to_short - SAMPLETIME + if to_short <= 0: + #loggo e invio dati + try: + logga ( '>' + value ) + errormsglen = 0 + chiamaUrl() + except: + pass + to_short = TIMEOUTSHORT + to_enable = False # dopo un colpo il timer breve viene disabilitato + to_long = TIMEOUTLONG + + # gestione timeout lungo + to_long = to_long - SAMPLETIME + if to_long <= 0: + #loggo e invio dati + try: + logga ( '>>' + value ) + errormsglen = 0 + chiamaUrl() + except: + pass + to_long = TIMEOUTLONG + + diff --git a/IOB-PI/Jetco/std_v_2/saveTemp.sh b/IOB-PI/Jetco/std_v_2/saveTemp.sh new file mode 100644 index 0000000..a2cd2be --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/saveTemp.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +#salva la temperatura CPU e GPU su chiamata... + +# imposto logfile... +logFile="/var/log/logTemp.txt" + +cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp) +cpuTemp1=$(($cpuTemp0/1000)) +cpuTemp2=$(($cpuTemp0/100)) +cpuTempM=$(($cpuTemp2 % $cpuTemp1)) + +gpuTemp=`vcgencmd measure_temp` + +loadAvg=`cat /proc/loadavg` + +echo "$(date) | CPU: temp=$cpuTemp1.$cpuTempM ºC | GPU: $gpuTemp | LoadAvg: $loadAvg" >> $logFile diff --git a/IOB-PI/Jetco/std_v_2/sendReboot.py b/IOB-PI/Jetco/std_v_2/sendReboot.py new file mode 100644 index 0000000..021c400 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/sendReboot.py @@ -0,0 +1,130 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# sendReboot v. 1.8 + +#--------------------------------------------------------------- + + +import time +import sys + + +from datetime import datetime + +import urllib +import ConfigParser +import os, sys + +import logging + +import time + +#--------------------------------------------------------------- + +# COSTANTI +PROGRAM_NAME = "SendReboot IOB-pi v.1.8" + +# DA FILE CONF +idxMacchina = "99" + +# registro se ho fatto chiamata +global numTry +numTry = 1 + + +#--------------------------------------------------------------- +#Funzione di scrittura su url con try-except +#--------------------------------------------------------------- + +def chiamaUrl(numTry): + + try: + urllib.urlopen ( url ) + numTry = numTry + 10 + except Exception, e: + print e + logging.info ( e ) + print "Url aforte" , 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] + +#--------------------------------------------------------------- +# MAIN +#--------------------------------------------------------------- + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'IOB.cfg' ) + + idxMacchina = config.get ( 'id' , 'idxMacchina' ) + + + 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) + + +#-------------------------------------------- +# oggetto Logger +#-------------------------------------------- +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') + +except: + # manda mail o simili - FARE!!! + print "LOG: Impossibile creare file log con nome " + print (LOGFILE) +#-------------------------------------------- + + +print "\n\n" + PROGRAM_NAME + "\n\n" + +global startstatus +startstatus = 1 + +if startstatus == 1: + logging.info("Avvio Programma " + PROGRAM_NAME) + + +# lettura file configurazione +print ( ' idxMacchina = %s' % ( idxMacchina ) ) +print ( ' URLREBO = %s' % ( URLREBO ) ) +print ( ' LOGFILE = %s' % ( LOGFILE ) ) + +# lettura mac address +myMac = getMAC('eth0') +print ( ' MAC Address = %s' % ( myMac ) ) + +# configuro URL da inviare +url = URLREBO + idxMacchina + "&mac=" + myMac + +# modifica: cerco se ho inviato segnale altrimenti ritento invio... +while (numTry < 11): + logging.info("Tentativo invio URL: " + `numTry` ) + numTry = chiamaUrl(numTry) + time.sleep(3) + numTry = numTry + 1 + + +# registro che ho inviato! +logging.info("Inviato segnale di reboot!: " + url ) diff --git a/IOB-PI/Jetco/std_v_2/sendRebootIOB b/IOB-PI/Jetco/std_v_2/sendRebootIOB new file mode 100644 index 0000000..191bfff --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/sendRebootIOB @@ -0,0 +1,33 @@ +#!/bin/sh - +# +### BEGIN INIT INFO +# Provides: sendReboot +# Required-Start: $network $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Steamware's IOB reboot signal +# Description: Steamware's sendReboot segnalazione reboot dispositivo +### END INIT INFO + +#! /bin/sh +# /etc/init.d/sendReboot + + + +export HOME +case "$1" in + start) + cd /home/pi/steamware + echo "Starting sendReboot" + /usr/bin/python ./sendReboot.py 2>&1 & + echo "Verifica Rete e file IOB" + /usr/local/bin/setIobConf.sh + ;; + *) + echo "Usage: /etc/init.d/sendReboot {start}" + exit 1 + ;; +esac +exit 0 + diff --git a/IOB-PI/Jetco/std_v_2/sendRebootIOB.service b/IOB-PI/Jetco/std_v_2/sendRebootIOB.service new file mode 100644 index 0000000..48e3690 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/sendRebootIOB.service @@ -0,0 +1,22 @@ +[Unit] +SourcePath=/etc/init.d/sendRebootIOB +Description=LSB: Steamware's IOB reboot signal +Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target +Wants=network-online.target +After=network.target network-online.target auditd.service +Conflicts=shutdown.target + +[Service] +Type=forking +Restart=no +TimeoutSec=5min +IgnoreSIGPIPE=no +KillMode=process +GuessMainPID=no +RemainAfterExit=yes +SysVStartPriority=2 +ExecStart=/etc/init.d/sendRebootIOB start +ExecStop=/etc/init.d/sendRebootIOB stop + +[Install] +WantedBy=multi-user.target diff --git a/IOB-PI/Jetco/std_v_2/setIobConf.sh b/IOB-PI/Jetco/std_v_2/setIobConf.sh new file mode 100644 index 0000000..30b4781 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/setIobConf.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# verifico se sia rete donati o rete steamware o offline... +netStatus=`cat /sys/class/net/eth0/operstate` +iaddr=`ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1` + +cd /home/pi/steamware + +if [[ $netStatus != "up" ]] +then + echo "Siamo Offline, pagina demo!" +elif [[ $iaddr == "10.74.82"* ]] +then + cp IOB.cfg.steamware IOB.cfg -f + echo "Siamo in Steamware!" +elif [[ $iaddr == "192.168.51"* ]] +then + cp IOB.cfg.donati IOB.cfg -f + echo "Siamo a Passirano!" +else + echo "Siamo altrove, pagina demo!" +fi + +echo "$iaddr" + +chown pi:pi * \ No newline at end of file diff --git a/IOB-PI/Jetco/std_v_2/unix.py b/IOB-PI/Jetco/std_v_2/unix.py new file mode 100644 index 0000000..12fb3dc --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/unix.py @@ -0,0 +1,31 @@ +import fcntl +import os +import logging + +#--------------------------------------------------------------- +# meccanismo di file lock per evitare multiple instances +# The function will try to lock the file specified , if it success, return True, else return False. +# The nice thing is that the lock will be dropped when the program terminates. +# >>>Use : +# if not lockFile(".lock.pod"): +# sys.exit(0) + +def lockFile ( lockfile ) : + + fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY ) + try: + # Request exclusive (EX) non-blocking (NB) advisory lock. + fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB ) + except IOError: + return False + + return True + +if not lockFile ( ".lockfile" ) : + print '\n noi non siamo soli ...\n' + logging.error( "LOCK: Piu istanze aperte") + #sys.exit ( 0 ) + +#- print '\n running alone ...\n' + + diff --git a/IOB-PI/Jetco/std_v_2/win.py b/IOB-PI/Jetco/std_v_2/win.py new file mode 100644 index 0000000..f679f60 --- /dev/null +++ b/IOB-PI/Jetco/std_v_2/win.py @@ -0,0 +1,32 @@ +import win32api +print " Running on WINDOWS\n" +import os +#--------------------------------------------------------------- +# meccanismo di file lock per evitare multiple instances +# The function will try to lock the file specified , if it success, return True, else return False. +# The nice thing is that the lock will be dropped when the program terminates. +# >>>Use : +# if not lockFile(".lock.pod"): +# sys.exit(0) + +def lockFile ( lockfile ) : + try: + fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY ) + except: + logga("Errore nel file WIN.PY per FD") + try: + # Request exclusive (EX) non-blocking (NB) advisory lock. + #fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB ) + print " Dummy Method! Completa Lockfile\n" + except IOError: + return False + + return True +try: + if not lockFile ( ".lockfile" ) : + print '\n noi non siamo soli ...\n' + logga ( "LOCK: Piu istanze aperte") + sys.exit ( 0 ) +except: + logga("if not lockfile NON RIUSCITO in file WIN.PY") + sys.exit(1) diff --git a/IOB-PI/README.md b/IOB-PI/README.md new file mode 100644 index 0000000..fad572d --- /dev/null +++ b/IOB-PI/README.md @@ -0,0 +1,3 @@ +# Upgrade sw IOB-PI clienti + +ATTENZIONE: se si copia dalla versione standard, SUL PI VA DATO un dos2unix * x tutti i files.. \ No newline at end of file diff --git a/IOB-PI/std_v_2/IOB.cfg b/IOB-PI/std_v_2/IOB.cfg new file mode 100644 index 0000000..9d9c1de --- /dev/null +++ b/IOB-PI/std_v_2/IOB.cfg @@ -0,0 +1,35 @@ +[id] +idxMacchina = 0001 + +[web] +URLBASE = http://10.74.82.219/MP/IO/IOB/input/ +URLALIVE = http://10.74.82.219/MP/IO/IOB +URLENABLED = http://10.74.82.219/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/std_v_2/IOB.cfg.donati b/IOB-PI/std_v_2/IOB.cfg.donati new file mode 100644 index 0000000..29c3d61 --- /dev/null +++ b/IOB-PI/std_v_2/IOB.cfg.donati @@ -0,0 +1,35 @@ +[id] +idxMacchina = 2007 + +[web] +URLBASE = http://192.168.51.77/MP/IO/IOB/input/ +URLALIVE = http://192.168.51.77/MP/IO/IOB +URLENABLED = http://192.168.51.77/MP/IO/IOB/enabled/ +URLADV1 = ?valore= +URLREBO = http://192.168.51.77/MP/IO/sendReboot.aspx?idxMacchina= + +[time] +SAMPLETIME = 0.05 +TIMEOUTSHORT = 0.30 +TIMEOUTLONG = 50 +SENDURLTIME = 0.15 +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 = 1 +bit4 = 0 +bit5 = 0 +bit6 = 0 +bit7 = 0 diff --git a/IOB-PI/IOB.cfg.steamware b/IOB-PI/std_v_2/IOB.cfg.steamware similarity index 100% rename from IOB-PI/IOB.cfg.steamware rename to IOB-PI/std_v_2/IOB.cfg.steamware diff --git a/IOB-PI/std_v_2/MapoIOB b/IOB-PI/std_v_2/MapoIOB new file mode 100644 index 0000000..c49ec0a --- /dev/null +++ b/IOB-PI/std_v_2/MapoIOB @@ -0,0 +1,41 @@ +### BEGIN INIT INFO +# Provides: MapoIOB: script Steamware per avvio driver IOB +# Required-Start: $remote_fs $syslog ramlog +# Required-Stop: $remote_fs $syslog ramlog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Steamware's MapoIOB driver +# Description: Steamware's MapoIOB driver, versione lettura porta parallela +### END INIT INFO + +#! /bin/sh +# /etc/init.d/MapoIOB + +export HOME +case "$1" in + start) + echo "Starting readParallela" + cd /home/pi/steamware + /usr/bin/python ./readParallela.py 2>&1 & + ;; + stop) + echo "Stopping readParallela" + RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'` + kill -9 $RS_PID + cd /home/pi/steamware + rm .lockfile + ;; + restart) + ## Stop the service and regardless of whether it was + ## running or not, start it again. + $0 stop + killall python + $0 start + ;; + *) + echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}" + exit 1 + ;; +esac +exit 0 + diff --git a/IOB-PI/std_v_2/MapoIOB_logrot b/IOB-PI/std_v_2/MapoIOB_logrot new file mode 100644 index 0000000..13410b9 --- /dev/null +++ b/IOB-PI/std_v_2/MapoIOB_logrot @@ -0,0 +1,28 @@ +/var/log/MapoIOB.log { + size 8M + copytruncate + create 700 pi pi + dateext + rotate 100 + compress + maxage 366 + missingok +} +/var/log/logReboot.txt { + size 1M + copytruncate + create 700 pi pi + dateext + rotate 30 + compress + missingok +} +/var/log/logTemp.txt { + size 1M + copytruncate + create 700 pi pi + dateext + rotate 30 + compress + missingok +} diff --git a/IOB-PI/std_v_2/checkAlive.sh b/IOB-PI/std_v_2/checkAlive.sh new file mode 100644 index 0000000..aace73d --- /dev/null +++ b/IOB-PI/std_v_2/checkAlive.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia! + +DATE=`date +%Y-%m-%d` +cd /var/log +if [ -f MapoIOB.log ] + then + # controllo SE sia stato acceduto da meno di 2 minuti (=alive da log...) + trovato=`find . -name 'MapoIOB*' -cmin -1` + if [[ $trovato != './MapoIOB.log' ]] + then + /etc/init.d/MapoIOB restart + echo $date + "riavvio!" + fi +else + # in questo caso AVVIO il processo MapoIOB + /etc/init.d/MapoIOB start + echo $date + "file non trovato, avvio!" +fi diff --git a/IOB-PI/std_v_2/cleanPython.sh b/IOB-PI/std_v_2/cleanPython.sh new file mode 100644 index 0000000..c4f616a --- /dev/null +++ b/IOB-PI/std_v_2/cleanPython.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +DATE=`date +%Y-%m-%d_%T` +# log inizio pulizia +echo $DATE " - INIZIO pulizia processi python" >> clean.log +# effettua pulizia processi: killa tutti i processi python +killall python + +# avvia MapoIob +/etc/init.d/MapoIOB start + +# log fatto! +DATE=`date +%Y-%m-%d_%T` +echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log diff --git a/IOB-PI/std_v_2/convertLogFile.py b/IOB-PI/std_v_2/convertLogFile.py new file mode 100644 index 0000000..760c2a9 --- /dev/null +++ b/IOB-PI/std_v_2/convertLogFile.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# readFile v. 0.1 +# - single instance timer +# - invio multiplo x send eventi accodati +#--------------------------------------------------------------- +import os, sys +import argparse +#-------------------------------------------------------------- + +# gestione parser argomenti in input +parser = argparse.ArgumentParser() +parser.add_argument("inFile") +parser.add_argument("outFile") +args = parser.parse_args() + +#with open('logfile.txt', 'r') as inf, open('persMem.dat',"w") as outf: +with open(args.inFile, 'r') as inf, open(args.outFile,"w") as outf: + data = inf.readlines() + + lastDt = "" + lastMs = 0 + stepMs = 200 + + for line in data: + words = line.split() + if words[2] == 'queue': + # recupero dataOra + newDt = words[0].replace("-","") + words[1].replace(":","") + + # verifico se data/ora identica... + if (lastDt == newDt): + # --> aggiungo stepMs + lastMs += stepMs + else: + lastMs = 0 + + lastDt = newDt + + newDt = newDt + '{:03d}'.format(lastMs) #str(lastMs) + #print words[0].replace("-","") + words[1].replace(":","") + " | " + newDt + "\n" + + # print words + # outf.write(words[0].replace("-","") + words[1].replace(":","") + '#' + words[4].replace(">","") + '#' + words[5].replace("[","").replace("]","") +'\n') + outf.write(newDt + '#' + words[4].replace(">","") + '#' + words[5].replace("[","").replace("]","") +'\n') \ No newline at end of file diff --git a/IOB-PI/std_v_2/crontab b/IOB-PI/std_v_2/crontab new file mode 100644 index 0000000..74fe381 --- /dev/null +++ b/IOB-PI/std_v_2/crontab @@ -0,0 +1 @@ +* * * * * /bin/bash /home/pi/steamware/checkAlive.sh >> /home/pi/stdout 2>> /home/pi/stderr diff --git a/IOB-PI/std_v_2/install-RPI-IOB.sh b/IOB-PI/std_v_2/install-RPI-IOB.sh new file mode 100644 index 0000000..7de1dc1 --- /dev/null +++ b/IOB-PI/std_v_2/install-RPI-IOB.sh @@ -0,0 +1,51 @@ +#|/bin/bash + +#installa il necessario per RPI-3-IOB partendo dal contenuto della folder /home/pi/steamware + +#step 1: creo file di log nuovi +rm /var/log/log*.txt +rm /var/log/MapoIOB* +rm /home/pi/steamware/log*.txt + +touch /var/log/logReboot.txt +touch /var/log/logTemp.txt +touch /var/log/MapoIOB.log + +ln -sf /var/log/logReboot.txt /home/pi/steamware/logReboot.txt +ln -sf /var/log/logTemp.txt /home/pi/steamware/logTemp.txt +ln -sf /var/log/MapoIOB.log /home/pi/steamware/logfile.txt + +chown pi:pi /home/pi -R +chmod 666 /var/log/log*.txt +chmod 666 /var/log/MapoIOB.log + +#step 2: copio files in /usr/local/bin +cd /home/pi/steamware +chmod +x *.sh +cp *.sh /usr/local/bin/ + +#step 3: copio files x logrotate... +cd /home/pi/steamware +cp MapoIOB_logrot /etc/logrotate.d/ + +# step 4: copio target systemd in avvio... +cp -f sendRebootIOB /etc/init.d/sendRebootIOB +cp -f sendRebootIOB.service /etc/systemd/system/sendRebootIOB.service +echo "" +echo "-----------------------------------------------" +echo "Completare registrazione servizio avvio: digitare i seguenti comandi" +echo "systemctl enable sendRebootIOB" +echo "systemctl daemon-reload" +echo "systemctl status sendRebootIOB" +echo "-----------------------------------------------" +echo "" +echo "" +echo "" +echo "-----------------------------------------------" +echo "Infine creare voce crontab che salvi temperatura CPU/GPU ogni 20 minuti..." +echo "crontab -e" +echo "*/20 * * * * /usr/local/bin/saveTemp.sh" +echo "-----------------------------------------------" + + + diff --git a/IOB-PI/std_v_2/readFile.py b/IOB-PI/std_v_2/readFile.py new file mode 100644 index 0000000..887118d --- /dev/null +++ b/IOB-PI/std_v_2/readFile.py @@ -0,0 +1,152 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# readFile v. 0.1 +# - single instance timer +# - invio multiplo x send eventi accodati + +#--------------------------------------------------------------- + +import time + +from datetime import datetime + +import urllib +import ConfigParser +import os, sys + +import logging +import logging.handlers +import Queue + +import argparse +#-------------------------------------------------------------- + +# gestione parser argomenti in input +parser = argparse.ArgumentParser() +parser.add_argument("memFile") +parser.add_argument("logFile") +args = parser.parse_args() + +#definizione variabili BASE +stepQueuePut=25000 +stepQueueGet=250 +NMAXSEND=500000 # limite invio file x fare prove... +idxMacchina = "2003" + +#-------------------------------------------------------------- +# Gestione coda (condivisa) x registrazione eventi ed invio URL +#print "Creazione coda illimitata" +Coda = Queue.Queue(0) + +#--------------------------------------------------------------- +#Funzione di scrittura su coda con try-except + +def accoda(valore): + + try: + Coda.put(valore) + except Queue.Full: + logPro.error( "Queue full" + dtEve + '#' + value + '#' + cont ) + except: + logPro.error( "NETWORK:Errore http-no com rete-timeout" + url ) + + +#-------------------------------------------------------------- +# svuotaCoda x invio dati al server +def svuota_coda(): + + global NMAXSEND + + try: + if not Coda.empty(): + # invio SOLO i primi NMAXSEND eventi... SE minore del num eventi... + if NMAXSEND > Coda.qsize(): + NMAXSEND = Coda.qsize() + + + i = 0 + + with open(args.logFile,"w") as outf: + while i <= NMAXSEND: + if not Coda.empty(): + + # formatto dataOra corrente + dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] + + #prendo primo elemento dalla coda + resp = Coda.get() + + # recupero valori da elemento coda! + dtEve = resp.split("#")[0] + value = resp.split("#")[1] + cnt = resp.split("#")[2] + url = URLBASE + idxMacchina + URLADV1 + value + url = url + '&dtCurr=' + dtCurr + '&dtEve=' + dtEve + '&cnt=' + cnt + # CHIAMO URL + response3 = urllib.urlopen ( url ) + answ3 = response3.read() + + # registro chiamata + risposta + # outf.write(url + " --> " + answ3 + "\n") + + # incremento e controllo se mostrare output + i += 1 + if (i % stepQueueGet) == 0: + print "Inviati %d valori..." % i + + print "Inviati %d valori..." % i + except: + print "Errore in svuotamento coda!" + + +#--------------------------------------------------------------- +# MAIN + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'IOB.cfg' ) + + # NMAXSEND = config.getint ( 'time' , 'NMAXSEND' ) + # idxMacchina = config.get ( 'id' , 'idxMacchina' ) + + + URLBASE = config.get ( 'web' , 'URLBASE' ) + URLADV1 = config.get ( 'web' , 'URLADV1' ) + + LOGFILE = config.get ( 'log' , 'LOGFILE' ) + LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' ) +except: + print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg' + sys.exit(1) + +#--------------------------------------------------------------- + +dtCurr = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] +print "Inizio elaborazione: %s" % dtCurr + +# Leggo il file! +i = 0 +with open(args.memFile, 'r') as inf, open(args.logFile,"w") as outf: + data = inf.readlines() + + print "Trovate %d da processare..." % len(data) + +# leggo e metto in QUEUE... + for line in data: + accoda(line) + i += 1 + if (i % stepQueuePut) == 0: + print "Accodati %d valori..." % i + +print "Completata lettura file! %d righe accodate da trasmettere" % Coda.qsize() + +dtCurr = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] +print "Inizio invio: %s" % dtCurr + + +# chiamo procedura x svuotare coda... +svuota_coda() + +dtCurr = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] +print "Completato invio: %s" % dtCurr \ No newline at end of file diff --git a/IOB-PI/std_v_2/readParallela.py b/IOB-PI/std_v_2/readParallela.py new file mode 100644 index 0000000..6e36bec --- /dev/null +++ b/IOB-PI/std_v_2/readParallela.py @@ -0,0 +1,608 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# readParallela v. 2.0 +# - single instance timer +# - invio multiplo x send eventi accodati +# - gestione segnali BLINKING + +#--------------------------------------------------------------- +# levare locking +# timer semplificata +# GPIO global + + +import time +import sys + + +from datetime import datetime + +import urllib +import ConfigParser +import os, sys + +import logging +import logging.handlers +import threading +import Queue + +from array import * + +#-------------------------------------------------------------- + +# COSTANTI +MSGLEN = 9 +TIMEOUTSERIALE = 10 +MAXRETRY = 3 + +# numero campioni filtraggio segnale ballerino +MAX_COUNTER_BLINK = 10 + +PROGRAM_NAME ="ReadPar IOB-pi v.2.0" + +# DA FILE CONF +idxMacchina = "1001" +SAMPLETIME = 0.1 +TIMEOUTSHORT = (SAMPLETIME*20) +TIMEOUTLONG = (SAMPLETIME*600) +SENDURLTIME = 0.08 +NMAXSEND = 5 # numero massimo di invii per singolo ciclo di svuotamento + +# VAR +to_enable = False +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG +to_serial = TIMEOUTSERIALE +to_retry = MAXRETRY +errormsglen = 0 + +# VAR + +out_0 = 24 +out_1 = 26 + +in_0 = 11 +in_1 = 12 +in_2 = 13 +in_3 = 15 +in_4 = 16 +in_5 = 18 +in_6 = 22 +in_7 = 7 + +# contatore: serve x match tra accoda ed invia x possibile controllo a posteriori... ogni volta che accodo incremento di 1, va da 0 a 9999 +cont = '0' + +# variabile stato online/offline della macchina +onLine = '1' + +# variabile stato seinding/waiting x la parte invio URL +sending = '0' + +# variabile stato timer thread busy +timer_busy = False + +# +# array per ingressi filtrati + +i_counters = array ( 'i',[0,0,0,0,0,0,0,0]) +B_blinking = array ( 'B',[0,0,0,0,0,0,0,0]) +B_previous = array ( 'B',[0,0,0,0,0,0,0,0]) +B_input = array ( 'B',[0,0,0,0,0,0,0,0]) +B_output = array ( 'B',[0,0,0,0,0,0,0,0]) + +#-------------------------------------------------------------- +# Gestione coda (condivisa) x registrazione eventi ed invio URL +#print "Creazione coda illimitata" + +Coda = Queue.Queue(0) + +#queueLock = threading.Lock() + +#--------------------------------------------------------------- +# lettura parallela +# ritorna il byte letto pulito ( due char hex ) + +def readParallelaFiltrata(): + + global in_0 + global in_1 + global in_2 + global in_3 + global in_4 + global in_5 + global in_6 + global in_7 + + global GPIO + + current = '' + + + try: + + if GPIO.input(in_0): + B_input[0] = 0 + else: + B_input[0] = 1 + + if GPIO.input(in_1): + B_input[1] = 0 + else: + B_input[1] = 1 + + if GPIO.input(in_2): + B_input[2] = 0 + else: + B_input[2] = 1 + + if GPIO.input(in_3): + B_input[3] = 0 + else: + B_input[3] = 1 + + if GPIO.input(in_4): + B_input[4] = 0 + else: + B_input[4] = 1 + + if GPIO.input(in_5): + B_input[5] = 0 + else: + B_input[5] = 1 + + if GPIO.input(in_6): + B_input[6] = 0 + else: + B_input[6] = 1 + + if GPIO.input(in_7): + B_input[7] = 0 + else: + B_input[7] = 1 + + #ciclo per ogni segnale + for i in xrange(8) : + # print (i) + # se non blinking, copia ingresso + if ( B_blinking[i] == 0 ) : + B_output[i] = B_input[i] + else: + # gestione segnale blinking + # se fronte del segnale + if ( B_previous[i] != B_input[i] ) : + B_previous[i] = B_input[i] + # se fronte di salita + if ( B_input[i] == 1 ) : + # subito uscita = 1 + B_output[i] = 1 + i_counters[i] = MAX_COUNTER_BLINK + #else : + # # loggo che ho rilevato un blink... + # logPro.info("Blink down on bit " + `i`) + else: + # no , segnale eguale a prima + # se input a 0 + if ( B_input[i] == 0 ) : + # E CONTEGGIO IN CORSO + if ( i_counters[i] > 0 ) : + i_counters[i] = i_counters[i] -1 + if ( i_counters[i] == 0 ) : + B_output[i] = 0 + logPro.info("END Blink on bit " + `i` ) + + #Rimettiamo insieme i bit + new_value = 0 + + if ( B_output[0] == 1 ) : + new_value = new_value + 1 + if ( B_output[1] == 1 ) : + new_value = new_value + 2 + if ( B_output[2] == 1 ) : + new_value = new_value + 4 + if ( B_output[3] == 1 ) : + new_value = new_value + 8 + if ( B_output[4] == 1 ) : + new_value = new_value + 16 + if ( B_output[5] == 1 ) : + new_value = new_value + 32 + if ( B_output[6] == 1 ) : + new_value = new_value + 64 + if ( B_output[7] == 1 ) : + new_value = new_value + 128 + + current = hex( new_value ).replace ( "0x" , "" ).upper() + + except: + pass + + return current + +#--------------------------------------------------------------- +#Funzione di scrittura su coda con try-except + +def accoda(): + + try: + dtEve = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] + Coda.put(dtEve + '#' + value + '#' + cont) + + except Queue.Full: + logPro.error( "Queue full" + `dtEve` + '#' + `value` + '#' + `cont` ) + except: + logPro.error( "NETWORK:Errore http-no com rete-timeout" + url ) +# print "Url aforte" , url + + +#-------------------------------------------------------------- +# svuotaCoda x invio dati al server +def svuota_coda(): + + global onLine + global sending + global timer_busy + global NMAXSEND + + #print "start timer " + + if ( timer_busy == False ): + timer_busy = True + #print "start timer ok " + + try: + if not Coda.empty(): + #print "coda da svuotare!" + response = urllib.urlopen(URLALIVE) + answ = response.read() + if answ == 'OK': + #print "OK alive" + response2 = urllib.urlopen(URLENABLED + idxMacchina) + answ2 = response2.read() + if answ2 == 'OK': + # aggiorno stato ad online + if onLine == '0': + logPro.info("IOB ONLINE!") + #print("IOB ONLINE") + + onLine = '1' # imposto comunque online + else: + if onLine == '1': + logPro.error("IOB offline") + #print("IOB offline") + + onLine = '0' + else: + if onLine == '1': + logPro.error("Server offline") + #print("Server offline") + + onLine = '0' + + # ora verifico SE si possa inviare (ovvero sia online server e NON ci siano altri send attivi...) + if onLine == '1': + if sending == '0': + #segnalo che sono in sending! + sending = '1' + + # SAM 2016.12.23: modifica x invio FINO A nMaxSend ELEMENTI ad ogni ciclo di svuotamento + i = NMAXSEND + + while i >= 0: + if not Coda.empty(): + + # formatto dataOra corrente + dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] + + #prendo primo elemento dalla coda + resp = Coda.get() + + # recupero valori da elemento coda! + dtEve = resp.split("#")[0] + value = resp.split("#")[1] + cnt = resp.split("#")[2] + url = URLBASE + idxMacchina + URLADV1 + value + url = url + '&dtCurr=' + dtCurr + '&dtEve=' + dtEve + '&cnt=' + cnt + # CHIAMO URL + response3 = urllib.urlopen ( url ) + answ3 = response3.read() + #print(url) + + # log valore inviato! + logSnd.info( value + ' ['+ cnt +']' + ' R:' + answ3 ) + #print "Valore smaltito dalla coda" + + # tolgo 1 al contatore + i -= 1 + + # completato invio, riporto sending a zero! + sending = '0' + else: + logPro.info("WAIT active send to complete") + + else: + pass + + else: + pass + + except: + if onLine == '1': + logPro.error("Server Non raggiungibile") + #print "Non raggiungibile" + + onLine = '0' + +# in ogni caso + + timer_busy = False + #print "end timer ok" + + + #print "end timer " + + +#--------------------------------------------------------------- +# funzione timer thread +#--------------------------------------------------------------- +def do_every (interval, worker_func, iterations = 0): + if iterations != 1: + threading.Timer ( + interval, + do_every, [interval, worker_func, 0 if iterations == 0 else iterations-1] + ).start (); + + worker_func (); + +#--------------------------------------------------------------- +# gestione contatore +#--------------------------------------------------------------- +def contatore(): + + try: + global cont + ctr = int(cont) + ctr +=1 + ctr = ctr % 10000 # round robin 10000 eventi x track + cont = str(ctr) + except: + print("errore incremento contatore") + +#--------------------------------------------------------------- +# avvia porta parallela +#--------------------------------------------------------------- +def avviaParallela(): + + global in_0 + global in_1 + global in_2 + global in_3 + global in_4 + global in_5 + global in_6 + global in_7 + + global GPIO + + try: + + GPIO.setmode(GPIO.BOARD) + + GPIO.setwarnings(False) + + #GPIO.setup(out_0, GPIO.OUT) # output 0 + #GPIO.setup(out_1, GPIO.OUT) # output 1 + + GPIO.setup(in_0, GPIO.IN) # input 0 + GPIO.setup(in_1, GPIO.IN) # input 1 + GPIO.setup(in_2, GPIO.IN) # input 2 + GPIO.setup(in_3, GPIO.IN) # input 3 + GPIO.setup(in_4, GPIO.IN) # input 4 + GPIO.setup(in_5, GPIO.IN) # input 5 + GPIO.setup(in_6, GPIO.IN) # input 6 + GPIO.setup(in_7, GPIO.IN) # input 7 + + except: + print( "\n\n" + PROGRAM_NAME + " - Error 3 on RPi.GPIO ! \n\n") + sys.exit(1) + + + print( "\n\n" + PROGRAM_NAME + " - init ok \n\n") + + +#--------------------------------------------------------------- +#--------------------------------------------------------------- +# MAIN + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'IOB.cfg' ) + + SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' ) + TIMEOUTSHORT = config.getfloat ( 'time' , 'TIMEOUTSHORT' ) + TIMEOUTLONG = config.getfloat ( 'time' , 'TIMEOUTLONG' ) + SENDURLTIME = config.getfloat ( 'time' , 'SENDURLTIME' ) + NMAXSEND = config.getint ( 'time' , 'NMAXSEND' ) + + idxMacchina = config.get ( 'id' , 'idxMacchina' ) + + + URLBASE = config.get ( 'web' , 'URLBASE' ) + URLENABLED = config.get('web' , 'URLENABLED') + URLALIVE = config.get ('web' , 'URLALIVE') + URLADV1 = config.get ( 'web' , 'URLADV1' ) + + LOGFILE = config.get ( 'log' , 'LOGFILE' ) + LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' ) + + B_blinking[0] = config.getint ( 'blink' , 'bit0' ) + B_blinking[1] = config.getint ( 'blink' , 'bit1' ) + B_blinking[2] = config.getint ( 'blink' , 'bit2' ) + B_blinking[3] = config.getint ( 'blink' , 'bit3' ) + B_blinking[4] = config.getint ( 'blink' , 'bit4' ) + B_blinking[5] = config.getint ( 'blink' , 'bit5' ) + B_blinking[6] = config.getint ( 'blink' , 'bit6' ) + B_blinking[7] = config.getint ( 'blink' , 'bit7' ) + + MAX_COUNTER_BLINK = config.getint ( 'blink' , 'MAX_COUNTER_BLINK' ) + + +except: + print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg' + sys.exit(1) + +#-------------------------------------------- +# oggetto Logger +#-------------------------------------------- +try: + 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' + ) + + # aggiungo 2 logger specifici x queue e send... + logQue = logging.getLogger('queue') + logSnd = logging.getLogger('sendUrl') + logPro = logging.getLogger('program') + +except: + # manda mail o simili - FARE!!! + print "LOG: Impossibile creare file log con nome " + print (LOGFILE) +#-------------------------------------------- + + +print "\n\n" + PROGRAM_NAME + "\n\n" + +global startstatus +startstatus = 1 + +if startstatus == 1: + logPro.info("Avvio Programma" + PROGRAM_NAME) + +## Verifica l'OS e di conseguenza carica il file relativo con metodo di lockfile appropriato + check singola istanza +if os.name == 'posix': + import unix +else: + import win + +logPro.info( "Start " + PROGRAM_NAME ) + + +# lettura file configurazione + +# [id] +# idxMacchina = 2001 +# [time] +# SAMPLETIME = 0.1 +# TIMEOUTSHORT = 200 +# TIMEOUTLONG = 6000 + + +print ( ' idxMacchina = %s' % ( idxMacchina ) ) +print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) ) +print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) ) +print ( ' TIMEOUTLONG = %4.2f' % ( TIMEOUTLONG ) ) +print ( ' SENDURLTIME = %4.2f' % ( SENDURLTIME ) ) +print ( ' URLBASE = %s' % ( URLBASE ) ) +print ( ' URLADV1 = %s' % ( URLADV1 ) ) +print ( ' LOGFILE = %s' % ( LOGFILE ) ) +print ( ' LOGLEVEL = %s' % ( LOGLEVEL ) ) + +# -sys.stdout.write ( 'idxMacchina ?' + idxMacchina + '\n') + +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG + + +#-------------------------------------------------------------- +# apertura parallela + +try: + import RPi.GPIO as GPIO +except RuntimeError: + print( "\n\n" + PROGRAM_NAME + " - Error 1 - you need superuser privileges") +except: + print( "\n\n" + PROGRAM_NAME + " - Error 2 - you need superuser privileges. USE 'sudo' to run your script\n\n") + sys.exit(1) + + +avviaParallela() + + +#-------------------------------------------------------------- +# MARCO: qui inserire avvio thread di "svuotaCoda" + +# avviaSvuotaCoda +#print "Avvia svuota coda" + +do_every ( SENDURLTIME , svuota_coda ); + +#--------------------------------------------------------------- +# ciclo forever and ever + +old = '' + +#print "Avvio ciclo" +logPro.info("Avvio loop principale") +while 1: + + try: + time.sleep (SAMPLETIME) + except: + logPro.info("First_SLEEP: errore attesa sampletime") + + # lettura dati da IOB + value = readParallelaFiltrata() + + if ( value != '' ) : + if value != old : + #loggo e invio dati + try: + logQue.info( value + ' ['+ cont +']') + errormsglen = 0 + accoda() + contatore() + except: + logPro.error("URLBROWSER: errore registrazione valore e accoda") + pass + #enable e reset timer + to_enable = True + to_short = TIMEOUTSHORT + to_long = TIMEOUTLONG + + old = value + + + # gestione timeout breve + if ( to_enable ) : + to_short = to_short - SAMPLETIME + if to_short <= 0: + #loggo e invio dati + try: + logQue.info( '>' + value + ' ['+ cont +']') + errormsglen = 0 + accoda() + contatore() + except: + logPro.error("URLBROWSER: errore registrazione valore e accoda TO_short") + pass + to_short = TIMEOUTSHORT + to_enable = False # dopo un colpo il timer breve viene disabilitato + to_long = TIMEOUTLONG + + # gestione timeout lungo + to_long = to_long - SAMPLETIME + if to_long <= 0: + #loggo e invio dati + try: + logQue.info( '>>' + value + ' ['+ cont +']') + errormsglen = 0 + accoda() + contatore() + except: + logPro.error("URLBROWSER: errore registrazione valore e accoda TO_long") + pass + to_long = TIMEOUTLONG diff --git a/IOB-PI/std_v_2/readSeriale.py b/IOB-PI/std_v_2/readSeriale.py new file mode 100644 index 0000000..3c00644 --- /dev/null +++ b/IOB-PI/std_v_2/readSeriale.py @@ -0,0 +1,363 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +#--------------------------------------------------------------- + +import serial +import time +import sys +import datetime +import urllib +import ConfigParser +import os, sys + +#--------------------------------------------------------------- + +# COSTANTI +MSGLEN = 9 +TIMEOUTSERIALE = 10 +MAXRETRY = 3 + +# DA FILE CONF +idxMacchina = "2001" +SAMPLETIME = 0.1 +TIMEOUTSHORT = (SAMPLETIME*20) +TIMEOUTLONG = (SAMPLETIME*600) + +# VAR +to_enable = False +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG +to_serial = TIMEOUTSERIALE +to_retry = MAXRETRY +errormsglen = 0 + +#--------------------------------------------------------------- +# classe logger + +class Logger: + def __init__(self, filename): + try: + self.filename = filename + except: + logga("LOGGER: errore try su self.filename") + sys.exit(1) + def __call__(self, string): + try: + file = open(self.filename, 'a') + file.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + '] ') + file.write(string + '\n') + file.close() + except: + logga("LOGGER: errore try su scrittura") + sys.exit(1) + +#--------------------------------------------------------------- +# lettura buffer seriale e pulizia caratteri non stampabili +# ritorna '' se non c'è un messaggio buono o il messaggio pulito ( due bytes hex ) +# il messaggio ha il formato xxi00 00xxx + +def readSeriale(): + + global to_serial + global to_retry + global errormsglen + + ret = '' + current = '' + i = 0 + + # ritorna '' se non ci sono abbastanza caratteri + try: + if ser.inWaiting() < MSGLEN : +# +# to_serial = to_serial - 1 # se non mi risponde, faccio un ' altra richiesta.... +# if to_serial <= 0: +# try: +# requestData () +# except: +# logga("SERIALE: errore su requestData") +# sys.exit(1) +# to_serial = TIMEOUTSERIALE # ripristino timer +# to_retry = to_retry - 1 # contatore retry +# if to_retry <= 0: +# logga ( 'IOB not responding' ) +# return ret + logga("SERIALE: errore msglen < 9 char - Errore no. " + str(errormsglen)) + errormsglen = errormsglen +1 + avviaSeriale() + time.sleep(.2) + if errormsglen > 30: + sys.exit(1) + except: + if startstatus == 0: + logga ("Porta SERIALE non disponibile - ser.inWaiting error - exit... - Errore no. " + str(errormsglen)) + errormsglen = errormsglen +1 + avviaSeriale() + time.sleep(.2) + if errormsglen > 30: + sys.exit(1) + + # finchè c'è robba .. leggi e tieni i buoni + to_serial = TIMEOUTSERIALE + to_retry = MAXRETRY + try: + while ser.inWaiting() > 0 : + try: + c = ser.read(1) + except: + logga("SERIALE: errore su try ser.read") + sys.exit(1) + # filtra caratteri non stampabili + if c > ' ' : + current += c + #sys.stdout.write(current + '<<<<\n') + # ora il messaggio ha il formato xxxxxi00 00xxx : cerco la 'i' iniziale + try: + while i < len(current) and current[i] != 'i': + i = i + 1 + except: + logga("SERIALE: errore su ricerca i iniziale") + sys.exit(1) + # se non ho trovato la 'i' restituisco '' + if i == len(current)-1: + return ret + else: + current = current[i+1:i+3] + # richiesta dati ad IOB + requestData() + #sys.stdout.write ( current + '\n') + except: + if startstatus == 0: + logga ('Porta SERIALE non disponibile - ser.inWaiting e filtraggio error...exit') + sys.exit(1) + return current +#--------------------------------------------------------------- +# richiesta dati ad IOB : scrittura su seriale + +def requestData (): + try : + ser.write ("$i" + '\r\n') + ser.flush() + except : + if startstatus == 0: + logga ( "SERIAL: Errore di scrittura/flush") + + +#--------------------------------------------------------------- +#Funzione di scrittura su url con try-except + +def chiamaUrl(): + try: + url = URLBASE + idxMacchina + URLADV1 + value + urllib.urlopen ( url ) + except: + logga ( "NETWORK:Errore http-no com rete-timeout" + url ) + + +#--------------------------------------------------------------- +# Funzione che verifica possibilità di creare log e include testo corrente + +def logga(message) : + try: + log(message) + except : + pass + +#--------------------------------------------------------------- + + +def avviaSeriale(): + global ser + + try: + ser = serial.Serial( + port = comm_port , + baudrate = 9600 , + parity = serial.PARITY_NONE , + stopbits = serial.STOPBITS_ONE , + bytesize = serial.EIGHTBITS + ) + startstatus = 0 + except serial.serialutil.SerialException , e : + try: + if startstatus == 0: + logga ( "SERIAL:Errore apertura seriale - " + comm_port) + except: + pass + sys.stdout.write ( '\nErrore apertura seriale\n\n%s\n\n' % e ) + if errormsglen > 30: + sys.exit (1) + +#--------------------------------------------------------------- +#--------------------------------------------------------------- +# MAIN + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'readSeriale.cfg' ) + + SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' ) + TIMEOUTSHORT = config.getfloat ( 'time' , 'TIMEOUTSHORT' ) + TIMEOUTLONG = config.getfloat ( 'time' , 'TIMEOUTLONG' ) + + idxMacchina = config.get ( 'id' , 'idxMacchina' ) + comm_port = config.get ( 'comm' , 'port' ) + + URLBASE = config.get ( 'web' , 'URLBASE' ) + URLADV1 = config.get ( 'web' , 'URLADV1' ) + + LOGFILE = config.get ( 'log' , 'LOGFILE' ) + LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' ) +except: + sys.exit(1) + +# oggetto Logger +try: + log = Logger(LOGFILE) +except: + # manda mail o simili - FARE!!! + print "LOG: Impossibile creare file log con nome " + print (LOGFILE) + +print '\n\n Read seriale IOB v.0.2 !!!!\n' + +global startstatus +startstatus = 1 + +if startstatus == 1: + logga("Avvio Programma") + +# Verifica l'OS e di conseguenza carica il file relativo con metodo di lockfile appropriato + check singola istanza +if os.name == 'posix': + import unix +else: + import win + +logga ( "Start Read seriale IOB v.0.2") + + +# lettura file configurazione + +# [comm] +# port = /dev/ttyS0 +# [id] +# idxMacchina = 2001 +# [time] +# SAMPLETIME = 0.1 +# TIMEOUTSHORT = 200 +# TIMEOUTLONG = 6000 + +print ( ' comm_port = %s' % ( comm_port ) ) +print ( ' idxMacchina = %s' % ( idxMacchina ) ) +print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) ) +print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) ) +print ( ' TIMEOUTLONG = %4.2f' % ( TIMEOUTLONG ) ) +print ( ' URLBASE = %s' % ( URLBASE ) ) +print ( ' URLADV1 = %s' % ( URLADV1 ) ) +print ( ' LOGFILE = %s' % ( LOGFILE ) ) +print ( ' LOGLEVEL = %s' % ( LOGLEVEL ) ) + +# -sys.stdout.write ( 'idxMacchina ?' + idxMacchina + '\n') + +to_short = TIMEOUTSHORT +to_long = TIMEOUTLONG + + + +#-------------------------------------------------------------- + + +#--------------------------------------------------------------- +# apertura seriale + +avviaSeriale() + +#try: +# ser = serial.Serial( +# port = comm_port , +# baudrate = 9600 , +# parity = serial.PARITY_NONE , +# stopbits = serial.STOPBITS_ONE , +# bytesize = serial.EIGHTBITS +# ) +# print "Initialized!" +#except serial.serialutil.SerialException , e : +# try: +# logga ( "SERIAL:Errore apertura seriale - " + comm_port) +# except: +# pass +# sys.stdout.write ( '\nErrore apertura seriale\n\n%s\n\n' % e ) +# sys.exit (1) + +#--------------------------------------------------------------- +# ciclo forever and ever + +old = '' + +# richiesta dati ad IOB +try: + requestData() +except: + logga("SERIALE: errore sul try di requestData") + sys.exit(1) + + +while 1: + try: + time.sleep (SAMPLETIME) + except: + logga("SERIALE_SLEEP: errore attesa sampletime") + # lettura dati da IOB + try: + value = readSeriale() + except: + if startstatus == 0: + logga("errore PRIMA LETTURA SERIALE") + sys.exit(1) + if ( value != '' ) : + if value != old : + #loggo e invio dati + try: + logga ( value ) + errormsglen = 0 + chiamaUrl() + except: + logga("URLBROWSER: errore registrazione valore e chiamaUrl") + pass + #enable e reset timer + to_enable = True + to_short = TIMEOUTSHORT + to_long = TIMEOUTLONG + + old = value + + + # gestione timeout breve + if ( to_enable ) : + to_short = to_short - SAMPLETIME + if to_short <= 0: + #loggo e invio dati + try: + logga ( '>' + value ) + errormsglen = 0 + chiamaUrl() + except: + pass + to_short = TIMEOUTSHORT + to_enable = False # dopo un colpo il timer breve viene disabilitato + to_long = TIMEOUTLONG + + # gestione timeout lungo + to_long = to_long - SAMPLETIME + if to_long <= 0: + #loggo e invio dati + try: + logga ( '>>' + value ) + errormsglen = 0 + chiamaUrl() + except: + pass + to_long = TIMEOUTLONG + + diff --git a/IOB-PI/std_v_2/saveTemp.sh b/IOB-PI/std_v_2/saveTemp.sh new file mode 100644 index 0000000..a2cd2be --- /dev/null +++ b/IOB-PI/std_v_2/saveTemp.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +#salva la temperatura CPU e GPU su chiamata... + +# imposto logfile... +logFile="/var/log/logTemp.txt" + +cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp) +cpuTemp1=$(($cpuTemp0/1000)) +cpuTemp2=$(($cpuTemp0/100)) +cpuTempM=$(($cpuTemp2 % $cpuTemp1)) + +gpuTemp=`vcgencmd measure_temp` + +loadAvg=`cat /proc/loadavg` + +echo "$(date) | CPU: temp=$cpuTemp1.$cpuTempM ºC | GPU: $gpuTemp | LoadAvg: $loadAvg" >> $logFile diff --git a/IOB-PI/std_v_2/sendReboot.py b/IOB-PI/std_v_2/sendReboot.py new file mode 100644 index 0000000..021c400 --- /dev/null +++ b/IOB-PI/std_v_2/sendReboot.py @@ -0,0 +1,130 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# sendReboot v. 1.8 + +#--------------------------------------------------------------- + + +import time +import sys + + +from datetime import datetime + +import urllib +import ConfigParser +import os, sys + +import logging + +import time + +#--------------------------------------------------------------- + +# COSTANTI +PROGRAM_NAME = "SendReboot IOB-pi v.1.8" + +# DA FILE CONF +idxMacchina = "99" + +# registro se ho fatto chiamata +global numTry +numTry = 1 + + +#--------------------------------------------------------------- +#Funzione di scrittura su url con try-except +#--------------------------------------------------------------- + +def chiamaUrl(numTry): + + try: + urllib.urlopen ( url ) + numTry = numTry + 10 + except Exception, e: + print e + logging.info ( e ) + print "Url aforte" , 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] + +#--------------------------------------------------------------- +# MAIN +#--------------------------------------------------------------- + +try: + config = ConfigParser.RawConfigParser() + config.read ( 'IOB.cfg' ) + + idxMacchina = config.get ( 'id' , 'idxMacchina' ) + + + 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) + + +#-------------------------------------------- +# oggetto Logger +#-------------------------------------------- +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') + +except: + # manda mail o simili - FARE!!! + print "LOG: Impossibile creare file log con nome " + print (LOGFILE) +#-------------------------------------------- + + +print "\n\n" + PROGRAM_NAME + "\n\n" + +global startstatus +startstatus = 1 + +if startstatus == 1: + logging.info("Avvio Programma " + PROGRAM_NAME) + + +# lettura file configurazione +print ( ' idxMacchina = %s' % ( idxMacchina ) ) +print ( ' URLREBO = %s' % ( URLREBO ) ) +print ( ' LOGFILE = %s' % ( LOGFILE ) ) + +# lettura mac address +myMac = getMAC('eth0') +print ( ' MAC Address = %s' % ( myMac ) ) + +# configuro URL da inviare +url = URLREBO + idxMacchina + "&mac=" + myMac + +# modifica: cerco se ho inviato segnale altrimenti ritento invio... +while (numTry < 11): + logging.info("Tentativo invio URL: " + `numTry` ) + numTry = chiamaUrl(numTry) + time.sleep(3) + numTry = numTry + 1 + + +# registro che ho inviato! +logging.info("Inviato segnale di reboot!: " + url ) diff --git a/IOB-PI/std_v_2/sendRebootIOB b/IOB-PI/std_v_2/sendRebootIOB new file mode 100644 index 0000000..191bfff --- /dev/null +++ b/IOB-PI/std_v_2/sendRebootIOB @@ -0,0 +1,33 @@ +#!/bin/sh - +# +### BEGIN INIT INFO +# Provides: sendReboot +# Required-Start: $network $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Steamware's IOB reboot signal +# Description: Steamware's sendReboot segnalazione reboot dispositivo +### END INIT INFO + +#! /bin/sh +# /etc/init.d/sendReboot + + + +export HOME +case "$1" in + start) + cd /home/pi/steamware + echo "Starting sendReboot" + /usr/bin/python ./sendReboot.py 2>&1 & + echo "Verifica Rete e file IOB" + /usr/local/bin/setIobConf.sh + ;; + *) + echo "Usage: /etc/init.d/sendReboot {start}" + exit 1 + ;; +esac +exit 0 + diff --git a/IOB-PI/std_v_2/sendRebootIOB.service b/IOB-PI/std_v_2/sendRebootIOB.service new file mode 100644 index 0000000..48e3690 --- /dev/null +++ b/IOB-PI/std_v_2/sendRebootIOB.service @@ -0,0 +1,22 @@ +[Unit] +SourcePath=/etc/init.d/sendRebootIOB +Description=LSB: Steamware's IOB reboot signal +Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target +Wants=network-online.target +After=network.target network-online.target auditd.service +Conflicts=shutdown.target + +[Service] +Type=forking +Restart=no +TimeoutSec=5min +IgnoreSIGPIPE=no +KillMode=process +GuessMainPID=no +RemainAfterExit=yes +SysVStartPriority=2 +ExecStart=/etc/init.d/sendRebootIOB start +ExecStop=/etc/init.d/sendRebootIOB stop + +[Install] +WantedBy=multi-user.target diff --git a/IOB-PI/std_v_2/setIobConf.sh b/IOB-PI/std_v_2/setIobConf.sh new file mode 100644 index 0000000..30b4781 --- /dev/null +++ b/IOB-PI/std_v_2/setIobConf.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# verifico se sia rete donati o rete steamware o offline... +netStatus=`cat /sys/class/net/eth0/operstate` +iaddr=`ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1` + +cd /home/pi/steamware + +if [[ $netStatus != "up" ]] +then + echo "Siamo Offline, pagina demo!" +elif [[ $iaddr == "10.74.82"* ]] +then + cp IOB.cfg.steamware IOB.cfg -f + echo "Siamo in Steamware!" +elif [[ $iaddr == "192.168.51"* ]] +then + cp IOB.cfg.donati IOB.cfg -f + echo "Siamo a Passirano!" +else + echo "Siamo altrove, pagina demo!" +fi + +echo "$iaddr" + +chown pi:pi * \ No newline at end of file diff --git a/IOB-PI/std_v_2/unix.py b/IOB-PI/std_v_2/unix.py new file mode 100644 index 0000000..12fb3dc --- /dev/null +++ b/IOB-PI/std_v_2/unix.py @@ -0,0 +1,31 @@ +import fcntl +import os +import logging + +#--------------------------------------------------------------- +# meccanismo di file lock per evitare multiple instances +# The function will try to lock the file specified , if it success, return True, else return False. +# The nice thing is that the lock will be dropped when the program terminates. +# >>>Use : +# if not lockFile(".lock.pod"): +# sys.exit(0) + +def lockFile ( lockfile ) : + + fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY ) + try: + # Request exclusive (EX) non-blocking (NB) advisory lock. + fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB ) + except IOError: + return False + + return True + +if not lockFile ( ".lockfile" ) : + print '\n noi non siamo soli ...\n' + logging.error( "LOCK: Piu istanze aperte") + #sys.exit ( 0 ) + +#- print '\n running alone ...\n' + + diff --git a/IOB-PI/std_v_2/win.py b/IOB-PI/std_v_2/win.py new file mode 100644 index 0000000..f679f60 --- /dev/null +++ b/IOB-PI/std_v_2/win.py @@ -0,0 +1,32 @@ +import win32api +print " Running on WINDOWS\n" +import os +#--------------------------------------------------------------- +# meccanismo di file lock per evitare multiple instances +# The function will try to lock the file specified , if it success, return True, else return False. +# The nice thing is that the lock will be dropped when the program terminates. +# >>>Use : +# if not lockFile(".lock.pod"): +# sys.exit(0) + +def lockFile ( lockfile ) : + try: + fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY ) + except: + logga("Errore nel file WIN.PY per FD") + try: + # Request exclusive (EX) non-blocking (NB) advisory lock. + #fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB ) + print " Dummy Method! Completa Lockfile\n" + except IOError: + return False + + return True +try: + if not lockFile ( ".lockfile" ) : + print '\n noi non siamo soli ...\n' + logga ( "LOCK: Piu istanze aperte") + sys.exit ( 0 ) +except: + logga("if not lockfile NON RIUSCITO in file WIN.PY") + sys.exit(1)