Compare commits
232 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b1a6235a7 | |||
| 71557f9336 | |||
| 0015d54f60 | |||
| 01926cca84 | |||
| 08893d7954 | |||
| 77a8602d40 | |||
| 31ecb827f2 | |||
| 6fedee77b2 | |||
| 14f48e4d5c | |||
| 42fa3db8be | |||
| 93eb3977a0 | |||
| f53fc4c53f | |||
| 0327246395 | |||
| 762b4f70ed | |||
| 55f40679b5 | |||
| 3b55637cd7 | |||
| 6b4ca6bd6c | |||
| 1620ba43d5 | |||
| 5fed4d1ef2 | |||
| f7cff6e969 | |||
| e124ebfd97 | |||
| e94c621b96 | |||
| 872f66eee4 | |||
| 1924809d0f | |||
| deca006214 | |||
| 9eb16e3e65 | |||
| 06e5d6ceb2 | |||
| 4ecc3070cc | |||
| 75e142f607 | |||
| f52348912a | |||
| 632a17a62c | |||
| 7ad9cf43ab | |||
| 9b74406d23 | |||
| 81ee1dacd6 | |||
| 90e3efb5cc | |||
| 79f217f250 | |||
| 6e27d14e7e | |||
| 2ab0093423 | |||
| 48f8549401 | |||
| 46133bc94e | |||
| 79a8746aac | |||
| e24fce9a2a | |||
| ca580fb771 | |||
| 8556dbb0cd | |||
| 648ab698fb | |||
| 5845b21631 | |||
| b1d4c4a75e | |||
| 32639151c7 | |||
| 3cbffb991a | |||
| 5df0e12766 | |||
| 56a2ae5852 | |||
| 77460d1b81 | |||
| 1bef600b67 | |||
| 6c742962d1 | |||
| dea7856c7f | |||
| 94a417b169 | |||
| 88f4dae076 | |||
| 77e9dedc46 | |||
| 09bca1a908 | |||
| 46e111e891 | |||
| 484208bd14 | |||
| 44cdd84b99 | |||
| 98bbb01903 | |||
| 5d090083da | |||
| 7a1cc4789a | |||
| 81e87dd089 | |||
| c6239fcbd1 | |||
| 639a82ad25 | |||
| b5fa1ffa35 | |||
| 16f68cdd5f | |||
| e246e919d0 | |||
| 6a17af857f | |||
| 1310ef6121 | |||
| 7f56a210dd | |||
| aea7afa4ef | |||
| 4ecaae4867 | |||
| 781c1bc1dc | |||
| fea49968a0 | |||
| a129e15c06 | |||
| 06093b509e | |||
| 79b5beed5c | |||
| c129b35e06 | |||
| 9996d6df76 | |||
| ff8271d7d6 | |||
| 5958e300f4 | |||
| b2679d52e2 | |||
| 492c21a109 | |||
| 7f75622f8c | |||
| dab1a83722 | |||
| 6b37e12732 | |||
| 7007241ed7 | |||
| 9bac4a473e | |||
| 6d50259b7e | |||
| 7f1c430ea3 | |||
| e955fc3791 | |||
| ec9b300ef3 | |||
| 542086ce93 | |||
| dc8565640a | |||
| 351fce46e3 | |||
| 7e65cf4cc9 | |||
| 29f625b2c2 | |||
| 7bf9062e1b | |||
| 3eb4b86cd6 | |||
| 9a0f388733 | |||
| 129d63cd1a | |||
| 57e647efd3 | |||
| ab6b2ea2a9 | |||
| cf941dcede | |||
| d7cb3d2dbc | |||
| 061e3aaf68 | |||
| 3b7b81cc4a | |||
| 2939dfb093 | |||
| 22909f3fdd | |||
| c9e4c53114 | |||
| fb0acf97e5 | |||
| 26c39d1ddc | |||
| 4466ac88e6 | |||
| 52209ce3ea | |||
| 5d2fab0ea0 | |||
| 8b9c4cac06 | |||
| 5758f998bd | |||
| 7317b6fc80 | |||
| bf81aaac63 | |||
| 424c4b1641 | |||
| f867cba96a | |||
| 329fd4b099 | |||
| 3f1c488685 | |||
| 7eeb21df0c | |||
| 5026e4bd02 | |||
| c668c67b5d | |||
| 0c843bfe2b | |||
| 618b76ab28 | |||
| 970f36060e | |||
| ce7ae13863 | |||
| ac825efca6 | |||
| d1f7506087 | |||
| 6cd06e6278 | |||
| 6bfc2670d7 | |||
| a5e0cb7bae | |||
| 3063d3bdef | |||
| fb2f83603a | |||
| b4e56f960e | |||
| 645cf9aea3 | |||
| 2c7a7d8035 | |||
| 2f13e828c3 | |||
| a1926bc4f1 | |||
| a0afc0523e | |||
| 8bcbb88dc2 | |||
| b7ef2f60e8 | |||
| a555828c35 | |||
| a85fc3b496 | |||
| e33f18c02d | |||
| 74f31ce985 | |||
| 2150a3c402 | |||
| 08b98c64e5 | |||
| d4e4c83acd | |||
| 0ed470c610 | |||
| a049b84f16 | |||
| c1e7970eec | |||
| da26f57e75 | |||
| cd34987745 | |||
| 6464dc8941 | |||
| 62fdd76bb4 | |||
| 78e22cf5ad | |||
| e58ee47832 | |||
| 8def552ab9 | |||
| 398fe142ca | |||
| 8c998cd46e | |||
| 8f9122478f | |||
| a6788be49f | |||
| 45c0c8bc07 | |||
| 476390cd78 | |||
| 60b652f261 | |||
| e06da6057b | |||
| ac3534469e | |||
| fc5164fa1c | |||
| 31bf7139b4 | |||
| 6ac83202e3 | |||
| 8cc99c4805 | |||
| 757e8ba066 | |||
| de33b976d3 | |||
| 2f7f9f2c6c | |||
| 29255f89a0 | |||
| f33f796500 | |||
| f273e3b4ff | |||
| 18ff37d151 | |||
| e5540022eb | |||
| 9808844664 | |||
| 6e93cd0dd4 | |||
| 85c6dbeeb7 | |||
| 5a5b09c58a | |||
| 8b066b6e8b | |||
| f4a98addac | |||
| 8a093882f4 | |||
| 79c368846b | |||
| 4ff712c193 | |||
| a8442048d0 | |||
| 278ce688f7 | |||
| a9e6afd047 | |||
| 39eb52d59b | |||
| 140f6bd3a7 | |||
| 0ab3c9a004 | |||
| 7c7363bdf8 | |||
| d1af037e7f | |||
| 3cebf9f04d | |||
| e4d6d2a319 | |||
| 1b718a6d95 | |||
| c897768950 | |||
| 3712099ee1 | |||
| 44d4aeefad | |||
| a7a0fc63bb | |||
| 50d1bdfd49 | |||
| 1a705c1a4b | |||
| 337e84863c | |||
| d135b5f6d0 | |||
| 068460366e | |||
| 3b486c786c | |||
| 5917f2e653 | |||
| 74bb36276b | |||
| c672da3009 | |||
| f8e8240f11 | |||
| 3c1c72b20d | |||
| 8cae35ba57 | |||
| 01421786af | |||
| b5493cdac1 | |||
| 302708e999 | |||
| afbc4e3a28 | |||
| 2ad3736d4d | |||
| 7dd98135d4 | |||
| e055dc61af | |||
| 8469dd4643 | |||
| a039716dae |
@@ -331,3 +331,9 @@ _Pvt_Extensions
|
||||
.settings
|
||||
|
||||
|
||||
# Area temp
|
||||
|
||||
/SMGen/*/unsafe_uploads/*
|
||||
/SMGen/*/Rules/*/*
|
||||
/SMGen/*/Rules/*
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
variables:
|
||||
VERS_MAIN: '0.9'
|
||||
NEW_REL: ''
|
||||
APP_NAME: 'SMGen'
|
||||
SOL_NAME: 'SMGen'
|
||||
|
||||
# helper x fix pacchetti nuget da repo locale nexus.steamware.net
|
||||
.nuget-fix: &nuget-fix
|
||||
- |
|
||||
echo "esecuzione Nuget FIX steps"
|
||||
dotnet nuget list source
|
||||
$hasSource = dotnet nuget list source | Select-String -Pattern "Steamware Nexus Proxy"
|
||||
if (! [String]::IsNullOrWhiteSpace($hasSource)) {
|
||||
dotnet nuget remove source "`"Steamware Nexus Proxy`""
|
||||
}
|
||||
$hasSource = dotnet nuget list source | Select-String -Pattern "Steamware Nexus"
|
||||
if (! [String]::IsNullOrWhiteSpace($hasSource)) {
|
||||
dotnet nuget remove source "`"Steamware Nexus`""
|
||||
}
|
||||
$hasSource = dotnet nuget list source | Select-String -Pattern "nexus-proxy-v3"
|
||||
if (! [String]::IsNullOrWhiteSpace($hasSource)) {
|
||||
dotnet nuget remove source nexus-proxy-v3
|
||||
}
|
||||
dotnet nuget add source https://nexus.steamware.net/repository/nuget-group-3/index.json -n "Steamware Nexus" -u nugetUser -p $NEXUS_PASSWD --store-password-in-clear-text
|
||||
echo "Steamware Nexus Source added"
|
||||
|
||||
|
||||
|
||||
stages:
|
||||
- build
|
||||
- staging
|
||||
- deploy
|
||||
|
||||
# ---------- BUILD ----------
|
||||
SMGen:build:
|
||||
stage: build
|
||||
tags:
|
||||
- win
|
||||
variables:
|
||||
APP_NAME: SMGen
|
||||
SOL_NAME: SMGen
|
||||
before_script:
|
||||
- *nuget-fix
|
||||
- dotnet restore "$env:SOL_NAME.sln"
|
||||
script:
|
||||
- dotnet build $env:APP_NAME/$env:APP_NAME.csproj
|
||||
|
||||
|
||||
# ---------- STAGING ----------
|
||||
SMGen:staging:
|
||||
stage: staging
|
||||
tags:
|
||||
- win
|
||||
variables:
|
||||
APP_NAME: SMGen
|
||||
SOL_NAME: SMGen
|
||||
only:
|
||||
- develop
|
||||
needs: ["SMGen:build"]
|
||||
before_script:
|
||||
- *nuget-fix
|
||||
- dotnet restore "$env:SOL_NAME.sln"
|
||||
script:
|
||||
- dotnet build $env:APP_NAME/$env:APP_NAME.csproj
|
||||
- dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=$IIS_PWD -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj
|
||||
|
||||
# ---------- DEPLOY ----------
|
||||
SMGen:deploy:
|
||||
stage: deploy
|
||||
tags:
|
||||
- win
|
||||
environment:
|
||||
name: production
|
||||
url: https://office.egalware.com/MP/SMGEN
|
||||
variables:
|
||||
APP_NAME: SMGen
|
||||
SOL_NAME: SMGen
|
||||
only:
|
||||
- master
|
||||
needs: ["SMGen:build"]
|
||||
before_script:
|
||||
- *nuget-fix
|
||||
- dotnet restore "$env:SOL_NAME.sln"
|
||||
script:
|
||||
- dotnet build $env:APP_NAME/$env:APP_NAME.csproj
|
||||
# IIS PROD
|
||||
- dotnet publish -p:PublishProfile=IIS-PROD.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=$IIS_PWD -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -62,6 +62,6 @@ echo "$(date) | chiusura processi precedenti!" >> $logFile
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
echo "$(date) | apertura nuovo URL!" >> $logFile
|
||||
DISPLAY=:0.0 chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -61,6 +61,6 @@ fi
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -61,6 +61,6 @@ fi
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -61,6 +61,6 @@ fi
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -61,6 +61,6 @@ fi
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.219/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.219/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.219/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.20
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -62,6 +62,6 @@ echo "$(date) | chiusura processi precedenti!" >> $logFile
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
echo "$(date) | apertura nuovo URL!" >> $logFile
|
||||
DISPLAY=:0.0 chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -61,6 +61,6 @@ fi
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
ven 14 ott 2016, 16.24.45, CEST | Cavo connesso, eth: up
|
||||
ven 14 ott 2016, 16.24.45, CEST | IP: 10.74.82.23
|
||||
ven 14 ott 2016, 16.24.45, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.219/MP-MON!
|
||||
ven 14 ott 2016, 16.24.45, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.218/MP-MON!
|
||||
ven 14 ott 2016, 16.29.23, CEST | Cavo connesso, eth: up
|
||||
ven 14 ott 2016, 16.29.23, CEST | IP: 10.74.82.23
|
||||
ven 14 ott 2016, 16.29.23, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.219/MP-MON!
|
||||
ven 14 ott 2016, 16.29.23, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.218/MP-MON!
|
||||
sab 19 nov 2016, 07.17.19, CET | Cavo connesso, eth: up
|
||||
sab 19 nov 2016, 07.17.19, CET | IP: 192.168.51.173
|
||||
sab 19 nov 2016, 07.17.19, CET | Siamo a Passirano, imposto pagina a http://192.168.51.71/MP-MON!
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -61,6 +61,6 @@ fi
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
ven 14 ott 2016, 16.46.26, CEST | Cavo connesso, eth: up
|
||||
ven 14 ott 2016, 16.46.26, CEST | IP: 10.74.82.23
|
||||
ven 14 ott 2016, 16.46.26, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.219/MP-MON!
|
||||
ven 14 ott 2016, 16.46.26, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.218/MP-MON!
|
||||
ven 14 ott 2016, 16.47.44, CEST | Cavo connesso, eth: up
|
||||
ven 14 ott 2016, 16.47.44, CEST | IP: 10.74.82.23
|
||||
ven 14 ott 2016, 16.47.44, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.219/MP-MON!
|
||||
ven 14 ott 2016, 16.47.44, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.218/MP-MON!
|
||||
sab 17 dic 2016, 11.17.20, CET | Cavo connesso, eth: up
|
||||
lun 19 dic 2016, 06.44.42, CET | IP: 192.168.51.174
|
||||
lun 19 dic 2016, 06.44.42, CET | Siamo a Passirano, imposto pagina a http://192.168.51.71/MP-MON!
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -61,6 +61,6 @@ fi
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
ven 14 ott 2016, 16.41.10, CEST | Cavo connesso, eth: up
|
||||
ven 14 ott 2016, 16.41.10, CEST | IP: 10.74.82.23
|
||||
ven 14 ott 2016, 16.41.10, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.219/MP-MON!
|
||||
ven 14 ott 2016, 16.41.10, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.218/MP-MON!
|
||||
ven 14 ott 2016, 16.43.19, CEST | Cavo connesso, eth: up
|
||||
ven 14 ott 2016, 16.43.19, CEST | IP: 10.74.82.23
|
||||
ven 14 ott 2016, 16.43.19, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.219/MP-MON!
|
||||
ven 14 ott 2016, 16.43.19, CEST | Siamo in Steamware, imposto pagina a http://10.74.82.218/MP-MON!
|
||||
ven 16 dic 2016, 19.17.19, CET | Cavo connesso, eth: up
|
||||
ven 16 dic 2016, 19.17.19, CET | IP: 192.168.51.175
|
||||
ven 16 dic 2016, 19.17.19, CET | Siamo a Passirano, imposto pagina a http://192.168.51.71/MP-MON!
|
||||
|
||||
@@ -47,7 +47,7 @@ url='file:///home/pi/steamware/MP-MON-DEMO.html'
|
||||
|
||||
if [[ $iaddr == "10.74.82"* ]]
|
||||
then
|
||||
url='http://10.74.82.219/MP-MON'
|
||||
url='http://10.74.82.218/MP-MON'
|
||||
echo "$(date) | Siamo in Steamware, imposto pagina a $url!" >> $logFile
|
||||
elif [[ $iaddr == "192.168.51"* ]]
|
||||
then
|
||||
@@ -61,6 +61,6 @@ fi
|
||||
killall -9 chromium-browser
|
||||
|
||||
# avvio chromium in KIOSK senza segnalazione errori...
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.219/MP-MON --incognito --disable-translate
|
||||
#chromium-browser --noerrdialogs --kiosk http://10.74.82.218/MP-MON --incognito --disable-translate
|
||||
chromium-browser --noerrdialogs --kiosk $url --incognito --disable-translate
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
Binary file not shown.
@@ -6,11 +6,11 @@ port = COM1
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
Binary file not shown.
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
+16
-1
@@ -1,3 +1,18 @@
|
||||
# Upgrade sw IOB-PI clienti
|
||||
|
||||
ATTENZIONE: se si copia dalla versione standard, SUL PI VA DATO un dos2unix * x tutti i files..
|
||||
ATTENZIONE: se si copia dalla versione standard, SUL PI VA DATO un dos2unix * x tutti i files..
|
||||
|
||||
## Salt install##
|
||||
|
||||
Se il minion è taggato come iop-pi bast dare state apply, poiché dallo stato top.sls è configurato di fare gli stati
|
||||
* iob-pi.sls
|
||||
* iob-setup.sls
|
||||
|
||||
|
||||
## MD5 zip##
|
||||
|
||||
creazione MD5: da powershell
|
||||
|
||||
<code>
|
||||
Get-FileHash .\Mapo.zip -Algorithm MD5
|
||||
</code>
|
||||
Binary file not shown.
@@ -0,0 +1,796 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# readParallela v. 2.5.2 12 Ingressi
|
||||
# - single instance timer
|
||||
# - invio multiplo x send eventi accodati
|
||||
# - gestione segnali BLINKING
|
||||
# - gestione INVERSIONE segnali cv 10-VII-2018
|
||||
# - gestione FILTRAGGIO segnali brevi cv 23-VII-2018
|
||||
# - (2.3) gestione 12 bit cv 14-I-2020
|
||||
# - (2.4) fix ingressi e conf apertura parallela + gestione vari bit filtraggio x nuovi ingressi + update conf con 12 parametri bit SEL 15-I-2020
|
||||
# - (2.4.8) versione adatta a raspberry PI vecchia generazione (GPIO corto, 8bit)
|
||||
# - (2.5) Fix (hope) ciclo "wait send to complete", gestione timeout (rety infinito se IO riparte in modo anomalo)
|
||||
# - (2.5.1) Fix numero versione 18.05.2023
|
||||
# - (2.5.2) Fix gestione eccezioni con report dettagliato
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# levare locking
|
||||
# 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 = 10
|
||||
|
||||
# numero campioni filtraggio segnale ballerino
|
||||
MAX_COUNTER_BLINK = 10
|
||||
|
||||
PROGRAM_NAME ="ReadPar IOB-pi v.2.5.2"
|
||||
|
||||
# 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
|
||||
in_8 = 29
|
||||
in_9 = 31
|
||||
in_10 = 32
|
||||
in_11 = 36
|
||||
|
||||
# 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,0,0,0,0])
|
||||
B_blinking = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0])
|
||||
B_previous = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0])
|
||||
B_input = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0])
|
||||
B_output = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0])
|
||||
|
||||
B_inverting = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0])
|
||||
|
||||
B_filter = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0])
|
||||
B_filter_prev = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0])
|
||||
B_temp = array ( 'B',[0,0,0,0,0,0,0,0,0,0,0,0])
|
||||
i_filter_counters = array ( 'i',[0,0,0,0,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 in_8
|
||||
global in_9
|
||||
global in_10
|
||||
global in_11
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
if GPIO.input(in_8):
|
||||
B_input[8] = 0
|
||||
else:
|
||||
B_input[8] = 1
|
||||
|
||||
if GPIO.input(in_9):
|
||||
B_input[9] = 0
|
||||
else:
|
||||
B_input[9] = 1
|
||||
|
||||
if GPIO.input(in_10):
|
||||
B_input[10] = 0
|
||||
else:
|
||||
B_input[10] = 1
|
||||
|
||||
if GPIO.input(in_11):
|
||||
B_input[11] = 0
|
||||
else:
|
||||
B_input[11] = 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ciclo per ogni segnale
|
||||
for i in xrange(12) :
|
||||
#print (i)
|
||||
|
||||
# v2.1 gestione inversione bit ingresso
|
||||
|
||||
if ( B_inverting[i] == 1 ) :
|
||||
if ( B_input[i] == 0 ) :
|
||||
B_input[i] = 1
|
||||
else :
|
||||
B_input[i] = 0
|
||||
|
||||
# v2.2 gestione filtro segnali brevi
|
||||
|
||||
if ( B_filter[i] == 1 ) :
|
||||
|
||||
# fronte 0 -> 1
|
||||
if ( B_input[i] == 1 ) and ( B_filter_prev [i] == 0 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# vero fronte 0 -> 1
|
||||
i_filter_counters[i] = MAX_COUNTER_FILTER
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
#logPro.info("START spike 0->1 on bit " + `i` )
|
||||
else :
|
||||
# fine disturbo breve di uno stato 1
|
||||
i_filter_counters[i] = 0
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
logPro.info("END spike 0->1 on bit " + `i` )
|
||||
|
||||
# stabile 1 -> 1
|
||||
if ( B_input[i] == 1 ) and ( B_filter_prev [i] == 1 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# segnale stabile a 1
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
else :
|
||||
# poco dopo il fronte
|
||||
i_filter_counters[i] = i_filter_counters[i] - 1
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
|
||||
# fronte 1 -> 0
|
||||
if ( B_input[i] == 0 ) and ( B_filter_prev [i] == 1 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# vero fronte 1 -> 0
|
||||
i_filter_counters[i] = MAX_COUNTER_FILTER
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
#logPro.info("START spike 1->0 on bit " + `i` )
|
||||
else :
|
||||
# fine disturbo breve di uno stato 0
|
||||
i_filter_counters[i] = 0
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
logPro.info("END spike 1->0 on bit " + `i` )
|
||||
|
||||
# stabile 0 -> 0
|
||||
if ( B_input[i] == 0 ) and ( B_filter_prev [i] == 0 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# segnale stabile a 0
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
else :
|
||||
# poco dopo il fronte
|
||||
i_filter_counters[i] = i_filter_counters[i] - 1
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
|
||||
B_filter_prev [i] = B_input[i]
|
||||
B_input[i] = B_temp[i]
|
||||
|
||||
# fine gestione filtro segnali brevi
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
if ( B_output[8] == 1 ) :
|
||||
new_value = new_value + 256
|
||||
if ( B_output[9] == 1 ) :
|
||||
new_value = new_value + 512
|
||||
if ( B_output[10] == 1 ) :
|
||||
new_value = new_value + 1024
|
||||
if ( B_output[11] == 1 ) :
|
||||
new_value = new_value + 2048
|
||||
|
||||
|
||||
current = hex( new_value ).replace ( "0x" , "" ).upper()
|
||||
|
||||
except Exception as e:
|
||||
print "Errore in readParallelaFiltrata \n\n"
|
||||
print str(e)
|
||||
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 Exception as e:
|
||||
logPro.error( "NETWORK:Errore http-no com rete-timeout" + url )
|
||||
logPro.error(str(e))
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# 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:
|
||||
if to_retry > 0:
|
||||
to_retry -= 1
|
||||
logPro.info("WAIT active send to complete")
|
||||
else:
|
||||
sending = '0'
|
||||
to_retry = MAXRETRY
|
||||
logPro.info("END WAIT, reset to_retry var")
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
if onLine == '1':
|
||||
logPro.error("Server Non raggiungibile")
|
||||
logPro.error(str(e))
|
||||
#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 Exception as e:
|
||||
print("errore incremento contatore \n\n")
|
||||
print(str(e))
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# 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 in_8
|
||||
global in_9
|
||||
global in_10
|
||||
global in_11
|
||||
|
||||
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
|
||||
GPIO.setup(in_8, GPIO.IN) # input 8
|
||||
GPIO.setup(in_9, GPIO.IN) # input 9
|
||||
GPIO.setup(in_10, GPIO.IN) # input 10
|
||||
GPIO.setup(in_11, GPIO.IN) # input 11
|
||||
|
||||
except Exception as e:
|
||||
print( "\n\n" + PROGRAM_NAME + " - Error 3 on RPi.GPIO ! \n\n")
|
||||
print str(e)
|
||||
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' )
|
||||
B_blinking[8] = config.getint ( 'blink' , 'bit8' )
|
||||
B_blinking[9] = config.getint ( 'blink' , 'bit9' )
|
||||
B_blinking[10] = config.getint ( 'blink' , 'bit10' )
|
||||
B_blinking[11] = config.getint ( 'blink' , 'bit11' )
|
||||
|
||||
MAX_COUNTER_BLINK = config.getint ( 'blink' , 'MAX_COUNTER_BLINK' )
|
||||
|
||||
# cv 2.1 se bit = 1 allora inverto segnale in ingresso...
|
||||
|
||||
B_inverting[0] = config.getint ( 'invert' , 'bit0' )
|
||||
B_inverting[1] = config.getint ( 'invert' , 'bit1' )
|
||||
B_inverting[2] = config.getint ( 'invert' , 'bit2' )
|
||||
B_inverting[3] = config.getint ( 'invert' , 'bit3' )
|
||||
B_inverting[4] = config.getint ( 'invert' , 'bit4' )
|
||||
B_inverting[5] = config.getint ( 'invert' , 'bit5' )
|
||||
B_inverting[6] = config.getint ( 'invert' , 'bit6' )
|
||||
B_inverting[7] = config.getint ( 'invert' , 'bit7' )
|
||||
B_inverting[8] = config.getint ( 'invert' , 'bit8' )
|
||||
B_inverting[9] = config.getint ( 'invert' , 'bit9' )
|
||||
B_inverting[10] = config.getint ( 'invert' , 'bit10' )
|
||||
B_inverting[11] = config.getint ( 'invert' , 'bit11' )
|
||||
|
||||
# cv 2.2 se bit = 1 allora filtro segnali brevi ...
|
||||
|
||||
B_filter[0] = config.getint ( 'filter' , 'bit0' )
|
||||
B_filter[1] = config.getint ( 'filter' , 'bit1' )
|
||||
B_filter[2] = config.getint ( 'filter' , 'bit2' )
|
||||
B_filter[3] = config.getint ( 'filter' , 'bit3' )
|
||||
B_filter[4] = config.getint ( 'filter' , 'bit4' )
|
||||
B_filter[5] = config.getint ( 'filter' , 'bit5' )
|
||||
B_filter[6] = config.getint ( 'filter' , 'bit6' )
|
||||
B_filter[7] = config.getint ( 'filter' , 'bit7' )
|
||||
B_filter[8] = config.getint ( 'filter' , 'bit8' )
|
||||
B_filter[9] = config.getint ( 'filter' , 'bit9' )
|
||||
B_filter[10] = config.getint ( 'filter' , 'bit10' )
|
||||
B_filter[11] = config.getint ( 'filter' , 'bit11' )
|
||||
|
||||
MAX_COUNTER_FILTER = config.getint ( 'filter' , 'MAX_COUNTER_FILTER' )
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg'
|
||||
print str(e)
|
||||
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 Exception as e:
|
||||
# manda mail o simili - FARE!!!
|
||||
print "LOG: Impossibile creare file log con nome"
|
||||
print (LOGFILE)
|
||||
print "\n\n"
|
||||
print str(e)
|
||||
#--------------------------------------------
|
||||
|
||||
|
||||
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 Exception as e:
|
||||
print( "\n\n" + PROGRAM_NAME + " - Error 2 - you need superuser privileges. USE 'sudo' to run your script\n\n")
|
||||
print str(e)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
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 Exception as e:
|
||||
logPro.info("First_SLEEP: errore attesa sampletime")
|
||||
logPro.error(str(e))
|
||||
|
||||
# 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 Exception as e:
|
||||
logPro.error("URLBROWSER: errore registrazione valore e accoda")
|
||||
logPro.error(str(e))
|
||||
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 Exception as e:
|
||||
logPro.error("URLBROWSER: errore registrazione valore e accoda TO_short")
|
||||
logPro.error(str(e))
|
||||
pass
|
||||
to_short = TIMEOUTSHORT
|
||||
to_enable = False # dopo un colpo il timer breve viene disabilitato
|
||||
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 Exception as e:
|
||||
logPro.error("URLBROWSER: errore registrazione valore e accoda TO_long")
|
||||
logPro.error(str(e))
|
||||
pass
|
||||
to_long = TIMEOUTLONG
|
||||
@@ -0,0 +1,733 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# readParallela v. 2.5.2 8 Ingressi
|
||||
# - single instance timer
|
||||
# - invio multiplo x send eventi accodati
|
||||
# - gestione segnali BLINKING
|
||||
# - gestione INVERSIONE segnali cv 10-VII-2018
|
||||
# - gestione FILTRAGGIO segnali brevi cv 23-VII-2018
|
||||
# - (2.3) gestione 12 bit cv 14-I-2020
|
||||
# - (2.4) fix ingressi e conf apertura parallela + gestione vari bit filtraggio x nuovi ingressi + update conf con 12 parametri bit SEL 15-I-2020
|
||||
# - (2.4.8) versione adatta a raspberry PI vecchia generazione (GPIO corto, 8bit)
|
||||
# - (2.5) Fix (hope) ciclo "wait send to complete", gestione timeout (rety infinito se IO riparte in modo anomalo)
|
||||
# - (2.5.1) Fix numero versione 18.05.2023
|
||||
# - (2.5.2) Fix gestione eccezioni con report dettagliato
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# levare locking
|
||||
# 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 = 10
|
||||
|
||||
# numero campioni filtraggio segnale ballerino
|
||||
MAX_COUNTER_BLINK = 10
|
||||
|
||||
PROGRAM_NAME ="ReadPar IOB-pi v.2.5.2"
|
||||
|
||||
# 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])
|
||||
|
||||
B_inverting = array ( 'B',[0,0,0,0,0,0,0,0])
|
||||
|
||||
B_filter = array ( 'B',[0,0,0,0,0,0,0,0])
|
||||
B_filter_prev = array ( 'B',[0,0,0,0,0,0,0,0])
|
||||
B_temp = array ( 'B',[0,0,0,0,0,0,0,0])
|
||||
i_filter_counters = array ( 'i',[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)
|
||||
|
||||
# v2.1 gestione inversione bit ingresso
|
||||
|
||||
if ( B_inverting[i] == 1 ) :
|
||||
if ( B_input[i] == 0 ) :
|
||||
B_input[i] = 1
|
||||
else :
|
||||
B_input[i] = 0
|
||||
|
||||
# v2.2 gestione filtro segnali brevi
|
||||
|
||||
if ( B_filter[i] == 1 ) :
|
||||
|
||||
# fronte 0 -> 1
|
||||
if ( B_input[i] == 1 ) and ( B_filter_prev [i] == 0 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# vero fronte 0 -> 1
|
||||
i_filter_counters[i] = MAX_COUNTER_FILTER
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
#logPro.info("START spike 0->1 on bit " + `i` )
|
||||
else :
|
||||
# fine disturbo breve di uno stato 1
|
||||
i_filter_counters[i] = 0
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
logPro.info("END spike 0->1 on bit " + `i` )
|
||||
|
||||
# stabile 1 -> 1
|
||||
if ( B_input[i] == 1 ) and ( B_filter_prev [i] == 1 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# segnale stabile a 1
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
else :
|
||||
# poco dopo il fronte
|
||||
i_filter_counters[i] = i_filter_counters[i] - 1
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
|
||||
# fronte 1 -> 0
|
||||
if ( B_input[i] == 0 ) and ( B_filter_prev [i] == 1 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# vero fronte 1 -> 0
|
||||
i_filter_counters[i] = MAX_COUNTER_FILTER
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
#logPro.info("START spike 1->0 on bit " + `i` )
|
||||
else :
|
||||
# fine disturbo breve di uno stato 0
|
||||
i_filter_counters[i] = 0
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
logPro.info("END spike 1->0 on bit " + `i` )
|
||||
|
||||
# stabile 0 -> 0
|
||||
if ( B_input[i] == 0 ) and ( B_filter_prev [i] == 0 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# segnale stabile a 0
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
else :
|
||||
# poco dopo il fronte
|
||||
i_filter_counters[i] = i_filter_counters[i] - 1
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
|
||||
B_filter_prev [i] = B_input[i]
|
||||
B_input[i] = B_temp[i]
|
||||
|
||||
# fine gestione filtro segnali brevi
|
||||
|
||||
|
||||
# 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 Exception as e:
|
||||
print "Errore in readParallelaFiltrata \n\n"
|
||||
print str(e)
|
||||
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 Exception as e:
|
||||
logPro.error( "NETWORK:Errore http-no com rete-timeout" + url )
|
||||
logPro.error(str(e))
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# 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:
|
||||
if to_retry > 0:
|
||||
to_retry -= 1
|
||||
logPro.info("WAIT active send to complete")
|
||||
else:
|
||||
sending = '0'
|
||||
to_retry = MAXRETRY
|
||||
logPro.info("END WAIT, reset to_retry var")
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
if onLine == '1':
|
||||
logPro.error("Server Non raggiungibile")
|
||||
logPro.error(str(e))
|
||||
#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 Exception as e:
|
||||
print("errore incremento contatore \n\n")
|
||||
print(str(e))
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# 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 Exception as e:
|
||||
print( "\n\n" + PROGRAM_NAME + " - Error 3 on RPi.GPIO ! \n\n")
|
||||
print str(e)
|
||||
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' )
|
||||
|
||||
# cv 2.1 se bit = 1 allora inverto segnale in ingresso...
|
||||
|
||||
B_inverting[0] = config.getint ( 'invert' , 'bit0' )
|
||||
B_inverting[1] = config.getint ( 'invert' , 'bit1' )
|
||||
B_inverting[2] = config.getint ( 'invert' , 'bit2' )
|
||||
B_inverting[3] = config.getint ( 'invert' , 'bit3' )
|
||||
B_inverting[4] = config.getint ( 'invert' , 'bit4' )
|
||||
B_inverting[5] = config.getint ( 'invert' , 'bit5' )
|
||||
B_inverting[6] = config.getint ( 'invert' , 'bit6' )
|
||||
B_inverting[7] = config.getint ( 'invert' , 'bit7' )
|
||||
|
||||
# cv 2.2 se bit = 1 allora filtro segnali brevi ...
|
||||
|
||||
B_filter[0] = config.getint ( 'filter' , 'bit0' )
|
||||
B_filter[1] = config.getint ( 'filter' , 'bit1' )
|
||||
B_filter[2] = config.getint ( 'filter' , 'bit2' )
|
||||
B_filter[3] = config.getint ( 'filter' , 'bit3' )
|
||||
B_filter[4] = config.getint ( 'filter' , 'bit4' )
|
||||
B_filter[5] = config.getint ( 'filter' , 'bit5' )
|
||||
B_filter[6] = config.getint ( 'filter' , 'bit6' )
|
||||
B_filter[7] = config.getint ( 'filter' , 'bit7' )
|
||||
|
||||
MAX_COUNTER_FILTER = config.getint ( 'filter' , 'MAX_COUNTER_FILTER' )
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print "\n\n" + PROGRAM_NAME + ' - Error 4 - in config file ' 'IOB.cfg'
|
||||
print str(e)
|
||||
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 Exception as e:
|
||||
# manda mail o simili - FARE!!!
|
||||
print "LOG: Impossibile creare file log con nome"
|
||||
print (LOGFILE)
|
||||
print "\n\n"
|
||||
print str(e)
|
||||
#--------------------------------------------
|
||||
|
||||
|
||||
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 Exception as e:
|
||||
print( "\n\n" + PROGRAM_NAME + " - Error 2 - you need superuser privileges. USE 'sudo' to run your script\n\n")
|
||||
print str(e)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
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 Exception as e:
|
||||
logPro.info("First_SLEEP: errore attesa sampletime")
|
||||
logPro.error(str(e))
|
||||
|
||||
# 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 Exception as e:
|
||||
logPro.error("URLBROWSER: errore registrazione valore e accoda")
|
||||
logPro.error(str(e))
|
||||
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 Exception as e:
|
||||
logPro.error("URLBROWSER: errore registrazione valore e accoda TO_short")
|
||||
logPro.error(str(e))
|
||||
pass
|
||||
to_short = TIMEOUTSHORT
|
||||
to_enable = False # dopo un colpo il timer breve viene disabilitato
|
||||
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 Exception as e:
|
||||
logPro.error("URLBROWSER: errore registrazione valore e accoda TO_long")
|
||||
logPro.error(str(e))
|
||||
pass
|
||||
to_long = TIMEOUTLONG
|
||||
@@ -0,0 +1,135 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# sendReboot v. 1.8
|
||||
# - (2.5.2) Fix gestione eccezioni con report dettagliato
|
||||
#---------------------------------------------------------------
|
||||
|
||||
|
||||
import time
|
||||
import sys
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import urllib
|
||||
import ConfigParser
|
||||
import os, sys
|
||||
|
||||
import logging
|
||||
|
||||
import time
|
||||
|
||||
#---------------------------------------------------------------
|
||||
|
||||
# COSTANTI
|
||||
SR_PROG_NAME = "SendReboot IOB-pi v.2.5.2"
|
||||
|
||||
# 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 as e:
|
||||
print("Errore in chiamaUrl")
|
||||
print(str(e))
|
||||
logging.info ( str(e) )
|
||||
|
||||
print("Url chiamato: " , url)
|
||||
return numTry
|
||||
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# Funzione di recupero mac address per poterlo inviare a MPIO
|
||||
#---------------------------------------------------------------
|
||||
def getMAC(interface):
|
||||
# Return the MAC address of interface
|
||||
try:
|
||||
str = open('/sys/class/net/' + interface + '/address').read()
|
||||
except:
|
||||
str = "00:00:00:00:00:00"
|
||||
return str[0:17]
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# 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 Exception as e:
|
||||
print("\n\n" + SR_PROG_NAME + ' - Error 4 - in config file ' 'IOB.cfg')
|
||||
print(str(e))
|
||||
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 Exception as e:
|
||||
# manda mail o simili - FARE!!!
|
||||
print("LOG: Impossibile creare file log con nome ")
|
||||
print(LOGFILE)
|
||||
print(str(e))
|
||||
#--------------------------------------------
|
||||
|
||||
|
||||
print("\n\n" + SR_PROG_NAME + "\n\n")
|
||||
|
||||
global startstatus
|
||||
startstatus = 1
|
||||
|
||||
if startstatus == 1:
|
||||
logging.info("Avvio Programma " + SR_PROG_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 )
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MP/IO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
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/
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.219/MPIO/sendReboot.aspx?idxMacchina=
|
||||
URLREBO = http://10.74.82.218/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.05
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# readParallela v. 2.4
|
||||
# readParallela v. 2.5.1
|
||||
# - single instance timer
|
||||
# - invio multiplo x send eventi accodati
|
||||
# - gestione segnali BLINKING
|
||||
@@ -9,6 +9,9 @@
|
||||
# - gestione FILTRAGGIO segnali brevi cv 23-VII-2018
|
||||
# - (2.3) gestione 12 bit cv 14-I-2020
|
||||
# - (2.4) fix ingressi e conf apertura parallela + gestione vari bit filtraggio x nuovi ingressi + update conf con 12 parametri bit SEL 15-I-2020
|
||||
# - (2.4.8) versione adatta a raspberry PI vecchia generazione (GPIO corto, 8bit)
|
||||
# - (2.5) Fix (hope) ciclo "wait send to complete", gestione timeout (rety infinito se IO riparte in modo anomalo)
|
||||
# - (2.5.1) Fix numero versione 18.05.2023
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# levare locking
|
||||
@@ -38,12 +41,12 @@ from array import *
|
||||
# COSTANTI
|
||||
MSGLEN = 9
|
||||
TIMEOUTSERIALE = 10
|
||||
MAXRETRY = 3
|
||||
MAXRETRY = 10
|
||||
|
||||
# numero campioni filtraggio segnale ballerino
|
||||
MAX_COUNTER_BLINK = 10
|
||||
|
||||
PROGRAM_NAME ="ReadPar IOB-pi v.2.4"
|
||||
PROGRAM_NAME ="ReadPar IOB-pi v.2.5.1"
|
||||
|
||||
# DA FILE CONF
|
||||
idxMacchina = "1001"
|
||||
@@ -304,7 +307,7 @@ def readParallelaFiltrata():
|
||||
B_output[i] = 0
|
||||
logPro.info("END Blink on bit " + `i` )
|
||||
|
||||
#Rimettiamo insieme i bit
|
||||
#Rimettiamo insieme i bit
|
||||
new_value = 0
|
||||
|
||||
if ( B_output[0] == 1 ) :
|
||||
@@ -354,7 +357,7 @@ def accoda():
|
||||
logPro.error( "Queue full" + `dtEve` + '#' + `value` + '#' + `cont` )
|
||||
except:
|
||||
logPro.error( "NETWORK:Errore http-no com rete-timeout" + url )
|
||||
# print "Url aforte" , url
|
||||
#print "Url aforte" , url
|
||||
|
||||
|
||||
#--------------------------------------------------------------
|
||||
@@ -440,7 +443,13 @@ def svuota_coda():
|
||||
# completato invio, riporto sending a zero!
|
||||
sending = '0'
|
||||
else:
|
||||
logPro.info("WAIT active send to complete")
|
||||
if to_retry > 0:
|
||||
to_retry -= 1
|
||||
logPro.info("WAIT active send to complete")
|
||||
else:
|
||||
sending = '0'
|
||||
to_retry = MAXRETRY
|
||||
logPro.info("END WAIT, reset to_retry var")
|
||||
|
||||
else:
|
||||
pass
|
||||
@@ -455,7 +464,7 @@ def svuota_coda():
|
||||
|
||||
onLine = '0'
|
||||
|
||||
# in ogni caso
|
||||
# in ogni caso
|
||||
|
||||
timer_busy = False
|
||||
#print "end timer ok"
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
#!/bin/bash
|
||||
|
||||
# script per update IOB-PI (filre readParallela) secondo la tipologia del raspberry tra 8 e 12 ingressi
|
||||
|
||||
revNum=`awk '/^Revision/ {sub("^1000", "", $3); print $3}' /proc/cpuinfo`
|
||||
anno=2000
|
||||
model='na'
|
||||
ram=0
|
||||
|
||||
# decodifica da questa tabella: https://elinux.org/RPi_HardwareHistory e https://ozzmaker.com/check-raspberry-software-hardware-version-command-line
|
||||
case $revNum in
|
||||
|
||||
0002 | 0003 | 0004 | 0005 | 0006)
|
||||
anno='2012'
|
||||
model='B'
|
||||
ram=256
|
||||
;;
|
||||
|
||||
0007 | 0008 | 0009)
|
||||
anno='2013'
|
||||
model='A'
|
||||
ram=256
|
||||
;;
|
||||
|
||||
000d | 000e | 000f)
|
||||
anno='2012'
|
||||
model='B'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0010)
|
||||
anno='2014'
|
||||
model='B+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0011)
|
||||
anno='2014'
|
||||
model='CM1'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0012)
|
||||
anno='2014'
|
||||
model='A+'
|
||||
ram=256
|
||||
;;
|
||||
|
||||
0013)
|
||||
anno='2015'
|
||||
model='B+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0014)
|
||||
anno='2014'
|
||||
model='CM1'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
0015)
|
||||
anno='2014'
|
||||
model='A+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
a01040 | a01041 | a21042)
|
||||
anno='2015'
|
||||
model='2 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a22042)
|
||||
anno='2016'
|
||||
model='2 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
900021)
|
||||
anno='2016'
|
||||
model='A+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
900032)
|
||||
anno='2016'
|
||||
model='B+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
900092)
|
||||
anno='2015'
|
||||
model='Zero'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
900093 | 920093)
|
||||
anno='2016'
|
||||
model='Zero'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
9000c1)
|
||||
anno='2017'
|
||||
model='Zero W'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
a02082 | a22082 | a22082 | a32082)
|
||||
anno='2016'
|
||||
model='3 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a020a0)
|
||||
anno='2017'
|
||||
model='CM3'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a020d3)
|
||||
anno='2018'
|
||||
model='3 Model B+'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
9020e0)
|
||||
anno='2018'
|
||||
model='3 Model A+'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
a02100)
|
||||
anno='2019'
|
||||
model='CM3'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
a03111)
|
||||
anno='2019'
|
||||
model='4 Model B'
|
||||
ram=1024
|
||||
;;
|
||||
|
||||
b03111 | b03112)
|
||||
anno='2019'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
b03114)
|
||||
anno='2020'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
b03115)
|
||||
anno='2022'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
c03111 | c03112)
|
||||
anno='2019'
|
||||
model='4 Model B'
|
||||
ram=4096
|
||||
;;
|
||||
|
||||
c03114)
|
||||
anno='2020'
|
||||
model='4 Model B'
|
||||
ram=4096
|
||||
;;
|
||||
|
||||
c03115)
|
||||
anno='2022'
|
||||
model='4 Model B'
|
||||
ram=2048
|
||||
;;
|
||||
|
||||
d03114)
|
||||
anno='2020'
|
||||
model='4 Model B'
|
||||
ram=8192
|
||||
;;
|
||||
|
||||
d03115)
|
||||
anno='2022'
|
||||
model='4 Model B'
|
||||
ram=8192
|
||||
;;
|
||||
|
||||
|
||||
902120)
|
||||
anno='2021'
|
||||
model='Zero 2 W'
|
||||
ram=512
|
||||
;;
|
||||
|
||||
*)
|
||||
anno='2000'
|
||||
model='Unknown'
|
||||
ram=128
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "RPI $anno | model $model | RAM $ram"
|
||||
echo "Revisione: $revNum"
|
||||
|
||||
# default a 8 IN...
|
||||
selIn=8
|
||||
# verifico anno/ram, se almeno 2014 e 1gb --> 12 bit...
|
||||
if [ $anno -gt 2015 ] && [ $ram -gt 512 ]; then
|
||||
selIn=12
|
||||
fi
|
||||
|
||||
echo "Scelta versione $selIn ingressi"
|
||||
|
||||
|
||||
# fermo esecuzione...
|
||||
/etc/init.d/MapoIOB stop
|
||||
echo "Arrestato servizio..."
|
||||
|
||||
# mv file readParallela.py corrente...
|
||||
mv readParallela.py readParallela_$(date -d "today" +"%Y%m%d").py
|
||||
|
||||
# secondo tipo copio il file corretto
|
||||
if [ $selIn -eq 8 ]; then
|
||||
cp -f readParallela_8.py readParallela.py
|
||||
else
|
||||
cp -f readParallela_12.py readParallela.py
|
||||
fi
|
||||
|
||||
# fix permessi
|
||||
chown pi: *
|
||||
chmod +x readP*
|
||||
|
||||
# riavvio esecuzione...
|
||||
/etc/init.d/MapoIOB restart
|
||||
echo "Modifiche effettuate..."
|
||||
|
||||
echo "Attenzione: verificare effettiva partenza servizio, per farlo digitare il comando"
|
||||
echo "/etc/init.d/MapoIOB restart"
|
||||
echo "--------------------------------"
|
||||
echo "In particolare il file IOB.cfg deve contenere NMAXSEND = 5 nella sezione [time]"
|
||||
echo "--------------------------------"
|
||||
echo "Inoltre verificare presenza sezioni [blink] [invert] [filter]"
|
||||
echo "--------------------------------"
|
||||
@@ -0,0 +1,23 @@
|
||||
[id]
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.218/MPIO/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
|
||||
@@ -0,0 +1,23 @@
|
||||
[id]
|
||||
idxMacchina = 1002
|
||||
|
||||
[web]
|
||||
URLBASE = http://192.168.51.71/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://192.168.51.71/MPIO/Alive.aspx
|
||||
URLENABLED = http://192.168.51.71/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://192.168.51.71/MPIO/sendReboot.aspx?idxMacchina=
|
||||
|
||||
[time]
|
||||
SAMPLETIME = 0.25
|
||||
TIMEOUTSHORT = 2
|
||||
TIMEOUTLONG = 50
|
||||
SENDURLTIME = 0.2
|
||||
|
||||
[log]
|
||||
LOGLEVEL = 10
|
||||
LOGFILE = logfile.txt
|
||||
LOGREBO = /var/log/logReboot.txt
|
||||
|
||||
[comm]
|
||||
port = /dev/ttyAMA0
|
||||
@@ -0,0 +1,23 @@
|
||||
[id]
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.218/MPIO/inputIOB.aspx?idxMacchina=
|
||||
URLALIVE = http://10.74.82.218/MPIO/Alive.aspx
|
||||
URLENABLED = http://10.74.82.218/MPIO/Enabled.aspx?idxMacchina=
|
||||
URLADV1 = &valore=
|
||||
URLREBO = http://10.74.82.218/MPIO/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
|
||||
@@ -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
|
||||
|
||||
@@ -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 ]
|
||||
then
|
||||
# controllo SE sia stato acceduto da meno di 2 minuti (=alive da log...)
|
||||
trovato=`find . -name 'MapoIOB*' -cmin -1`
|
||||
if [[ $trovato != './MapoIOB' ]]
|
||||
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
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
* * * * * /bin/bash /home/pi/steamware/checkAlive.sh >> /home/pi/stdout 2>> /home/pi/stderr
|
||||
@@ -0,0 +1,47 @@
|
||||
#|/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
|
||||
|
||||
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 /home/pi/steamware/logfile.txt
|
||||
|
||||
chown pi:pi /home/pi -R
|
||||
chmod 666 /var/log/log*.txt
|
||||
chmod 666 /var/log/MapoIOB
|
||||
|
||||
#step 2: copio files in /usr/local/bin
|
||||
cd /home/pi/steamware
|
||||
chmod +x *.sh
|
||||
cp *.sh /usr/local/bin/
|
||||
|
||||
# step 3: 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 "-----------------------------------------------"
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
/usr/bin/python /home/pi/steamware/readParallela.py
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
/usr/bin/python /home/steamware/readSeriale.py
|
||||
@@ -0,0 +1,530 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# readParallela v. 1.8
|
||||
# versione estetica di Carlo + single instance timer
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# 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
|
||||
#--------------------------------------------------------------
|
||||
|
||||
# COSTANTI
|
||||
MSGLEN = 9
|
||||
TIMEOUTSERIALE = 10
|
||||
MAXRETRY = 3
|
||||
|
||||
PROGRAM_NAME ="ReadPar IOB-pi v.1.8"
|
||||
|
||||
# DA FILE CONF
|
||||
idxMacchina = "1001"
|
||||
SAMPLETIME = 0.1
|
||||
TIMEOUTSHORT = (SAMPLETIME*20)
|
||||
TIMEOUTLONG = (SAMPLETIME*600)
|
||||
SENDURLTIME = 0.08
|
||||
|
||||
# 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 999
|
||||
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
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# Gestione coda (condivisa) x registrazione eventi ed invio URL
|
||||
#print "Creazione coda 1000 elementi"
|
||||
|
||||
Coda = Queue.Queue(0)
|
||||
|
||||
#queueLock = threading.Lock()
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# lettura parallela
|
||||
# ritorna il byte letto pulito ( due char hex )
|
||||
|
||||
def readParallela():
|
||||
|
||||
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 = ''
|
||||
|
||||
# print "input : "
|
||||
|
||||
# ritorna '' se non ci sono abbastanza caratteri
|
||||
try:
|
||||
num_value = 255
|
||||
|
||||
# print "num_value : " , num_value , in_0
|
||||
|
||||
if GPIO.input(in_0):
|
||||
num_value = num_value - 1
|
||||
|
||||
if GPIO.input(in_1):
|
||||
num_value = num_value - 2
|
||||
|
||||
if GPIO.input(in_2):
|
||||
num_value = num_value - 4
|
||||
|
||||
if GPIO.input(in_3):
|
||||
num_value = num_value - 8
|
||||
|
||||
if GPIO.input(in_4):
|
||||
num_value = num_value - 16
|
||||
|
||||
if GPIO.input(in_5):
|
||||
num_value = num_value - 32
|
||||
|
||||
if GPIO.input(in_6):
|
||||
num_value = num_value - 64
|
||||
|
||||
if GPIO.input(in_7):
|
||||
num_value = num_value - 128
|
||||
|
||||
current = hex( num_value ).replace ( "0x" , "" ).upper()
|
||||
|
||||
# print "\n\n\n\n\n" , num_value , current
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
return current
|
||||
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# MARCO: cambiare: chiama URL NON deve chiamare url MA METTERE IN CODA (riempiCoda!!!)
|
||||
# la parte URL vera va messa in svuotaCoda, PARAMETRICA
|
||||
|
||||
#---------------------------------------------------------------
|
||||
#Funzione di scrittura su coda con try-except
|
||||
|
||||
def accoda():
|
||||
|
||||
try:
|
||||
# url = URLBASE + idxMacchina + URLADV1 + value
|
||||
# urllib.urlopen ( url )
|
||||
#dtEve = time.strftime("%y%m%d%H%M%S")+"000"
|
||||
dtEve = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3]
|
||||
#logPro.debug( "Nuovo valore inserito in coda: " + dtEve + "#" + value + '#' + cont)
|
||||
#print(dtEve)
|
||||
#queueLock.acquire()
|
||||
Coda.put(dtEve + '#' + value + '#' + cont)
|
||||
#queueLock.release()
|
||||
#print "Nuovo valore inserito in coda: " + dtEve + "#", value
|
||||
|
||||
except Queue.Full:
|
||||
logPro.error( "Quque full" + dtEve + '#' + value + '#' + cont )
|
||||
except:
|
||||
logPro.error( "NETWORK:Errore http-no com rete-timeout" + url )
|
||||
# print "Url aforte" , url
|
||||
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# MARCO: scrivere svuotaCoda come thread etc...
|
||||
def svuota_coda():
|
||||
|
||||
global onLine
|
||||
global sending
|
||||
global timer_busy
|
||||
|
||||
#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'
|
||||
|
||||
# formatto dataOra corrente
|
||||
#dtCurr = time.strftime("%y%m%d%H%M%S")+"000"
|
||||
dtCurr = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3]
|
||||
# prendo 1 valore dalla coda...
|
||||
#queueLock.acquire()
|
||||
resp = Coda.get()
|
||||
# RILASCIO SUBITO la coda x nuovi insert...
|
||||
#queueLock.release()
|
||||
|
||||
|
||||
# recupero valori da 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)
|
||||
#logPro.debug(url)
|
||||
|
||||
|
||||
# log valore inviato!
|
||||
logSnd.info( value + ' ['+ cnt +']' + ' R:' + answ3 )
|
||||
#print "Valore smaltito dalla coda"
|
||||
|
||||
# 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 % 1000 # round robin 1000 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' )
|
||||
|
||||
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' )
|
||||
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 = readParallela()
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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 )
|
||||
@@ -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
|
||||
@@ -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 *
|
||||
@@ -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.')
|
||||
@@ -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.
@@ -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.
@@ -0,0 +1,68 @@
|
||||
[id]
|
||||
idxMacchina = 0001
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.218/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
|
||||
bit8 = 0
|
||||
bit9 = 0
|
||||
bit10 = 0
|
||||
bit11 = 0
|
||||
|
||||
[invert]
|
||||
bit0 = 0
|
||||
bit1 = 0
|
||||
bit2 = 0
|
||||
bit3 = 0
|
||||
bit4 = 0
|
||||
bit5 = 0
|
||||
bit6 = 0
|
||||
bit7 = 0
|
||||
bit8 = 0
|
||||
bit9 = 0
|
||||
bit10 = 0
|
||||
bit11 = 0
|
||||
|
||||
[filter]
|
||||
MAX_COUNTER_FILTER = 8
|
||||
bit0 = 0
|
||||
bit1 = 0
|
||||
bit2 = 0
|
||||
bit3 = 0
|
||||
bit4 = 0
|
||||
bit5 = 0
|
||||
bit6 = 0
|
||||
bit7 = 0
|
||||
bit8 = 0
|
||||
bit9 = 0
|
||||
bit10 = 0
|
||||
bit11 = 0
|
||||
@@ -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
|
||||
@@ -0,0 +1,35 @@
|
||||
[id]
|
||||
idxMacchina = 1005
|
||||
|
||||
[web]
|
||||
URLBASE = http://10.74.82.218/MP/IO/IOB/input/
|
||||
URLALIVE = http://10.74.82.218/MP/IO/IOB
|
||||
URLENABLED = http://10.74.82.218/MP/IO/IOB/enabled/
|
||||
URLADV1 = ?valore=
|
||||
URLREBO = http://10.74.82.218/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
|
||||
@@ -0,0 +1,41 @@
|
||||
#! /bin/bash
|
||||
### BEGIN INIT INFO
|
||||
# Provides: MapoIOB: script Steamware per avvio driver IOB
|
||||
# Required-Start: $remote_fs $syslog ramlog
|
||||
# Required-Stop: $remote_fs $syslog ramlog
|
||||
# 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
|
||||
|
||||
# /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
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
[Unit]
|
||||
SourcePath=/etc/init.d/MapoIOB
|
||||
Description=LSB: Steamware's MapoIOB driver
|
||||
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=1
|
||||
ExecStart=/etc/init.d/MapoIOB start
|
||||
ExecStop=/etc/init.d/MapoIOB stop
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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')
|
||||
@@ -0,0 +1 @@
|
||||
* * * * * /bin/bash /home/pi/steamware/checkAlive.sh >> /home/pi/stdout 2>> /home/pi/stderr
|
||||
@@ -0,0 +1,54 @@
|
||||
#|/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 ""
|
||||
|
||||
# step 5: copio target MapoIOB in avvio...
|
||||
cp -f MapoIOB /etc/init.d/MapoIOB
|
||||
cp -f MapoIOB.service /etc/systemd/system/MapoIOB.service
|
||||
|
||||
|
||||
#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 "-----------------------------------------------"
|
||||
@@ -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
|
||||
@@ -0,0 +1,719 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# readParallela v. 2.4.8
|
||||
# - single instance timer
|
||||
# - invio multiplo x send eventi accodati
|
||||
# - gestione segnali BLINKING
|
||||
# - gestione INVERSIONE segnali cv 10-VII-2018
|
||||
# - gestione FILTRAGGIO segnali brevi cv 23-VII-2018
|
||||
# - (2.3) gestione 12 bit cv 14-I-2020
|
||||
# - (2.4) fix ingressi e conf apertura parallela + gestione vari bit filtraggio x nuovi ingressi + update conf con 12 parametri bit SEL 15-I-2020
|
||||
# - (2.4.8) versione adatta a raspberry PI vecchia generazione (GPIO corto, 8bit)
|
||||
# - (2.5) Fix (hope) ciclo "wait send to complete", gestione timeout (rety infinito se IO riparte in modo anomalo)
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# 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 = 10
|
||||
|
||||
# numero campioni filtraggio segnale ballerino
|
||||
MAX_COUNTER_BLINK = 10
|
||||
|
||||
PROGRAM_NAME ="ReadPar IOB-pi v.2.5.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])
|
||||
|
||||
B_inverting = array ( 'B',[0,0,0,0,0,0,0,0])
|
||||
|
||||
B_filter = array ( 'B',[0,0,0,0,0,0,0,0])
|
||||
B_filter_prev = array ( 'B',[0,0,0,0,0,0,0,0])
|
||||
B_temp = array ( 'B',[0,0,0,0,0,0,0,0])
|
||||
i_filter_counters = array ( 'i',[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)
|
||||
|
||||
# v2.1 gestione inversione bit ingresso
|
||||
|
||||
if ( B_inverting[i] == 1 ) :
|
||||
if ( B_input[i] == 0 ) :
|
||||
B_input[i] = 1
|
||||
else :
|
||||
B_input[i] = 0
|
||||
|
||||
# v2.2 gestione filtro segnali brevi
|
||||
|
||||
if ( B_filter[i] == 1 ) :
|
||||
|
||||
# fronte 0 -> 1
|
||||
if ( B_input[i] == 1 ) and ( B_filter_prev [i] == 0 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# vero fronte 0 -> 1
|
||||
i_filter_counters[i] = MAX_COUNTER_FILTER
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
#logPro.info("START spike 0->1 on bit " + `i` )
|
||||
else :
|
||||
# fine disturbo breve di uno stato 1
|
||||
i_filter_counters[i] = 0
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
logPro.info("END spike 0->1 on bit " + `i` )
|
||||
|
||||
# stabile 1 -> 1
|
||||
if ( B_input[i] == 1 ) and ( B_filter_prev [i] == 1 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# segnale stabile a 1
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
else :
|
||||
# poco dopo il fronte
|
||||
i_filter_counters[i] = i_filter_counters[i] - 1
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
|
||||
# fronte 1 -> 0
|
||||
if ( B_input[i] == 0 ) and ( B_filter_prev [i] == 1 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# vero fronte 1 -> 0
|
||||
i_filter_counters[i] = MAX_COUNTER_FILTER
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
#logPro.info("START spike 1->0 on bit " + `i` )
|
||||
else :
|
||||
# fine disturbo breve di uno stato 0
|
||||
i_filter_counters[i] = 0
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
logPro.info("END spike 1->0 on bit " + `i` )
|
||||
|
||||
# stabile 0 -> 0
|
||||
if ( B_input[i] == 0 ) and ( B_filter_prev [i] == 0 ) :
|
||||
if ( i_filter_counters[i] == 0 ) :
|
||||
# segnale stabile a 0
|
||||
B_temp[i] = 0 # tengo l' ingresso a 0
|
||||
else :
|
||||
# poco dopo il fronte
|
||||
i_filter_counters[i] = i_filter_counters[i] - 1
|
||||
B_temp[i] = 1 # tengo l' ingresso a 1
|
||||
|
||||
B_filter_prev [i] = B_input[i]
|
||||
B_input[i] = B_temp[i]
|
||||
|
||||
# fine gestione filtro segnali brevi
|
||||
|
||||
|
||||
# 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:
|
||||
if to_retry > 0:
|
||||
to_retry -= 1
|
||||
logPro.info("WAIT active send to complete")
|
||||
else:
|
||||
sending = '0'
|
||||
to_retry = MAXRETRY
|
||||
logPro.info("END WAIT, reset to_retry var")
|
||||
|
||||
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' )
|
||||
|
||||
# cv 2.1 se bit = 1 allora inverto segnale in ingresso...
|
||||
|
||||
B_inverting[0] = config.getint ( 'invert' , 'bit0' )
|
||||
B_inverting[1] = config.getint ( 'invert' , 'bit1' )
|
||||
B_inverting[2] = config.getint ( 'invert' , 'bit2' )
|
||||
B_inverting[3] = config.getint ( 'invert' , 'bit3' )
|
||||
B_inverting[4] = config.getint ( 'invert' , 'bit4' )
|
||||
B_inverting[5] = config.getint ( 'invert' , 'bit5' )
|
||||
B_inverting[6] = config.getint ( 'invert' , 'bit6' )
|
||||
B_inverting[7] = config.getint ( 'invert' , 'bit7' )
|
||||
|
||||
# cv 2.2 se bit = 1 allora filtro segnali brevi ...
|
||||
|
||||
B_filter[0] = config.getint ( 'filter' , 'bit0' )
|
||||
B_filter[1] = config.getint ( 'filter' , 'bit1' )
|
||||
B_filter[2] = config.getint ( 'filter' , 'bit2' )
|
||||
B_filter[3] = config.getint ( 'filter' , 'bit3' )
|
||||
B_filter[4] = config.getint ( 'filter' , 'bit4' )
|
||||
B_filter[5] = config.getint ( 'filter' , 'bit5' )
|
||||
B_filter[6] = config.getint ( 'filter' , 'bit6' )
|
||||
B_filter[7] = config.getint ( 'filter' , 'bit7' )
|
||||
|
||||
MAX_COUNTER_FILTER = config.getint ( 'filter' , 'MAX_COUNTER_FILTER' )
|
||||
|
||||
|
||||
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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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 )
|
||||
@@ -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
|
||||
@@ -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 *
|
||||
@@ -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.
@@ -0,0 +1,54 @@
|
||||
#|/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 ""
|
||||
|
||||
# step 5: copio target MapoIOB in avvio...
|
||||
cp -f MapoIOB /etc/init.d/MapoIOB
|
||||
cp -f MapoIOB.service /etc/systemd/system/MapoIOB.service
|
||||
|
||||
|
||||
#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 "-----------------------------------------------"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user