Aggiunta macchina 2010 (EMCO LM1200)

This commit is contained in:
Samuele E. Locatelli
2018-07-10 17:46:53 +02:00
parent 42f26b823e
commit 6f65bc7f1c
27 changed files with 178007 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
[id]
idxMacchina = 2010
[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 = 0
bit4 = 0
bit5 = 0
bit6 = 0
bit7 = 0
+35
View File
@@ -0,0 +1,35 @@
[id]
idxMacchina = 2004
[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
+35
View File
@@ -0,0 +1,35 @@
[id]
idxMacchina = 1005
[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/MPIO/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
+41
View File
@@ -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
+28
View File
@@ -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
}
+20
View File
@@ -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
+14
View File
@@ -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
+46
View File
@@ -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')
+1
View File
@@ -0,0 +1 @@
* * * * * /bin/bash /home/pi/steamware/checkAlive.sh >> /home/pi/stdout 2>> /home/pi/stderr
+51
View File
@@ -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 "-----------------------------------------------"
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
/usr/bin/python /home/pi/steamware/readParallela.py
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
/usr/bin/python /home/steamware/readSeriale.py
+701
View File
@@ -0,0 +1,701 @@
20170207110000000#1#1912
20170207110001000#41#1913
20170207110001200#41#1914
20170207110017000#1#1915
20170207110018000#1#1916
20170207110019000#23#1917
20170207110020000#23#1918
20170207110033000#9#1919
20170207110033200#9#1920
20170207110034000#49#1921
20170207110034200#49#1922
20170207110034400#9#1923
20170207110034600#9#1924
20170207110036000#23#1925
20170207110036200#63#1926
20170207110037000#23#1927
20170207110037200#23#1928
20170207110038000#63#1929
20170207110038200#23#1930
20170207110038400#23#1931
20170207110041000#9#1932
20170207110041200#9#1933
20170207110042000#49#1934
20170207110042200#49#1935
20170207110043000#63#1936
20170207110043200#63#1937
20170207110045000#41#1938
20170207110046000#41#1939
20170207110135000#41#1940
20170207110226000#41#1941
20170207110316000#41#1942
20170207110322000#1#1943
20170207110323000#1#1944
20170207110324000#23#1945
20170207110325000#23#1946
20170207110347000#9#1947
20170207110348000#9#1948
20170207110348200#49#1949
20170207110348400#49#1950
20170207110348600#63#1951
20170207110349000#63#1952
20170207110351000#41#1953
20170207110352000#41#1954
20170207110416000#1#1955
20170207110417000#1#1956
20170207110418000#23#1957
20170207110419000#23#1958
20170207110435000#9#1959
20170207110435200#9#1960
20170207110436000#49#1961
20170207110436200#49#1962
20170207110436400#63#1963
20170207110437000#63#1964
20170207110439000#41#1965
20170207110439200#41#1966
20170207110515000#1#1967
20170207110515200#1#1968
20170207110517000#23#1969
20170207110517200#23#1970
20170207110607000#23#1971
20170207110657000#23#1972
20170207110747000#23#1973
20170207110837000#23#1974
20170207110927000#23#1975
20170207111017000#23#1976
20170207111107000#23#1977
20170207111157000#23#1978
20170207111247000#23#1979
20170207111338000#23#1980
20170207111428000#23#1981
20170207111518000#23#1982
20170207111608000#23#1983
20170207111618000#9#1984
20170207111618200#9#1985
20170207111619000#49#1986
20170207111619200#49#1987
20170207111619400#63#1988
20170207111620000#63#1989
20170207111622000#41#1990
20170207111623000#41#1991
20170207111625000#1#1992
20170207111625200#1#1993
20170207111627000#23#1994
20170207111627200#23#1995
20170207111643000#1#1996
20170207111643200#1#1997
20170207111659000#23#1998
20170207111659200#23#1999
20170207111704000#1#2000
20170207111704200#1#2001
20170207111720000#23#2002
20170207111720200#23#2003
20170207111724000#1#2004
20170207111725000#1#2005
20170207111745000#0#2006
20170207111745200#0#2007
20170207111802000#1#2008
20170207111802200#1#2009
20170207111852000#1#2010
20170207111942000#1#2011
20170207112032000#1#2012
20170207112035000#9#2013
20170207112035200#9#2014
20170207112036000#1#2015
20170207112036200#9#2016
20170207112036400#9#2017
20170207112037000#1#2018
20170207112037200#1#2019
20170207112037400#9#2020
20170207112038000#9#2021
20170207112040000#1#2022
20170207112040200#1#2023
20170207112041000#9#2024
20170207112041200#9#2025
20170207112054000#1#2026
20170207112054200#1#2027
20170207112059000#9#2028
20170207112059200#49#2029
20170207112059400#49#2030
20170207112100000#41#2031
20170207112100200#41#2032
20170207112103000#1#2033
20170207112103200#1#2034
20170207112114000#23#2035
20170207112114200#23#2036
20170207112118000#1#2037
20170207112118200#1#2038
20170207112125000#23#2039
20170207112125200#23#2040
20170207112215000#23#2041
20170207112231000#9#2042
20170207112231200#9#2043
20170207112231400#49#2044
20170207112232000#49#2045
20170207112232200#63#2046
20170207112232400#63#2047
20170207112235000#41#2048
20170207112235200#41#2049
20170207112310000#1#2050
20170207112311000#1#2051
20170207112312000#23#2052
20170207112313000#23#2053
20170207112314000#3#2054
20170207112314200#3#2055
20170207112314400#23#2056
20170207112314600#23#2057
20170207112318000#3#2058
20170207112318200#3#2059
20170207112408000#3#2060
20170207112458000#3#2061
20170207112548000#3#2062
20170207112638000#3#2063
20170207112728000#3#2064
20170207112818000#3#2065
20170207112908000#3#2066
20170207112958000#3#2067
20170207113048000#3#2068
20170207113049000#9#2069
20170207113050000#9#2070
20170207113140000#9#2071
20170207113230000#9#2072
20170207113320000#9#2073
20170207113410000#9#2074
20170207113500000#9#2075
20170207113550000#9#2076
20170207113640000#9#2077
20170207113730000#9#2078
20170207113820000#9#2079
20170207113910000#9#2080
20170207114000000#9#2081
20170207114050000#9#2082
20170207114140000#9#2083
20170207114231000#9#2084
20170207114321000#9#2085
20170207114411000#9#2086
20170207114501000#9#2087
20170207114551000#9#2088
20170207114641000#9#2089
20170207114731000#9#2090
20170207114821000#9#2091
20170207114911000#9#2092
20170207115001000#9#2093
20170207115051000#9#2094
20170207115141000#9#2095
20170207115231000#9#2096
20170207115322000#9#2097
20170207115412000#9#2098
20170207115502000#9#2099
20170207115552000#9#2100
20170207115642000#9#2101
20170207115732000#9#2102
20170207115822000#9#2103
20170207115912000#49#2104
20170207115912200#49#2105
20170207120002000#49#2106
20170207120052000#49#2107
20170207120142000#49#2108
20170207120216000#9#2109
20170207120217000#9#2110
20170207120218000#3#2111
20170207120219000#3#2112
20170207120308000#3#2113
20170207120359000#3#2114
20170207120449000#3#2115
20170207120539000#3#2116
20170207120629000#3#2117
20170207120719000#3#2118
20170207120809000#3#2119
20170207120859000#3#2120
20170207120946000#7#2121
20170207120947000#9#2122
20170207120947200#9#2123
20170207120957000#49#2124
20170207120957200#9#2125
20170207120957400#9#2126
20170207120958000#49#2127
20170207120958200#49#2128
20170207121048000#49#2129
20170207121138000#49#2130
20170207121143000#9#2131
20170207121143200#9#2132
20170207121144000#3#2133
20170207121144200#3#2134
20170207121234000#3#2135
20170207121324000#3#2136
20170207121414000#3#2137
20170207121504000#3#2138
20170207121554000#3#2139
20170207121644000#3#2140
20170207121735000#3#2141
20170207121825000#3#2142
20170207121913000#9#2143
20170207121913200#9#2144
20170207122003000#9#2145
20170207122053000#9#2146
20170207122141000#49#2147
20170207122141200#49#2148
20170207122231000#49#2149
20170207122254000#9#2150
20170207122254200#9#2151
20170207122255000#3#2152
20170207122255200#3#2153
20170207122345000#3#2154
20170207122435000#3#2155
20170207122525000#3#2156
20170207122616000#3#2157
20170207122706000#3#2158
20170207122756000#3#2159
20170207122846000#3#2160
20170207122936000#3#2161
20170207123023000#7#2162
20170207123023200#9#2163
20170207123024000#9#2164
20170207123113000#9#2165
20170207123124000#49#2166
20170207123124200#49#2167
20170207123214000#49#2168
20170207123239000#9#2169
20170207123239200#49#2170
20170207123240000#9#2171
20170207123240200#9#2172
20170207123241000#3#2173
20170207123241200#3#2174
20170207123331000#3#2175
20170207123421000#3#2176
20170207123511000#3#2177
20170207123601000#3#2178
20170207123652000#3#2179
20170207123742000#3#2180
20170207123832000#3#2181
20170207123922000#3#2182
20170207124008000#7#2183
20170207124009000#9#2184
20170207124009200#9#2185
20170207124054000#49#2186
20170207124054200#49#2187
20170207124144000#49#2188
20170207124200000#9#2189
20170207124200200#9#2190
20170207124250000#9#2191
20170207124340000#9#2192
20170207124430000#9#2193
20170207124520000#9#2194
20170207124610000#9#2195
20170207124700000#9#2196
20170207124724000#23#2197
20170207124724200#23#2198
20170207124725000#3#2199
20170207124725200#3#2200
20170207124815000#3#2201
20170207124905000#3#2202
20170207124955000#3#2203
20170207125045000#3#2204
20170207125135000#3#2205
20170207125225000#3#2206
20170207125315000#3#2207
20170207125405000#3#2208
20170207125453000#9#2209
20170207125453200#9#2210
20170207125519000#49#2211
20170207125519200#49#2212
20170207125609000#49#2213
20170207125641000#9#2214
20170207125641200#9#2215
20170207125643000#3#2216
20170207125643200#3#2217
20170207125733000#3#2218
20170207125823000#3#2219
20170207125913000#3#2220
20170207130003000#3#2221
20170207130053000#3#2222
20170207130143000#3#2223
20170207130233000#3#2224
20170207130323000#3#2225
20170207130411000#7#2226
20170207130411200#9#2227
20170207130412000#9#2228
20170207130423000#49#2229
20170207130423200#49#2230
20170207130513000#49#2231
20170207130535000#9#2232
20170207130535200#9#2233
20170207130537000#3#2234
20170207130537200#3#2235
20170207130627000#3#2236
20170207130717000#3#2237
20170207130807000#3#2238
20170207130857000#3#2239
20170207130948000#3#2240
20170207131038000#3#2241
20170207131128000#3#2242
20170207131218000#3#2243
20170207131305000#7#2244
20170207131305200#9#2245
20170207131305400#9#2246
20170207131355000#9#2247
20170207131356000#49#2248
20170207131357000#49#2249
20170207131446000#49#2250
20170207131459000#9#2251
20170207131459200#9#2252
20170207131500000#3#2253
20170207131500200#3#2254
20170207131550000#3#2255
20170207131640000#3#2256
20170207131730000#3#2257
20170207131821000#3#2258
20170207131911000#3#2259
20170207132001000#3#2260
20170207132051000#3#2261
20170207132141000#3#2262
20170207132228000#9#2263
20170207132228200#9#2264
20170207132303000#49#2265
20170207132304000#49#2266
20170207132353000#49#2267
20170207132421000#9#2268
20170207132421200#9#2269
20170207132423000#3#2270
20170207132423200#3#2271
20170207132513000#3#2272
20170207132603000#3#2273
20170207132653000#3#2274
20170207132743000#3#2275
20170207132833000#3#2276
20170207132923000#3#2277
20170207133013000#3#2278
20170207133103000#3#2279
20170207133151000#7#2280
20170207133152000#9#2281
20170207133152200#9#2282
20170207133205000#49#2283
20170207133206000#49#2284
20170207133255000#49#2285
20170207133311000#9#2286
20170207133312000#9#2287
20170207133313000#3#2288
20170207133313200#3#2289
20170207133403000#3#2290
20170207133453000#3#2291
20170207133543000#3#2292
20170207133633000#3#2293
20170207133723000#3#2294
20170207133813000#3#2295
20170207133903000#3#2296
20170207133954000#3#2297
20170207134040000#7#2298
20170207134040200#9#2299
20170207134040400#9#2300
20170207134130000#9#2301
20170207134156000#49#2302
20170207134156200#49#2303
20170207134246000#49#2304
20170207134314000#9#2305
20170207134314200#9#2306
20170207134316000#3#2307
20170207134316200#3#2308
20170207134406000#3#2309
20170207134456000#3#2310
20170207134546000#3#2311
20170207134636000#3#2312
20170207134726000#3#2313
20170207134816000#3#2314
20170207134907000#3#2315
20170207134957000#3#2316
20170207135045000#9#2317
20170207135045200#9#2318
20170207135059000#49#2319
20170207135100000#49#2320
20170207135149000#49#2321
20170207135212000#9#2322
20170207135212200#9#2323
20170207135214000#3#2324
20170207135214200#3#2325
20170207135304000#3#2326
20170207135354000#3#2327
20170207135444000#3#2328
20170207135534000#3#2329
20170207135624000#3#2330
20170207135715000#3#2331
20170207135805000#3#2332
20170207135855000#3#2333
20170207135942000#9#2334
20170207135942200#9#2335
20170207140009000#49#2336
20170207140009200#49#2337
20170207140059000#49#2338
20170207140139000#9#2339
20170207140139200#9#2340
20170207140140000#3#2341
20170207140140200#3#2342
20170207140230000#3#2343
20170207140320000#3#2344
20170207140410000#3#2345
20170207140500000#3#2346
20170207140550000#3#2347
20170207140640000#3#2348
20170207140730000#3#2349
20170207140821000#3#2350
20170207140908000#9#2351
20170207140908200#9#2352
20170207140919000#49#2353
20170207140919200#49#2354
20170207141009000#49#2355
20170207141024000#9#2356
20170207141025000#9#2357
20170207141026000#3#2358
20170207141026200#3#2359
20170207141116000#3#2360
20170207141206000#3#2361
20170207141256000#3#2362
20170207141346000#3#2363
20170207141436000#3#2364
20170207141526000#3#2365
20170207141616000#3#2366
20170207141706000#3#2367
20170207141753000#9#2368
20170207141753200#9#2369
20170207141758000#49#2370
20170207141758200#49#2371
20170207141848000#49#2372
20170207141915000#9#2373
20170207141915200#9#2374
20170207141916000#3#2375
20170207141916200#3#2376
20170207142006000#3#2377
20170207142056000#3#2378
20170207142146000#3#2379
20170207142236000#3#2380
20170207142327000#3#2381
20170207142417000#3#2382
20170207142507000#3#2383
20170207142557000#3#2384
20170207142642000#7#2385
20170207142643000#9#2386
20170207142643200#9#2387
20170207142722000#49#2388
20170207142722200#49#2389
20170207142812000#49#2390
20170207142847000#9#2391
20170207142847200#9#2392
20170207142848000#3#2393
20170207142849000#3#2394
20170207142938000#3#2395
20170207143029000#3#2396
20170207143119000#3#2397
20170207143209000#3#2398
20170207143259000#3#2399
20170207143349000#3#2400
20170207143439000#3#2401
20170207143529000#3#2402
20170207143616000#9#2403
20170207143616200#9#2404
20170207143637000#49#2405
20170207143637200#9#2406
20170207143638000#9#2407
20170207143638200#49#2408
20170207143638400#49#2409
20170207143638600#9#2410
20170207143638800#9#2411
20170207143639000#49#2412
20170207143639200#49#2413
20170207143729000#49#2414
20170207143805000#9#2415
20170207143806000#9#2416
20170207143807000#3#2417
20170207143807200#3#2418
20170207143857000#3#2419
20170207143947000#3#2420
20170207144037000#3#2421
20170207144127000#3#2422
20170207144217000#3#2423
20170207144308000#3#2424
20170207144358000#3#2425
20170207144448000#3#2426
20170207144534000#9#2427
20170207144535000#9#2428
20170207144546000#49#2429
20170207144546200#49#2430
20170207144636000#49#2431
20170207144714000#9#2432
20170207144714200#9#2433
20170207144716000#3#2434
20170207144716200#3#2435
20170207144806000#3#2436
20170207144856000#3#2437
20170207144946000#3#2438
20170207145036000#3#2439
20170207145126000#3#2440
20170207145217000#3#2441
20170207145307000#3#2442
20170207145357000#3#2443
20170207145444000#9#2444
20170207145444200#9#2445
20170207145534000#9#2446
20170207145624000#9#2447
20170207145714000#9#2448
20170207145804000#9#2449
20170207145852000#49#2450
20170207145852200#49#2451
20170207145942000#49#2452
20170207145959000#9#2453
20170207145959200#9#2454
20170207150000000#3#2455
20170207150001000#3#2456
20170207150051000#3#2457
20170207150141000#3#2458
20170207150231000#3#2459
20170207150321000#3#2460
20170207150411000#3#2461
20170207150501000#3#2462
20170207150551000#3#2463
20170207150641000#3#2464
20170207150728000#7#2465
20170207150728200#9#2466
20170207150728400#9#2467
20170207150818000#9#2468
20170207150844000#49#2469
20170207150844200#49#2470
20170207150934000#49#2471
20170207151009000#9#2472
20170207151009200#9#2473
20170207151011000#3#2474
20170207151011200#3#2475
20170207151101000#3#2476
20170207151151000#3#2477
20170207151241000#3#2478
20170207151331000#3#2479
20170207151421000#3#2480
20170207151511000#3#2481
20170207151601000#3#2482
20170207151651000#3#2483
20170207151738000#7#2484
20170207151739000#9#2485
20170207151739200#9#2486
20170207151822000#49#2487
20170207151823000#49#2488
20170207151912000#49#2489
20170207151942000#9#2490
20170207151943000#49#2491
20170207151943200#9#2492
20170207151943400#9#2493
20170207151946000#3#2494
20170207151946200#3#2495
20170207152036000#3#2496
20170207152126000#3#2497
20170207152216000#3#2498
20170207152306000#3#2499
20170207152356000#3#2500
20170207152446000#3#2501
20170207152536000#3#2502
20170207152626000#3#2503
20170207152713000#7#2504
20170207152713200#9#2505
20170207152713400#9#2506
20170207152747000#49#2507
20170207152747200#49#2508
20170207152837000#49#2509
20170207152917000#9#2510
20170207152918000#9#2511
20170207152920000#3#2512
20170207152920200#3#2513
20170207153010000#3#2514
20170207153100000#3#2515
20170207153150000#3#2516
20170207153240000#3#2517
20170207153330000#3#2518
20170207153420000#3#2519
20170207153510000#3#2520
20170207153600000#3#2521
20170207153647000#7#2522
20170207153647200#9#2523
20170207153647400#9#2524
20170207153650000#49#2525
20170207153650200#49#2526
20170207153740000#49#2527
20170207153750000#9#2528
20170207153750200#9#2529
20170207153751000#3#2530
20170207153751200#3#2531
20170207153841000#3#2532
20170207153931000#3#2533
20170207154022000#3#2534
20170207154112000#3#2535
20170207154202000#3#2536
20170207154252000#3#2537
20170207154342000#3#2538
20170207154432000#3#2539
20170207154519000#9#2540
20170207154519200#9#2541
20170207154548000#49#2542
20170207154549000#49#2543
20170207154638000#49#2544
20170207154714000#9#2545
20170207154714200#9#2546
20170207154719000#3#2547
20170207154719200#3#2548
20170207154809000#3#2549
20170207154859000#3#2550
20170207154949000#3#2551
20170207155039000#3#2552
20170207155130000#3#2553
20170207155220000#3#2554
20170207155310000#3#2555
20170207155400000#3#2556
20170207155446000#9#2557
20170207155446200#9#2558
20170207155519000#49#2559
20170207155520000#49#2560
20170207155610000#49#2561
20170207155620000#9#2562
20170207155620200#9#2563
20170207155621000#3#2564
20170207155621200#3#2565
20170207155711000#3#2566
20170207155801000#3#2567
20170207155851000#3#2568
20170207155941000#3#2569
20170207160031000#3#2570
20170207160121000#3#2571
20170207160212000#3#2572
20170207160302000#3#2573
20170207160348000#7#2574
20170207160349000#9#2575
20170207160349200#9#2576
20170207160427000#49#2577
20170207160427200#49#2578
20170207160517000#49#2579
20170207160548000#9#2580
20170207160548200#9#2581
20170207160550000#3#2582
20170207160550200#3#2583
20170207160640000#3#2584
20170207160730000#3#2585
20170207160821000#3#2586
20170207160911000#3#2587
20170207161001000#3#2588
20170207161051000#3#2589
20170207161141000#3#2590
20170207161231000#3#2591
20170207161318000#7#2592
20170207161318200#9#2593
20170207161319000#9#2594
20170207161408000#9#2595
20170207161459000#9#2596
20170207161549000#9#2597
20170207161639000#9#2598
20170207161729000#9#2599
20170207161819000#9#2600
20170207161826000#49#2601
20170207161826200#49#2602
20170207161827000#9#2603
20170207161827200#9#2604
20170207161827400#49#2605
20170207161827600#49#2606
20170207161836000#41#2607
20170207161836200#41#2608
20170207161926000#41#2609
20170207162016000#41#2610
20170207162106000#41#2611
20170207162156000#41#2612
File diff suppressed because it is too large Load Diff
+152
View File
@@ -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 = "2000"
#--------------------------------------------------------------
# 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
+608
View File
@@ -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
+363
View File
@@ -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 xx<ACK>i00 00<CR><LF>xxx
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
+17
View File
@@ -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
+130
View File
@@ -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 )
+33
View File
@@ -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
@@ -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
+26
View File
@@ -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 *
+31
View File
@@ -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'
Binary file not shown.
+32
View File
@@ -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)
Binary file not shown.