Aggiunta IOB-PI base + conf macchine DONATI

This commit is contained in:
Samuele E. Locatelli
2017-10-19 10:28:33 +02:00
parent a5ba863213
commit 212d2a0467
579 changed files with 2414353 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
[id]
idxMacchina = 1005
[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.20
TIMEOUTSHORT = 0.30
TIMEOUTLONG = 50
SENDURLTIME = 0.50
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
LOGREBO = logReboot.txt
[comm]
port = /dev/ttyAMA0
+41
View File
@@ -0,0 +1,41 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start: $remote_fs $syslog ramlog
# Required-Stop: $remote_fs $syslog ramlog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Steamware's MapoIOB driver
# Description: Steamware's MapoIOB driver, versione lettura porta parallela
### END INIT INFO
#! /bin/sh
# /etc/init.d/MapoIOB
export HOME
case "$1" in
start)
echo "Starting readParallela"
cd /home/pi/steamware
/usr/bin/python ./readParallela.py 2>&1 &
;;
stop)
echo "Stopping readParallela"
RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'`
kill -9 $RS_PID
cd /home/pi/steamware
rm .lockfile
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
killall python
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
Binary file not shown.
+40
View File
@@ -0,0 +1,40 @@
### 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
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
+40
View File
@@ -0,0 +1,40 @@
### 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 readSeriale"
cd /home/pi/steamware
/usr/bin/python ./readSeriale.py 2>&1 &
;;
stop)
echo "Stopping readSeriale"
RS_PID=`ps auxwww | grep readSeriale.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
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia!
DATE=`date +%Y-%m-%d`
cd /var/log
if [ -f MapoIOB ]
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
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
DATE=`date +%Y-%m-%d_%T`
# log inizio pulizia
echo $DATE " - INIZIO pulizia processi python" >> clean.log
# effettua pulizia processi: killa tutti i processi python
killall python
# avvia MapoIob
/etc/init.d/MapoIOB start
# log fatto!
DATE=`date +%Y-%m-%d_%T`
echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log
+179
View File
@@ -0,0 +1,179 @@
2015-03-13 06:26:02 program INFO Avvio ProgrammaReadPar IOB-pi v.1.7
2015-03-13 06:26:02 program INFO Start ReadPar IOB-pi v.1.7
2015-03-13 06:26:02 program INFO Avvio loop principale
2015-03-13 06:26:02 queue INFO 21 [0]
2015-03-13 06:26:02 queue INFO >21 [1]
2015-03-13 06:26:03 sendUrl INFO 21 [0] R:OK
2015-03-13 06:26:03 sendUrl INFO 21 [1] R:OK
2015-03-13 06:26:52 queue INFO >>21 [2]
2015-03-13 06:26:52 sendUrl INFO 21 [2] R:OK
2015-03-13 06:27:42 queue INFO >>21 [3]
2015-03-13 06:27:43 sendUrl INFO 21 [3] R:OK
2015-03-13 06:28:33 queue INFO >>21 [4]
2015-03-13 06:28:33 sendUrl INFO 21 [4] R:OK
2015-03-13 06:29:23 queue INFO >>21 [5]
2015-03-13 06:29:23 sendUrl INFO 21 [5] R:OK
2015-03-13 06:30:13 queue INFO >>21 [6]
2015-03-13 06:30:13 sendUrl INFO 21 [6] R:OK
2015-03-13 06:31:03 queue INFO >>21 [7]
2015-03-13 06:31:04 sendUrl INFO 21 [7] R:OK
2015-03-13 06:31:53 queue INFO >>21 [8]
2015-03-13 06:31:53 sendUrl INFO 21 [8] R:OK
2015-03-13 06:32:43 queue INFO >>21 [9]
2015-03-13 06:32:44 sendUrl INFO 21 [9] R:OK
2015-03-13 06:33:33 queue INFO >>21 [10]
2015-03-13 06:33:34 sendUrl INFO 21 [10] R:OK
2015-03-13 06:34:24 queue INFO >>21 [11]
2015-03-13 06:34:24 sendUrl INFO 21 [11] R:OK
2015-03-13 06:35:14 queue INFO >>21 [12]
2015-03-13 06:35:14 sendUrl INFO 21 [12] R:OK
2015-03-13 06:36:04 queue INFO >>21 [13]
2015-03-13 06:36:04 sendUrl INFO 21 [13] R:OK
2015-03-13 06:36:54 queue INFO >>21 [14]
2015-03-13 06:36:54 sendUrl INFO 21 [14] R:OK
2015-03-13 06:37:44 queue INFO >>21 [15]
2015-03-13 06:37:45 sendUrl INFO 21 [15] R:OK
2015-03-13 06:38:34 queue INFO >>21 [16]
2015-03-13 06:38:35 sendUrl INFO 21 [16] R:OK
2015-03-13 06:39:25 queue INFO >>21 [17]
2015-03-13 06:39:25 sendUrl INFO 21 [17] R:OK
2015-03-13 06:40:15 queue INFO >>21 [18]
2015-03-13 06:40:15 sendUrl INFO 21 [18] R:OK
2015-03-13 06:41:05 queue INFO >>21 [19]
2015-03-13 06:41:05 sendUrl INFO 21 [19] R:OK
2015-03-13 06:41:55 queue INFO >>21 [20]
2015-03-13 06:41:55 sendUrl INFO 21 [20] R:OK
2015-03-13 06:42:45 queue INFO >>21 [21]
2015-03-13 06:42:45 sendUrl INFO 21 [21] R:OK
2015-03-13 06:43:35 queue INFO >>21 [22]
2015-03-13 06:43:35 sendUrl INFO 21 [22] R:OK
2015-03-13 06:44:25 queue INFO >>21 [23]
2015-03-13 06:44:26 sendUrl INFO 21 [23] R:OK
2015-03-13 06:45:15 queue INFO >>21 [24]
2015-03-13 06:45:16 sendUrl INFO 21 [24] R:OK
2015-03-13 06:46:06 queue INFO >>21 [25]
2015-03-13 06:46:06 sendUrl INFO 21 [25] R:OK
2015-03-13 06:46:56 queue INFO >>21 [26]
2015-03-13 06:46:56 sendUrl INFO 21 [26] R:OK
2015-03-13 06:47:46 queue INFO >>21 [27]
2015-03-13 06:47:46 sendUrl INFO 21 [27] R:OK
2015-03-13 06:48:36 queue INFO >>21 [28]
2015-03-13 06:48:36 sendUrl INFO 21 [28] R:OK
2015-03-13 06:49:26 queue INFO >>21 [29]
2015-03-13 06:49:26 sendUrl INFO 21 [29] R:OK
2015-03-13 06:50:16 queue INFO >>21 [30]
2015-03-13 06:50:17 sendUrl INFO 21 [30] R:OK
2015-03-13 06:51:06 queue INFO >>21 [31]
2015-03-13 06:51:07 sendUrl INFO 21 [31] R:OK
2015-03-13 06:51:56 queue INFO >>21 [32]
2015-03-13 06:51:57 sendUrl INFO 21 [32] R:OK
2015-03-13 06:52:47 queue INFO >>21 [33]
2015-03-13 06:52:47 sendUrl INFO 21 [33] R:OK
2015-03-13 06:53:37 queue INFO >>21 [34]
2015-03-13 06:53:37 sendUrl INFO 21 [34] R:OK
2015-03-13 06:54:27 queue INFO >>21 [35]
2015-03-13 06:54:27 sendUrl INFO 21 [35] R:OK
2015-03-13 06:55:17 queue INFO >>21 [36]
2015-03-13 06:55:17 sendUrl INFO 21 [36] R:OK
2015-03-13 06:56:07 queue INFO >>21 [37]
2015-03-13 06:56:08 sendUrl INFO 21 [37] R:OK
2015-03-13 06:56:57 queue INFO >>21 [38]
2015-03-13 06:56:58 sendUrl INFO 21 [38] R:OK
2015-03-13 06:57:47 queue INFO >>21 [39]
2015-03-13 06:57:48 sendUrl INFO 21 [39] R:OK
2015-03-13 06:58:38 queue INFO >>21 [40]
2015-03-13 06:58:38 sendUrl INFO 21 [40] R:OK
2015-03-13 06:59:28 queue INFO >>21 [41]
2015-03-13 06:59:28 sendUrl INFO 21 [41] R:OK
2015-03-13 07:00:18 queue INFO >>21 [42]
2015-03-13 07:00:18 sendUrl INFO 21 [42] R:OK
2015-03-13 07:01:08 queue INFO >>21 [43]
2015-03-13 07:01:09 sendUrl INFO 21 [43] R:OK
2015-03-13 07:01:58 queue INFO >>21 [44]
2015-03-13 07:01:58 sendUrl INFO 21 [44] R:OK
2015-03-13 07:02:48 queue INFO >>21 [45]
2015-03-13 07:02:49 sendUrl INFO 21 [45] R:OK
2015-03-13 07:03:39 queue INFO >>21 [46]
2015-03-13 07:03:39 sendUrl INFO 21 [46] R:OK
2015-03-13 07:04:29 queue INFO >>21 [47]
2015-03-13 07:04:29 sendUrl INFO 21 [47] R:OK
2015-03-13 07:05:19 queue INFO >>21 [48]
2015-03-13 07:05:19 sendUrl INFO 21 [48] R:OK
2015-03-13 07:06:09 queue INFO >>21 [49]
2015-03-13 07:06:10 sendUrl INFO 21 [49] R:OK
2015-03-13 07:06:59 queue INFO >>21 [50]
2015-03-13 07:06:59 sendUrl INFO 21 [50] R:OK
2015-03-13 07:07:49 queue INFO >>21 [51]
2015-03-13 07:07:50 sendUrl INFO 21 [51] R:OK
2015-03-13 07:08:39 queue INFO >>21 [52]
2015-03-13 07:08:40 sendUrl INFO 21 [52] R:OK
2015-03-13 07:09:30 queue INFO >>21 [53]
2015-03-13 07:09:30 sendUrl INFO 21 [53] R:OK
2015-03-13 07:10:20 queue INFO >>21 [54]
2015-03-13 07:10:20 sendUrl INFO 21 [54] R:OK
2015-03-13 07:11:10 queue INFO >>21 [55]
2015-03-13 07:11:10 sendUrl INFO 21 [55] R:OK
2015-03-13 07:12:00 queue INFO >>21 [56]
2015-03-13 07:12:00 sendUrl INFO 21 [56] R:OK
2015-03-13 07:12:50 queue INFO >>21 [57]
2015-03-13 07:12:50 sendUrl INFO 21 [57] R:OK
2015-03-13 07:13:40 queue INFO >>21 [58]
2015-03-13 07:13:41 sendUrl INFO 21 [58] R:OK
2015-03-13 07:14:30 queue INFO >>21 [59]
2015-03-13 07:14:31 sendUrl INFO 21 [59] R:OK
2015-03-13 07:15:20 queue INFO >>21 [60]
2015-03-13 07:15:21 sendUrl INFO 21 [60] R:OK
2015-03-13 07:16:11 queue INFO >>21 [61]
2015-03-13 07:16:11 sendUrl INFO 21 [61] R:OK
2015-03-13 07:17:01 queue INFO >>21 [62]
2015-03-13 07:17:01 sendUrl INFO 21 [62] R:OK
2015-03-13 07:17:51 queue INFO >>21 [63]
2015-03-13 07:17:51 sendUrl INFO 21 [63] R:OK
2015-03-13 07:18:41 queue INFO >>21 [64]
2015-03-13 07:18:41 sendUrl INFO 21 [64] R:OK
2015-03-13 07:19:31 queue INFO >>21 [65]
2015-03-13 07:19:31 sendUrl INFO 21 [65] R:OK
2015-03-13 07:20:21 queue INFO >>21 [66]
2015-03-13 07:20:22 sendUrl INFO 21 [66] R:OK
2015-03-13 07:21:11 queue INFO >>21 [67]
2015-03-13 07:21:12 sendUrl INFO 21 [67] R:OK
2015-03-13 07:22:02 queue INFO >>21 [68]
2015-03-13 07:22:02 sendUrl INFO 21 [68] R:OK
2015-03-13 07:22:52 queue INFO >>21 [69]
2015-03-13 07:22:52 sendUrl INFO 21 [69] R:OK
2015-03-13 07:23:42 queue INFO >>21 [70]
2015-03-13 07:23:42 sendUrl INFO 21 [70] R:OK
2015-03-13 07:24:32 queue INFO >>21 [71]
2015-03-13 07:24:32 sendUrl INFO 21 [71] R:OK
2015-03-13 07:25:22 queue INFO >>21 [72]
2015-03-13 07:25:23 sendUrl INFO 21 [72] R:OK
2015-03-13 07:26:12 queue INFO >>21 [73]
2015-03-13 07:26:12 sendUrl INFO 21 [73] R:OK
2015-03-13 07:27:02 queue INFO >>21 [74]
2015-03-13 07:27:03 sendUrl INFO 21 [74] R:OK
2015-03-13 07:27:53 queue INFO >>21 [75]
2015-03-13 07:27:53 sendUrl INFO 21 [75] R:OK
2015-03-13 07:28:43 queue INFO >>21 [76]
2015-03-13 07:28:43 sendUrl INFO 21 [76] R:OK
2015-03-13 07:29:33 queue INFO >>21 [77]
2015-03-13 07:29:33 sendUrl INFO 21 [77] R:OK
2015-03-13 07:30:23 queue INFO >>21 [78]
2015-03-13 07:30:23 sendUrl INFO 21 [78] R:OK
2015-03-13 07:31:13 queue INFO >>21 [79]
2015-03-13 07:31:13 sendUrl INFO 21 [79] R:OK
2015-03-13 07:32:03 queue INFO >>21 [80]
2015-03-13 07:32:04 sendUrl INFO 21 [80] R:OK
2015-03-13 07:32:54 queue INFO >>21 [81]
2015-03-13 07:32:54 sendUrl INFO 21 [81] R:OK
2015-03-13 07:33:44 queue INFO >>21 [82]
2015-03-13 07:33:44 sendUrl INFO 21 [82] R:OK
2015-03-13 07:34:34 queue INFO >>21 [83]
2015-03-13 07:34:34 sendUrl INFO 21 [83] R:OK
2015-03-13 07:35:24 queue INFO >>21 [84]
2015-03-13 07:35:24 sendUrl INFO 21 [84] R:OK
2015-03-13 07:36:14 queue INFO >>21 [85]
2015-03-13 07:36:14 sendUrl INFO 21 [85] R:OK
2015-03-13 07:37:04 queue INFO >>21 [86]
2015-03-13 07:37:05 sendUrl INFO 21 [86] R:OK
2015-03-13 07:37:54 queue INFO >>21 [87]
2015-03-13 07:37:55 sendUrl INFO 21 [87] R:OK
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
/usr/bin/python /home/pi/steamware/readParallela.py
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
/usr/bin/python /home/steamware/readSeriale.py
Binary file not shown.
+530
View File
@@ -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
+363
View File
@@ -0,0 +1,363 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#---------------------------------------------------------------
import serial
import time
import sys
import datetime
import urllib
import ConfigParser
import os, sys
#---------------------------------------------------------------
# COSTANTI
MSGLEN = 9
TIMEOUTSERIALE = 10
MAXRETRY = 3
# DA FILE CONF
idxMacchina = "2001"
SAMPLETIME = 0.1
TIMEOUTSHORT = (SAMPLETIME*20)
TIMEOUTLONG = (SAMPLETIME*600)
# VAR
to_enable = False
to_short = TIMEOUTSHORT
to_long = TIMEOUTLONG
to_serial = TIMEOUTSERIALE
to_retry = MAXRETRY
errormsglen = 0
#---------------------------------------------------------------
# classe logger
class Logger:
def __init__(self, filename):
try:
self.filename = filename
except:
logga("LOGGER: errore try su self.filename")
sys.exit(1)
def __call__(self, string):
try:
file = open(self.filename, 'a')
file.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + '] ')
file.write(string + '\n')
file.close()
except:
logga("LOGGER: errore try su scrittura")
sys.exit(1)
#---------------------------------------------------------------
# lettura buffer seriale e pulizia caratteri non stampabili
# ritorna '' se non c'è un messaggio buono o il messaggio pulito ( due bytes hex )
# il messaggio ha il formato xx<ACK>i00 00<CR><LF>xxx
def readSeriale():
global to_serial
global to_retry
global errormsglen
ret = ''
current = ''
i = 0
# ritorna '' se non ci sono abbastanza caratteri
try:
if ser.inWaiting() < MSGLEN :
#
# to_serial = to_serial - 1 # se non mi risponde, faccio un ' altra richiesta....
# if to_serial <= 0:
# try:
# requestData ()
# except:
# logga("SERIALE: errore su requestData")
# sys.exit(1)
# to_serial = TIMEOUTSERIALE # ripristino timer
# to_retry = to_retry - 1 # contatore retry
# if to_retry <= 0:
# logga ( 'IOB not responding' )
# return ret
logga("SERIALE: errore msglen < 9 char - Errore no. " + str(errormsglen))
errormsglen = errormsglen +1
avviaSeriale()
time.sleep(.2)
if errormsglen > 30:
sys.exit(1)
except:
if startstatus == 0:
logga ("Porta SERIALE non disponibile - ser.inWaiting error - exit... - Errore no. " + str(errormsglen))
errormsglen = errormsglen +1
avviaSeriale()
time.sleep(.2)
if errormsglen > 30:
sys.exit(1)
# finchè c'è robba .. leggi e tieni i buoni
to_serial = TIMEOUTSERIALE
to_retry = MAXRETRY
try:
while ser.inWaiting() > 0 :
try:
c = ser.read(1)
except:
logga("SERIALE: errore su try ser.read")
sys.exit(1)
# filtra caratteri non stampabili
if c > ' ' :
current += c
#sys.stdout.write(current + '<<<<\n')
# ora il messaggio ha il formato xxxxxi00 00xxx : cerco la 'i' iniziale
try:
while i < len(current) and current[i] != 'i':
i = i + 1
except:
logga("SERIALE: errore su ricerca i iniziale")
sys.exit(1)
# se non ho trovato la 'i' restituisco ''
if i == len(current)-1:
return ret
else:
current = current[i+1:i+3]
# richiesta dati ad IOB
requestData()
#sys.stdout.write ( current + '\n')
except:
if startstatus == 0:
logga ('Porta SERIALE non disponibile - ser.inWaiting e filtraggio error...exit')
sys.exit(1)
return current
#---------------------------------------------------------------
# richiesta dati ad IOB : scrittura su seriale
def requestData ():
try :
ser.write ("$i" + '\r\n')
ser.flush()
except :
if startstatus == 0:
logga ( "SERIAL: Errore di scrittura/flush")
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLBASE + idxMacchina + URLADV1 + value
urllib.urlopen ( url )
except:
logga ( "NETWORK:Errore http-no com rete-timeout" + url )
#---------------------------------------------------------------
# Funzione che verifica possibilità di creare log e include testo corrente
def logga(message) :
try:
log(message)
except :
pass
#---------------------------------------------------------------
def avviaSeriale():
global ser
try:
ser = serial.Serial(
port = comm_port ,
baudrate = 9600 ,
parity = serial.PARITY_NONE ,
stopbits = serial.STOPBITS_ONE ,
bytesize = serial.EIGHTBITS
)
startstatus = 0
except serial.serialutil.SerialException , e :
try:
if startstatus == 0:
logga ( "SERIAL:Errore apertura seriale - " + comm_port)
except:
pass
sys.stdout.write ( '\nErrore apertura seriale\n\n%s\n\n' % e )
if errormsglen > 30:
sys.exit (1)
#---------------------------------------------------------------
#---------------------------------------------------------------
# MAIN
try:
config = ConfigParser.RawConfigParser()
config.read ( 'IOB.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
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sendReboot v. 1.6
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
import logging
#---------------------------------------------------------------
# COSTANTI
PROGRAM_NAME ="SendReboot IOB-pi v.1.6"
# DA FILE CONF
idxMacchina = "99"
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLREBO + idxMacchina
urllib.urlopen ( url )
except:
logging.info ( "NETWORK:Errore http-no com rete-timeout per url: " + url )
print "Url aforte" , url
#---------------------------------------------------------------
# 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 ) )
chiamaUrl()
+30
View File
@@ -0,0 +1,30 @@
import fcntl
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 ) :
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'
+23
View File
@@ -0,0 +1,23 @@
[id]
idxMacchina = 1006
[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.20
TIMEOUTSHORT = 0.30
TIMEOUTLONG = 50
SENDURLTIME = 0.50
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
LOGREBO = logReboot.txt
[comm]
port = /dev/ttyAMA0
+41
View File
@@ -0,0 +1,41 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start: $remote_fs $syslog ramlog
# Required-Stop: $remote_fs $syslog ramlog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Steamware's MapoIOB driver
# Description: Steamware's MapoIOB driver, versione lettura porta parallela
### END INIT INFO
#! /bin/sh
# /etc/init.d/MapoIOB
export HOME
case "$1" in
start)
echo "Starting readParallela"
cd /home/pi/steamware
/usr/bin/python ./readParallela.py 2>&1 &
;;
stop)
echo "Stopping readParallela"
RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'`
kill -9 $RS_PID
cd /home/pi/steamware
rm .lockfile
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
killall python
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
+40
View File
@@ -0,0 +1,40 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start:
# Required-Stop:
# 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
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia!
DATE=`date +%Y-%m-%d`
cd /var/log
if [ -f MapoIOB ]
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
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
DATE=`date +%Y-%m-%d_%T`
# log inizio pulizia
echo $DATE " - INIZIO pulizia processi python" >> clean.log
# effettua pulizia processi: killa tutti i processi python
killall python
# avvia MapoIob
/etc/init.d/MapoIOB start
# log fatto!
DATE=`date +%Y-%m-%d_%T`
echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
[id]
idxMacchina = 1006
[web]
URLBASE = http://192.168.51.71/MPIO/inputIOB.aspx?idxMacchina=
URLADV1 = &valore=
URLREBO = http://192.168.51.71/MPIO/sendReboot.aspx?idxMacchina=
[time]
SAMPLETIME = 0.5
TIMEOUTSHORT = 2
TIMEOUTLONG = 60
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
[comm]
port = /dev/ttyAMA0
+337
View File
@@ -0,0 +1,337 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# readParallela v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
#---------------------------------------------------------------
# COSTANTI
MSGLEN = 9
TIMEOUTSERIALE = 10
MAXRETRY = 3
PROGRAM_NAME ="ReadPar IOB-pi v.1.1"
# DA FILE CONF
idxMacchina = "1001"
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
# 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
#---------------------------------------------------------------
# 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 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
##### convertire in HEX !!!!
except:
pass
return current
#---------------------------------------------------------------
#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 )
print "Url aforte" , url
#---------------------------------------------------------------
# Funzione che verifica possibilità di creare log e include testo corrente
def logga(message) :
try:
log(message)
except :
pass
#---------------------------------------------------------------
def avviaParallela():
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' )
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)
# 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" + PROGRAM_NAME + "\n\n"
global startstatus
startstatus = 1
if startstatus == 1:
logga("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
logga ( "Start " + PROGRAM_NAME )
# lettura file configurazione
# [id]
# idxMacchina = 2001
# [time]
# SAMPLETIME = 0.1
# TIMEOUTSHORT = 200
# TIMEOUTLONG = 6000
print ( ' idxMacchina = %s' % ( idxMacchina ) )
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 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()
#---------------------------------------------------------------
# ciclo forever and ever
old = ''
while 1:
try:
time.sleep (SAMPLETIME)
except:
logga("First_SLEEP: errore attesa sampletime")
# lettura dati da IOB
value = readParallela()
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
+530
View File
@@ -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
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sendReboot v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
import logging
#---------------------------------------------------------------
# COSTANTI
PROGRAM_NAME ="SendReboot IOB-pi v.1.3"
# DA FILE CONF
idxMacchina = "99"
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLREBO + idxMacchina
urllib.urlopen ( url )
except:
logging.info ( "NETWORK:Errore http-no com rete-timeout per url: " + url )
print "Url aforte" , url
#---------------------------------------------------------------
# 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 ) )
chiamaUrl()
+31
View File
@@ -0,0 +1,31 @@
import fcntl
import os
import logging
#---------------------------------------------------------------
# meccanismo di file lock per evitare multiple instances
# The function will try to lock the file specified , if it success, return True, else return False.
# The nice thing is that the lock will be dropped when the program terminates.
# >>>Use :
# if not lockFile(".lock.pod"):
# sys.exit(0)
def lockFile ( lockfile ) :
fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY )
try:
# Request exclusive (EX) non-blocking (NB) advisory lock.
fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB )
except IOError:
return False
return True
if not lockFile ( ".lockfile" ) :
print '\n noi non siamo soli ...\n'
logging.error( "LOCK: Piu istanze aperte")
#sys.exit ( 0 )
#- print '\n running alone ...\n'
+23
View File
@@ -0,0 +1,23 @@
[id]
idxMacchina = 1007
[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.20
TIMEOUTSHORT = 0.30
TIMEOUTLONG = 50
SENDURLTIME = 0.50
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
LOGREBO = logReboot.txt
[comm]
port = /dev/ttyAMA0
+41
View File
@@ -0,0 +1,41 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start: $remote_fs $syslog ramlog
# Required-Stop: $remote_fs $syslog ramlog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Steamware's MapoIOB driver
# Description: Steamware's MapoIOB driver, versione lettura porta parallela
### END INIT INFO
#! /bin/sh
# /etc/init.d/MapoIOB
export HOME
case "$1" in
start)
echo "Starting readParallela"
cd /home/pi/steamware
/usr/bin/python ./readParallela.py 2>&1 &
;;
stop)
echo "Stopping readParallela"
RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'`
kill -9 $RS_PID
cd /home/pi/steamware
rm .lockfile
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
killall python
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia!
DATE=`date +%Y-%m-%d`
cd /var/log
if [ -f MapoIOB ]
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
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
DATE=`date +%Y-%m-%d_%T`
# log inizio pulizia
echo $DATE " - INIZIO pulizia processi python" >> clean.log
# effettua pulizia processi: killa tutti i processi python
killall python
# avvia MapoIob
/etc/init.d/MapoIOB start
# log fatto!
DATE=`date +%Y-%m-%d_%T`
echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log
+699
View File
@@ -0,0 +1,699 @@
2015-03-12 06:26:02 program INFO Avvio ProgrammaReadPar IOB-pi v.1.7
2015-03-12 06:26:02 program INFO Start ReadPar IOB-pi v.1.7
2015-03-12 06:26:02 program INFO Avvio loop principale
2015-03-12 06:26:02 queue INFO 3 [0]
2015-03-12 06:26:02 queue INFO >3 [1]
2015-03-12 06:26:02 sendUrl INFO 3 [0] R:OK
2015-03-12 06:26:03 sendUrl INFO 3 [1] R:OK
2015-03-12 06:26:46 queue INFO 1 [2]
2015-03-12 06:26:46 queue INFO >1 [3]
2015-03-12 06:26:46 sendUrl INFO 1 [2] R:OK
2015-03-12 06:26:47 sendUrl INFO 1 [3] R:OK
2015-03-12 06:27:36 queue INFO >>1 [4]
2015-03-12 06:27:37 sendUrl INFO 1 [4] R:OK
2015-03-12 06:28:04 queue INFO 21 [5]
2015-03-12 06:28:04 queue INFO >21 [6]
2015-03-12 06:28:04 sendUrl INFO 21 [5] R:OK
2015-03-12 06:28:05 sendUrl INFO 21 [6] R:OK
2015-03-12 06:28:54 queue INFO >>21 [7]
2015-03-12 06:28:55 sendUrl INFO 21 [7] R:OK
2015-03-12 06:29:06 queue INFO 9 [8]
2015-03-12 06:29:06 queue INFO >9 [9]
2015-03-12 06:29:07 sendUrl INFO 9 [8] R:OK
2015-03-12 06:29:07 queue INFO 29 [10]
2015-03-12 06:29:07 queue INFO >29 [11]
2015-03-12 06:29:07 sendUrl INFO 9 [9] R:OK
2015-03-12 06:29:07 queue INFO 21 [12]
2015-03-12 06:29:08 sendUrl INFO 29 [10] R:OK
2015-03-12 06:29:08 queue INFO >21 [13]
2015-03-12 06:29:08 sendUrl INFO 29 [11] R:OK
2015-03-12 06:29:09 sendUrl INFO 21 [12] R:OK
2015-03-12 06:29:09 sendUrl INFO 21 [13] R:OK
2015-03-12 06:29:12 queue INFO 1 [14]
2015-03-12 06:29:12 sendUrl INFO 1 [14] R:OK
2015-03-12 06:29:12 queue INFO >1 [15]
2015-03-12 06:29:13 sendUrl INFO 1 [15] R:OK
2015-03-12 06:29:38 queue INFO 5 [16]
2015-03-12 06:29:39 queue INFO >5 [17]
2015-03-12 06:29:39 sendUrl INFO 5 [16] R:OK
2015-03-12 06:29:39 sendUrl INFO 5 [17] R:OK
2015-03-12 06:29:40 queue INFO 1 [18]
2015-03-12 06:29:40 queue INFO >1 [19]
2015-03-12 06:29:40 sendUrl INFO 1 [18] R:OK
2015-03-12 06:29:41 sendUrl INFO 1 [19] R:OK
2015-03-12 06:30:30 queue INFO >>1 [20]
2015-03-12 06:30:30 sendUrl INFO 1 [20] R:OK
2015-03-12 06:30:33 queue INFO 3 [21]
2015-03-12 06:30:33 queue INFO >3 [22]
2015-03-12 06:30:33 sendUrl INFO 3 [21] R:OK
2015-03-12 06:30:34 sendUrl INFO 3 [22] R:OK
2015-03-12 06:31:23 queue INFO >>3 [23]
2015-03-12 06:31:24 sendUrl INFO 3 [23] R:OK
2015-03-12 06:32:13 queue INFO >>3 [24]
2015-03-12 06:32:13 sendUrl INFO 3 [24] R:OK
2015-03-12 06:33:03 queue INFO >>3 [25]
2015-03-12 06:33:04 sendUrl INFO 3 [25] R:OK
2015-03-12 06:33:53 queue INFO >>3 [26]
2015-03-12 06:33:54 sendUrl INFO 3 [26] R:OK
2015-03-12 06:34:44 queue INFO >>3 [27]
2015-03-12 06:34:44 sendUrl INFO 3 [27] R:OK
2015-03-12 06:35:34 queue INFO >>3 [28]
2015-03-12 06:35:34 sendUrl INFO 3 [28] R:OK
2015-03-12 06:36:24 queue INFO >>3 [29]
2015-03-12 06:36:24 sendUrl INFO 3 [29] R:OK
2015-03-12 06:36:37 queue INFO 1 [30]
2015-03-12 06:36:37 queue INFO >1 [31]
2015-03-12 06:36:38 sendUrl INFO 1 [30] R:OK
2015-03-12 06:36:38 sendUrl INFO 1 [31] R:OK
2015-03-12 06:37:19 queue INFO 21 [32]
2015-03-12 06:37:19 queue INFO >21 [33]
2015-03-12 06:37:19 sendUrl INFO 21 [32] R:OK
2015-03-12 06:37:19 sendUrl INFO 21 [33] R:OK
2015-03-12 06:37:35 queue INFO 1 [34]
2015-03-12 06:37:35 queue INFO >1 [35]
2015-03-12 06:37:35 sendUrl INFO 1 [34] R:OK
2015-03-12 06:37:36 sendUrl INFO 1 [35] R:OK
2015-03-12 06:38:02 queue INFO 5 [36]
2015-03-12 06:38:02 queue INFO >5 [37]
2015-03-12 06:38:02 sendUrl INFO 5 [36] R:OK
2015-03-12 06:38:03 sendUrl INFO 5 [37] R:OK
2015-03-12 06:38:03 queue INFO 1 [38]
2015-03-12 06:38:04 queue INFO >1 [39]
2015-03-12 06:38:04 sendUrl INFO 1 [38] R:OK
2015-03-12 06:38:04 sendUrl INFO 1 [39] R:OK
2015-03-12 06:38:53 queue INFO >>1 [40]
2015-03-12 06:38:54 sendUrl INFO 1 [40] R:OK
2015-03-12 06:38:56 queue INFO 3 [41]
2015-03-12 06:38:57 sendUrl INFO 3 [41] R:OK
2015-03-12 06:38:57 queue INFO >3 [42]
2015-03-12 06:38:57 sendUrl INFO 3 [42] R:OK
2015-03-12 06:39:47 queue INFO >>3 [43]
2015-03-12 06:39:47 sendUrl INFO 3 [43] R:OK
2015-03-12 06:40:37 queue INFO >>3 [44]
2015-03-12 06:40:37 sendUrl INFO 3 [44] R:OK
2015-03-12 06:41:27 queue INFO >>3 [45]
2015-03-12 06:41:27 sendUrl INFO 3 [45] R:OK
2015-03-12 06:42:17 queue INFO >>3 [46]
2015-03-12 06:42:17 sendUrl INFO 3 [46] R:OK
2015-03-12 06:43:07 queue INFO >>3 [47]
2015-03-12 06:43:07 sendUrl INFO 3 [47] R:OK
2015-03-12 06:43:57 queue INFO >>3 [48]
2015-03-12 06:43:58 sendUrl INFO 3 [48] R:OK
2015-03-12 06:44:47 queue INFO >>3 [49]
2015-03-12 06:44:48 sendUrl INFO 3 [49] R:OK
2015-03-12 06:44:53 queue INFO 7 [50]
2015-03-12 06:44:53 sendUrl INFO 7 [50] R:OK
2015-03-12 06:44:53 queue INFO >7 [51]
2015-03-12 06:44:53 sendUrl INFO 7 [51] R:OK
2015-03-12 06:44:54 queue INFO 3 [52]
2015-03-12 06:44:55 queue INFO >3 [53]
2015-03-12 06:44:55 sendUrl INFO 3 [52] R:OK
2015-03-12 06:44:56 sendUrl INFO 3 [53] R:OK
2015-03-12 06:45:45 queue INFO >>3 [54]
2015-03-12 06:45:45 sendUrl INFO 3 [54] R:OK
2015-03-12 06:46:35 queue INFO >>3 [55]
2015-03-12 06:46:35 sendUrl INFO 3 [55] R:OK
2015-03-12 06:47:25 queue INFO >>3 [56]
2015-03-12 06:47:25 sendUrl INFO 3 [56] R:OK
2015-03-12 06:48:15 queue INFO >>3 [57]
2015-03-12 06:48:15 sendUrl INFO 3 [57] R:OK
2015-03-12 06:49:05 queue INFO >>3 [58]
2015-03-12 06:49:06 sendUrl INFO 3 [58] R:OK
2015-03-12 06:49:55 queue INFO >>3 [59]
2015-03-12 06:49:55 sendUrl INFO 3 [59] R:OK
2015-03-12 06:50:45 queue INFO >>3 [60]
2015-03-12 06:50:46 sendUrl INFO 3 [60] R:OK
2015-03-12 06:51:36 queue INFO >>3 [61]
2015-03-12 06:51:36 sendUrl INFO 3 [61] R:OK
2015-03-12 06:51:43 queue INFO 7 [62]
2015-03-12 06:51:43 queue INFO >7 [63]
2015-03-12 06:51:44 sendUrl INFO 7 [62] R:OK
2015-03-12 06:51:44 sendUrl INFO 7 [63] R:OK
2015-03-12 06:51:45 queue INFO 3 [64]
2015-03-12 06:51:45 queue INFO >3 [65]
2015-03-12 06:51:45 sendUrl INFO 3 [64] R:OK
2015-03-12 06:51:46 sendUrl INFO 3 [65] R:OK
2015-03-12 06:52:35 queue INFO >>3 [66]
2015-03-12 06:52:35 sendUrl INFO 3 [66] R:OK
2015-03-12 06:53:25 queue INFO >>3 [67]
2015-03-12 06:53:25 sendUrl INFO 3 [67] R:OK
2015-03-12 06:54:15 queue INFO >>3 [68]
2015-03-12 06:54:16 sendUrl INFO 3 [68] R:OK
2015-03-12 06:55:05 queue INFO >>3 [69]
2015-03-12 06:55:06 sendUrl INFO 3 [69] R:OK
2015-03-12 06:55:56 queue INFO >>3 [70]
2015-03-12 06:55:56 sendUrl INFO 3 [70] R:OK
2015-03-12 06:56:46 queue INFO >>3 [71]
2015-03-12 06:56:46 sendUrl INFO 3 [71] R:OK
2015-03-12 06:57:36 queue INFO >>3 [72]
2015-03-12 06:57:36 sendUrl INFO 3 [72] R:OK
2015-03-12 06:58:26 queue INFO >>3 [73]
2015-03-12 06:58:27 sendUrl INFO 3 [73] R:OK
2015-03-12 06:58:33 queue INFO 7 [74]
2015-03-12 06:58:33 queue INFO >7 [75]
2015-03-12 06:58:34 sendUrl INFO 7 [74] R:OK
2015-03-12 06:58:34 sendUrl INFO 7 [75] R:OK
2015-03-12 06:58:34 queue INFO 3 [76]
2015-03-12 06:58:35 sendUrl INFO 3 [76] R:OK
2015-03-12 06:58:35 queue INFO >3 [77]
2015-03-12 06:58:35 sendUrl INFO 3 [77] R:OK
2015-03-12 06:59:25 queue INFO >>3 [78]
2015-03-12 06:59:25 sendUrl INFO 3 [78] R:OK
2015-03-12 07:00:15 queue INFO >>3 [79]
2015-03-12 07:00:15 sendUrl INFO 3 [79] R:OK
2015-03-12 07:01:05 queue INFO >>3 [80]
2015-03-12 07:01:05 sendUrl INFO 3 [80] R:OK
2015-03-12 07:01:55 queue INFO >>3 [81]
2015-03-12 07:01:56 sendUrl INFO 3 [81] R:OK
2015-03-12 07:02:45 queue INFO >>3 [82]
2015-03-12 07:02:45 sendUrl INFO 3 [82] R:OK
2015-03-12 07:03:35 queue INFO >>3 [83]
2015-03-12 07:03:36 sendUrl INFO 3 [83] R:OK
2015-03-12 07:04:25 queue INFO >>3 [84]
2015-03-12 07:04:26 sendUrl INFO 3 [84] R:OK
2015-03-12 07:05:16 queue INFO >>3 [85]
2015-03-12 07:05:16 sendUrl INFO 3 [85] R:OK
2015-03-12 07:05:25 queue INFO 7 [86]
2015-03-12 07:05:25 queue INFO >7 [87]
2015-03-12 07:05:25 sendUrl INFO 7 [86] R:OK
2015-03-12 07:05:26 sendUrl INFO 7 [87] R:OK
2015-03-12 07:05:27 queue INFO 3 [88]
2015-03-12 07:05:27 queue INFO >3 [89]
2015-03-12 07:05:27 sendUrl INFO 3 [88] R:OK
2015-03-12 07:05:27 sendUrl INFO 3 [89] R:OK
2015-03-12 07:06:17 queue INFO >>3 [90]
2015-03-12 07:06:17 sendUrl INFO 3 [90] R:OK
2015-03-12 07:07:07 queue INFO >>3 [91]
2015-03-12 07:07:07 sendUrl INFO 3 [91] R:OK
2015-03-12 07:07:57 queue INFO >>3 [92]
2015-03-12 07:07:57 sendUrl INFO 3 [92] R:OK
2015-03-12 07:08:47 queue INFO >>3 [93]
2015-03-12 07:08:47 sendUrl INFO 3 [93] R:OK
2015-03-12 07:09:37 queue INFO >>3 [94]
2015-03-12 07:09:38 sendUrl INFO 3 [94] R:OK
2015-03-12 07:10:27 queue INFO >>3 [95]
2015-03-12 07:10:28 sendUrl INFO 3 [95] R:OK
2015-03-12 07:11:18 queue INFO >>3 [96]
2015-03-12 07:11:18 sendUrl INFO 3 [96] R:OK
2015-03-12 07:12:08 queue INFO >>3 [97]
2015-03-12 07:12:08 sendUrl INFO 3 [97] R:OK
2015-03-12 07:12:16 queue INFO 7 [98]
2015-03-12 07:12:16 queue INFO >7 [99]
2015-03-12 07:12:17 sendUrl INFO 7 [98] R:OK
2015-03-12 07:12:17 sendUrl INFO 7 [99] R:OK
2015-03-12 07:12:18 queue INFO 3 [100]
2015-03-12 07:12:18 queue INFO >3 [101]
2015-03-12 07:12:18 sendUrl INFO 3 [100] R:OK
2015-03-12 07:12:19 sendUrl INFO 3 [101] R:OK
2015-03-12 07:13:08 queue INFO >>3 [102]
2015-03-12 07:13:08 sendUrl INFO 3 [102] R:OK
2015-03-12 07:13:58 queue INFO >>3 [103]
2015-03-12 07:13:58 sendUrl INFO 3 [103] R:OK
2015-03-12 07:14:48 queue INFO >>3 [104]
2015-03-12 07:14:49 sendUrl INFO 3 [104] R:OK
2015-03-12 07:15:38 queue INFO >>3 [105]
2015-03-12 07:15:39 sendUrl INFO 3 [105] R:OK
2015-03-12 07:16:28 queue INFO >>3 [106]
2015-03-12 07:16:29 sendUrl INFO 3 [106] R:OK
2015-03-12 07:17:19 queue INFO >>3 [107]
2015-03-12 07:17:19 sendUrl INFO 3 [107] R:OK
2015-03-12 07:18:09 queue INFO >>3 [108]
2015-03-12 07:18:09 sendUrl INFO 3 [108] R:OK
2015-03-12 07:18:59 queue INFO >>3 [109]
2015-03-12 07:18:59 sendUrl INFO 3 [109] R:OK
2015-03-12 07:19:07 queue INFO 7 [110]
2015-03-12 07:19:07 queue INFO >7 [111]
2015-03-12 07:19:07 sendUrl INFO 7 [110] R:OK
2015-03-12 07:19:07 sendUrl INFO 7 [111] R:OK
2015-03-12 07:19:08 queue INFO 3 [112]
2015-03-12 07:19:08 sendUrl INFO 3 [112] R:OK
2015-03-12 07:19:08 queue INFO >3 [113]
2015-03-12 07:19:09 sendUrl INFO 3 [113] R:OK
2015-03-12 07:19:58 queue INFO >>3 [114]
2015-03-12 07:19:59 sendUrl INFO 3 [114] R:OK
2015-03-12 07:20:49 queue INFO >>3 [115]
2015-03-12 07:20:49 sendUrl INFO 3 [115] R:OK
2015-03-12 07:21:39 queue INFO >>3 [116]
2015-03-12 07:21:39 sendUrl INFO 3 [116] R:OK
2015-03-12 07:22:29 queue INFO >>3 [117]
2015-03-12 07:22:29 sendUrl INFO 3 [117] R:OK
2015-03-12 07:23:19 queue INFO >>3 [118]
2015-03-12 07:23:19 sendUrl INFO 3 [118] R:OK
2015-03-12 07:24:09 queue INFO >>3 [119]
2015-03-12 07:24:10 sendUrl INFO 3 [119] R:OK
2015-03-12 07:24:59 queue INFO >>3 [120]
2015-03-12 07:25:00 sendUrl INFO 3 [120] R:OK
2015-03-12 07:25:50 queue INFO >>3 [121]
2015-03-12 07:25:50 sendUrl INFO 3 [121] R:OK
2015-03-12 07:25:56 queue INFO 7 [122]
2015-03-12 07:25:57 queue INFO >7 [123]
2015-03-12 07:25:57 sendUrl INFO 7 [122] R:OK
2015-03-12 07:25:57 sendUrl INFO 7 [123] R:OK
2015-03-12 07:25:58 queue INFO 3 [124]
2015-03-12 07:25:58 queue INFO >3 [125]
2015-03-12 07:25:58 sendUrl INFO 3 [124] R:OK
2015-03-12 07:25:59 sendUrl INFO 3 [125] R:OK
2015-03-12 07:26:48 queue INFO >>3 [126]
2015-03-12 07:26:49 sendUrl INFO 3 [126] R:OK
2015-03-12 07:27:38 queue INFO >>3 [127]
2015-03-12 07:27:38 sendUrl INFO 3 [127] R:OK
2015-03-12 07:28:28 queue INFO >>3 [128]
2015-03-12 07:28:29 sendUrl INFO 3 [128] R:OK
2015-03-12 07:29:19 queue INFO >>3 [129]
2015-03-12 07:29:19 sendUrl INFO 3 [129] R:OK
2015-03-12 07:30:09 queue INFO >>3 [130]
2015-03-12 07:30:09 sendUrl INFO 3 [130] R:OK
2015-03-12 07:30:59 queue INFO >>3 [131]
2015-03-12 07:30:59 sendUrl INFO 3 [131] R:OK
2015-03-12 07:31:49 queue INFO >>3 [132]
2015-03-12 07:31:50 sendUrl INFO 3 [132] R:OK
2015-03-12 07:32:39 queue INFO >>3 [133]
2015-03-12 07:32:39 sendUrl INFO 3 [133] R:OK
2015-03-12 07:32:49 queue INFO 7 [134]
2015-03-12 07:32:49 queue INFO >7 [135]
2015-03-12 07:32:49 sendUrl INFO 7 [134] R:OK
2015-03-12 07:32:49 sendUrl INFO 7 [135] R:OK
2015-03-12 07:32:50 queue INFO 3 [136]
2015-03-12 07:32:50 queue INFO >3 [137]
2015-03-12 07:32:51 sendUrl INFO 3 [136] R:OK
2015-03-12 07:32:51 sendUrl INFO 3 [137] R:OK
2015-03-12 07:33:40 queue INFO >>3 [138]
2015-03-12 07:33:40 sendUrl INFO 3 [138] R:OK
2015-03-12 07:34:30 queue INFO >>3 [139]
2015-03-12 07:34:31 sendUrl INFO 3 [139] R:OK
2015-03-12 07:35:20 queue INFO >>3 [140]
2015-03-12 07:35:21 sendUrl INFO 3 [140] R:OK
2015-03-12 07:36:11 queue INFO >>3 [141]
2015-03-12 07:36:11 sendUrl INFO 3 [141] R:OK
2015-03-12 07:37:01 queue INFO >>3 [142]
2015-03-12 07:37:01 sendUrl INFO 3 [142] R:OK
2015-03-12 07:37:51 queue INFO >>3 [143]
2015-03-12 07:37:52 sendUrl INFO 3 [143] R:OK
2015-03-12 07:38:41 queue INFO >>3 [144]
2015-03-12 07:38:41 sendUrl INFO 3 [144] R:OK
2015-03-12 07:39:31 queue INFO >>3 [145]
2015-03-12 07:39:32 sendUrl INFO 3 [145] R:OK
2015-03-12 07:39:40 queue INFO 7 [146]
2015-03-12 07:39:40 queue INFO >7 [147]
2015-03-12 07:39:40 sendUrl INFO 7 [146] R:OK
2015-03-12 07:39:41 sendUrl INFO 7 [147] R:OK
2015-03-12 07:39:41 queue INFO 3 [148]
2015-03-12 07:39:41 queue INFO >3 [149]
2015-03-12 07:39:42 sendUrl INFO 3 [148] R:OK
2015-03-12 07:39:42 sendUrl INFO 3 [149] R:OK
2015-03-12 07:40:31 queue INFO >>3 [150]
2015-03-12 07:40:32 sendUrl INFO 3 [150] R:OK
2015-03-12 07:41:22 queue INFO >>3 [151]
2015-03-12 07:41:22 sendUrl INFO 3 [151] R:OK
2015-03-12 07:42:12 queue INFO >>3 [152]
2015-03-12 07:42:12 sendUrl INFO 3 [152] R:OK
2015-03-12 07:43:02 queue INFO >>3 [153]
2015-03-12 07:43:02 sendUrl INFO 3 [153] R:OK
2015-03-12 07:43:52 queue INFO >>3 [154]
2015-03-12 07:43:52 sendUrl INFO 3 [154] R:OK
2015-03-12 07:44:42 queue INFO >>3 [155]
2015-03-12 07:44:43 sendUrl INFO 3 [155] R:OK
2015-03-12 07:45:32 queue INFO >>3 [156]
2015-03-12 07:45:33 sendUrl INFO 3 [156] R:OK
2015-03-12 07:46:23 queue INFO >>3 [157]
2015-03-12 07:46:23 sendUrl INFO 3 [157] R:OK
2015-03-12 07:46:30 queue INFO 7 [158]
2015-03-12 07:46:30 queue INFO >7 [159]
2015-03-12 07:46:30 sendUrl INFO 7 [158] R:OK
2015-03-12 07:46:31 sendUrl INFO 7 [159] R:OK
2015-03-12 07:46:32 queue INFO 3 [160]
2015-03-12 07:46:32 queue INFO >3 [161]
2015-03-12 07:46:32 sendUrl INFO 3 [160] R:OK
2015-03-12 07:46:32 sendUrl INFO 3 [161] R:OK
2015-03-12 07:47:22 queue INFO >>3 [162]
2015-03-12 07:47:22 sendUrl INFO 3 [162] R:OK
2015-03-12 07:48:12 queue INFO >>3 [163]
2015-03-12 07:48:12 sendUrl INFO 3 [163] R:OK
2015-03-12 07:49:02 queue INFO >>3 [164]
2015-03-12 07:49:02 sendUrl INFO 3 [164] R:OK
2015-03-12 07:49:52 queue INFO >>3 [165]
2015-03-12 07:49:52 sendUrl INFO 3 [165] R:OK
2015-03-12 07:50:42 queue INFO >>3 [166]
2015-03-12 07:50:43 sendUrl INFO 3 [166] R:OK
2015-03-12 07:51:32 queue INFO >>3 [167]
2015-03-12 07:51:33 sendUrl INFO 3 [167] R:OK
2015-03-12 07:52:23 queue INFO >>3 [168]
2015-03-12 07:52:23 sendUrl INFO 3 [168] R:OK
2015-03-12 07:53:13 queue INFO >>3 [169]
2015-03-12 07:53:13 sendUrl INFO 3 [169] R:OK
2015-03-12 07:53:28 queue INFO 1 [170]
2015-03-12 07:53:28 sendUrl INFO 1 [170] R:OK
2015-03-12 07:53:28 queue INFO >1 [171]
2015-03-12 07:53:28 sendUrl INFO 1 [171] R:OK
2015-03-12 07:53:50 queue INFO 21 [172]
2015-03-12 07:53:50 queue INFO >21 [173]
2015-03-12 07:53:50 sendUrl INFO 21 [172] R:OK
2015-03-12 07:53:51 sendUrl INFO 21 [173] R:OK
2015-03-12 07:54:40 queue INFO >>21 [174]
2015-03-12 07:54:40 sendUrl INFO 21 [174] R:OK
2015-03-12 07:55:16 queue INFO 1 [175]
2015-03-12 07:55:16 queue INFO >1 [176]
2015-03-12 07:55:16 sendUrl INFO 1 [175] R:OK
2015-03-12 07:55:16 sendUrl INFO 1 [176] R:OK
2015-03-12 07:55:42 queue INFO 5 [177]
2015-03-12 07:55:43 queue INFO >5 [178]
2015-03-12 07:55:43 sendUrl INFO 5 [177] R:OK
2015-03-12 07:55:43 sendUrl INFO 5 [178] R:OK
2015-03-12 07:55:44 queue INFO 1 [179]
2015-03-12 07:55:44 sendUrl INFO 1 [179] R:OK
2015-03-12 07:55:44 queue INFO >1 [180]
2015-03-12 07:55:45 sendUrl INFO 1 [180] R:OK
2015-03-12 07:56:34 queue INFO >>1 [181]
2015-03-12 07:56:35 sendUrl INFO 1 [181] R:OK
2015-03-12 07:56:37 queue INFO 3 [182]
2015-03-12 07:56:37 queue INFO >3 [183]
2015-03-12 07:56:38 sendUrl INFO 3 [182] R:OK
2015-03-12 07:56:38 sendUrl INFO 3 [183] R:OK
2015-03-12 07:57:27 queue INFO >>3 [184]
2015-03-12 07:57:27 sendUrl INFO 3 [184] R:OK
2015-03-12 07:58:17 queue INFO >>3 [185]
2015-03-12 07:58:18 sendUrl INFO 3 [185] R:OK
2015-03-12 07:59:07 queue INFO >>3 [186]
2015-03-12 07:59:08 sendUrl INFO 3 [186] R:OK
2015-03-12 07:59:58 queue INFO >>3 [187]
2015-03-12 07:59:58 sendUrl INFO 3 [187] R:OK
2015-03-12 08:00:48 queue INFO >>3 [188]
2015-03-12 08:00:48 sendUrl INFO 3 [188] R:OK
2015-03-12 08:01:38 queue INFO >>3 [189]
2015-03-12 08:01:38 sendUrl INFO 3 [189] R:OK
2015-03-12 08:02:28 queue INFO >>3 [190]
2015-03-12 08:02:28 sendUrl INFO 3 [190] R:OK
2015-03-12 08:02:41 queue INFO 1 [191]
2015-03-12 08:02:41 sendUrl INFO 1 [191] R:OK
2015-03-12 08:02:42 queue INFO >1 [192]
2015-03-12 08:02:42 sendUrl INFO 1 [192] R:OK
2015-03-12 08:03:12 queue INFO 21 [193]
2015-03-12 08:03:12 queue INFO >21 [194]
2015-03-12 08:03:12 sendUrl INFO 21 [193] R:OK
2015-03-12 08:03:13 sendUrl INFO 21 [194] R:OK
2015-03-12 08:04:02 queue INFO >>21 [195]
2015-03-12 08:04:02 sendUrl INFO 21 [195] R:OK
2015-03-12 08:04:27 queue INFO 1 [196]
2015-03-12 08:04:27 queue INFO >1 [197]
2015-03-12 08:04:27 sendUrl INFO 1 [196] R:OK
2015-03-12 08:04:28 sendUrl INFO 1 [197] R:OK
2015-03-12 08:04:53 queue INFO 5 [198]
2015-03-12 08:04:53 queue INFO >5 [199]
2015-03-12 08:04:53 sendUrl INFO 5 [198] R:OK
2015-03-12 08:04:54 sendUrl INFO 5 [199] R:OK
2015-03-12 08:04:55 queue INFO 1 [200]
2015-03-12 08:04:55 sendUrl INFO 1 [200] R:OK
2015-03-12 08:04:55 queue INFO >1 [201]
2015-03-12 08:04:55 sendUrl INFO 1 [201] R:OK
2015-03-12 08:05:45 queue INFO >>1 [202]
2015-03-12 08:05:45 sendUrl INFO 1 [202] R:OK
2015-03-12 08:05:48 queue INFO 3 [203]
2015-03-12 08:05:48 queue INFO >3 [204]
2015-03-12 08:05:48 sendUrl INFO 3 [203] R:OK
2015-03-12 08:05:49 sendUrl INFO 3 [204] R:OK
2015-03-12 08:06:38 queue INFO >>3 [205]
2015-03-12 08:06:39 sendUrl INFO 3 [205] R:OK
2015-03-12 08:07:28 queue INFO >>3 [206]
2015-03-12 08:07:28 sendUrl INFO 3 [206] R:OK
2015-03-12 08:08:18 queue INFO >>3 [207]
2015-03-12 08:08:19 sendUrl INFO 3 [207] R:OK
2015-03-12 08:09:08 queue INFO >>3 [208]
2015-03-12 08:09:09 sendUrl INFO 3 [208] R:OK
2015-03-12 08:09:59 queue INFO >>3 [209]
2015-03-12 08:09:59 sendUrl INFO 3 [209] R:OK
2015-03-12 08:10:49 queue INFO >>3 [210]
2015-03-12 08:10:49 sendUrl INFO 3 [210] R:OK
2015-03-12 08:11:39 queue INFO >>3 [211]
2015-03-12 08:11:39 sendUrl INFO 3 [211] R:OK
2015-03-12 08:11:52 queue INFO 1 [212]
2015-03-12 08:11:52 queue INFO >1 [213]
2015-03-12 08:11:53 sendUrl INFO 1 [212] R:OK
2015-03-12 08:11:53 sendUrl INFO 1 [213] R:OK
2015-03-12 08:12:42 queue INFO >>1 [214]
2015-03-12 08:12:42 sendUrl INFO 1 [214] R:OK
2015-03-12 08:13:32 queue INFO >>1 [215]
2015-03-12 08:13:33 sendUrl INFO 1 [215] R:OK
2015-03-12 08:14:23 queue INFO >>1 [216]
2015-03-12 08:14:23 sendUrl INFO 1 [216] R:OK
2015-03-12 08:15:13 queue INFO >>1 [217]
2015-03-12 08:15:13 sendUrl INFO 1 [217] R:OK
2015-03-12 08:16:03 queue INFO >>1 [218]
2015-03-12 08:16:03 sendUrl INFO 1 [218] R:OK
2015-03-12 08:16:53 queue INFO >>1 [219]
2015-03-12 08:16:54 sendUrl INFO 1 [219] R:OK
2015-03-12 08:17:43 queue INFO >>1 [220]
2015-03-12 08:17:43 sendUrl INFO 1 [220] R:OK
2015-03-12 08:18:33 queue INFO >>1 [221]
2015-03-12 08:18:34 sendUrl INFO 1 [221] R:OK
2015-03-12 08:19:24 queue INFO >>1 [222]
2015-03-12 08:19:24 sendUrl INFO 1 [222] R:OK
2015-03-12 08:20:14 queue INFO >>1 [223]
2015-03-12 08:20:14 sendUrl INFO 1 [223] R:OK
2015-03-12 08:21:04 queue INFO >>1 [224]
2015-03-12 08:21:04 sendUrl INFO 1 [224] R:OK
2015-03-12 08:21:54 queue INFO >>1 [225]
2015-03-12 08:21:54 sendUrl INFO 1 [225] R:OK
2015-03-12 08:22:44 queue INFO >>1 [226]
2015-03-12 08:22:44 sendUrl INFO 1 [226] R:OK
2015-03-12 08:23:34 queue INFO >>1 [227]
2015-03-12 08:23:35 sendUrl INFO 1 [227] R:OK
2015-03-12 08:24:24 queue INFO >>1 [228]
2015-03-12 08:24:25 sendUrl INFO 1 [228] R:OK
2015-03-12 08:25:15 queue INFO >>1 [229]
2015-03-12 08:25:15 sendUrl INFO 1 [229] R:OK
2015-03-12 08:25:53 queue INFO 21 [230]
2015-03-12 08:25:53 sendUrl INFO 21 [230] R:OK
2015-03-12 08:25:53 queue INFO >21 [231]
2015-03-12 08:25:53 sendUrl INFO 21 [231] R:OK
2015-03-12 08:26:33 queue INFO 1 [232]
2015-03-12 08:26:34 queue INFO >1 [233]
2015-03-12 08:26:34 sendUrl INFO 1 [232] R:OK
2015-03-12 08:26:34 sendUrl INFO 1 [233] R:OK
2015-03-12 08:27:08 queue INFO 21 [234]
2015-03-12 08:27:08 sendUrl INFO 21 [234] R:OK
2015-03-12 08:27:08 queue INFO >21 [235]
2015-03-12 08:27:08 sendUrl INFO 21 [235] R:OK
2015-03-12 08:27:58 queue INFO >>21 [236]
2015-03-12 08:27:58 sendUrl INFO 21 [236] R:OK
2015-03-12 08:28:00 queue INFO 1 [237]
2015-03-12 08:28:01 queue INFO >1 [238]
2015-03-12 08:28:01 sendUrl INFO 1 [237] R:OK
2015-03-12 08:28:01 sendUrl INFO 1 [238] R:OK
2015-03-12 08:28:51 queue INFO >>1 [239]
2015-03-12 08:28:51 sendUrl INFO 1 [239] R:OK
2015-03-12 08:29:00 queue INFO 3 [240]
2015-03-12 08:29:01 sendUrl INFO 3 [240] R:OK
2015-03-12 08:29:01 queue INFO >3 [241]
2015-03-12 08:29:01 sendUrl INFO 3 [241] R:OK
2015-03-12 08:29:50 queue INFO >>3 [242]
2015-03-12 08:29:51 sendUrl INFO 3 [242] R:OK
2015-03-12 08:30:41 queue INFO >>3 [243]
2015-03-12 08:30:41 sendUrl INFO 3 [243] R:OK
2015-03-12 08:31:31 queue INFO >>3 [244]
2015-03-12 08:31:31 sendUrl INFO 3 [244] R:OK
2015-03-12 08:32:21 queue INFO >>3 [245]
2015-03-12 08:32:21 sendUrl INFO 3 [245] R:OK
2015-03-12 08:33:11 queue INFO >>3 [246]
2015-03-12 08:33:12 sendUrl INFO 3 [246] R:OK
2015-03-12 08:34:01 queue INFO >>3 [247]
2015-03-12 08:34:01 sendUrl INFO 3 [247] R:OK
2015-03-12 08:34:51 queue INFO >>3 [248]
2015-03-12 08:34:52 sendUrl INFO 3 [248] R:OK
2015-03-12 08:34:57 queue INFO 7 [249]
2015-03-12 08:34:57 queue INFO >7 [250]
2015-03-12 08:34:57 sendUrl INFO 7 [249] R:OK
2015-03-12 08:34:58 sendUrl INFO 7 [250] R:OK
2015-03-12 08:34:58 queue INFO 3 [251]
2015-03-12 08:34:59 queue INFO >3 [252]
2015-03-12 08:34:59 sendUrl INFO 3 [251] R:OK
2015-03-12 08:34:59 sendUrl INFO 3 [252] R:OK
2015-03-12 08:35:49 queue INFO >>3 [253]
2015-03-12 08:35:49 sendUrl INFO 3 [253] R:OK
2015-03-12 08:36:39 queue INFO >>3 [254]
2015-03-12 08:36:39 sendUrl INFO 3 [254] R:OK
2015-03-12 08:37:29 queue INFO >>3 [255]
2015-03-12 08:37:29 sendUrl INFO 3 [255] R:OK
2015-03-12 08:38:19 queue INFO >>3 [256]
2015-03-12 08:38:19 sendUrl INFO 3 [256] R:OK
2015-03-12 08:39:09 queue INFO >>3 [257]
2015-03-12 08:39:10 sendUrl INFO 3 [257] R:OK
2015-03-12 08:39:59 queue INFO >>3 [258]
2015-03-12 08:40:00 sendUrl INFO 3 [258] R:OK
2015-03-12 08:40:50 queue INFO >>3 [259]
2015-03-12 08:40:50 sendUrl INFO 3 [259] R:OK
2015-03-12 08:41:40 queue INFO >>3 [260]
2015-03-12 08:41:40 sendUrl INFO 3 [260] R:OK
2015-03-12 08:41:47 queue INFO 7 [261]
2015-03-12 08:41:47 queue INFO >7 [262]
2015-03-12 08:41:48 sendUrl INFO 7 [261] R:OK
2015-03-12 08:41:48 sendUrl INFO 7 [262] R:OK
2015-03-12 08:41:49 queue INFO 3 [263]
2015-03-12 08:41:49 queue INFO >3 [264]
2015-03-12 08:41:49 sendUrl INFO 3 [263] R:OK
2015-03-12 08:41:50 sendUrl INFO 3 [264] R:OK
2015-03-12 08:42:39 queue INFO >>3 [265]
2015-03-12 08:42:39 sendUrl INFO 3 [265] R:OK
2015-03-12 08:43:29 queue INFO >>3 [266]
2015-03-12 08:43:29 sendUrl INFO 3 [266] R:OK
2015-03-12 08:44:19 queue INFO >>3 [267]
2015-03-12 08:44:20 sendUrl INFO 3 [267] R:OK
2015-03-12 08:45:09 queue INFO >>3 [268]
2015-03-12 08:45:10 sendUrl INFO 3 [268] R:OK
2015-03-12 08:46:00 queue INFO >>3 [269]
2015-03-12 08:46:00 sendUrl INFO 3 [269] R:OK
2015-03-12 08:46:50 queue INFO >>3 [270]
2015-03-12 08:46:50 sendUrl INFO 3 [270] R:OK
2015-03-12 08:47:40 queue INFO >>3 [271]
2015-03-12 08:47:40 sendUrl INFO 3 [271] R:OK
2015-03-12 08:48:30 queue INFO >>3 [272]
2015-03-12 08:48:30 sendUrl INFO 3 [272] R:OK
2015-03-12 08:48:37 queue INFO 7 [273]
2015-03-12 08:48:37 queue INFO >7 [274]
2015-03-12 08:48:37 sendUrl INFO 7 [273] R:OK
2015-03-12 08:48:38 sendUrl INFO 7 [274] R:OK
2015-03-12 08:48:39 queue INFO 3 [275]
2015-03-12 08:48:39 queue INFO >3 [276]
2015-03-12 08:48:39 sendUrl INFO 3 [275] R:OK
2015-03-12 08:48:39 sendUrl INFO 3 [276] R:OK
2015-03-12 08:49:29 queue INFO >>3 [277]
2015-03-12 08:49:29 sendUrl INFO 3 [277] R:OK
2015-03-12 08:50:19 queue INFO >>3 [278]
2015-03-12 08:50:19 sendUrl INFO 3 [278] R:OK
2015-03-12 08:51:09 queue INFO >>3 [279]
2015-03-12 08:51:09 sendUrl INFO 3 [279] R:OK
2015-03-12 08:51:59 queue INFO >>3 [280]
2015-03-12 08:51:59 sendUrl INFO 3 [280] R:OK
2015-03-12 08:52:49 queue INFO >>3 [281]
2015-03-12 08:52:50 sendUrl INFO 3 [281] R:OK
2015-03-12 08:53:11 queue INFO 1 [282]
2015-03-12 08:53:12 queue INFO >1 [283]
2015-03-12 08:53:12 sendUrl INFO 1 [282] R:OK
2015-03-12 08:53:12 sendUrl INFO 1 [283] R:OK
2015-03-12 08:54:02 queue INFO >>1 [284]
2015-03-12 08:54:02 sendUrl INFO 1 [284] R:OK
2015-03-12 08:54:52 queue INFO >>1 [285]
2015-03-12 08:54:52 sendUrl INFO 1 [285] R:OK
2015-03-12 08:55:22 queue INFO 21 [286]
2015-03-12 08:55:22 queue INFO >21 [287]
2015-03-12 08:55:22 sendUrl INFO 21 [286] R:OK
2015-03-12 08:55:23 sendUrl INFO 21 [287] R:OK
2015-03-12 08:56:12 queue INFO >>21 [288]
2015-03-12 08:56:12 sendUrl INFO 21 [288] R:OK
2015-03-12 08:57:02 queue INFO >>21 [289]
2015-03-12 08:57:02 sendUrl INFO 21 [289] R:OK
2015-03-12 08:57:52 queue INFO >>21 [290]
2015-03-12 08:57:53 sendUrl INFO 21 [290] R:OK
2015-03-12 08:58:42 queue INFO >>21 [291]
2015-03-12 08:58:42 sendUrl INFO 21 [291] R:OK
2015-03-12 08:59:32 queue INFO >>21 [292]
2015-03-12 08:59:33 sendUrl INFO 21 [292] R:OK
2015-03-12 09:00:23 queue INFO >>21 [293]
2015-03-12 09:00:23 sendUrl INFO 21 [293] R:OK
2015-03-12 09:01:13 queue INFO >>21 [294]
2015-03-12 09:01:13 sendUrl INFO 21 [294] R:OK
2015-03-12 09:02:03 queue INFO >>21 [295]
2015-03-12 09:02:03 sendUrl INFO 21 [295] R:OK
2015-03-12 09:02:53 queue INFO >>21 [296]
2015-03-12 09:02:54 sendUrl INFO 21 [296] R:OK
2015-03-12 09:02:58 queue INFO 1 [297]
2015-03-12 09:02:58 queue INFO >1 [298]
2015-03-12 09:02:58 sendUrl INFO 1 [297] R:OK
2015-03-12 09:02:59 sendUrl INFO 1 [298] R:OK
2015-03-12 09:03:24 queue INFO 5 [299]
2015-03-12 09:03:24 queue INFO >5 [300]
2015-03-12 09:03:24 sendUrl INFO 5 [299] R:OK
2015-03-12 09:03:25 sendUrl INFO 5 [300] R:OK
2015-03-12 09:03:25 queue INFO 1 [301]
2015-03-12 09:03:26 queue INFO >1 [302]
2015-03-12 09:03:26 sendUrl INFO 1 [301] R:OK
2015-03-12 09:03:26 sendUrl INFO 1 [302] R:OK
2015-03-12 09:04:16 queue INFO >>1 [303]
2015-03-12 09:04:16 sendUrl INFO 1 [303] R:OK
2015-03-12 09:04:19 queue INFO 3 [304]
2015-03-12 09:04:19 queue INFO >3 [305]
2015-03-12 09:04:19 sendUrl INFO 3 [304] R:OK
2015-03-12 09:04:20 sendUrl INFO 3 [305] R:OK
2015-03-12 09:05:09 queue INFO >>3 [306]
2015-03-12 09:05:09 sendUrl INFO 3 [306] R:OK
2015-03-12 09:05:59 queue INFO >>3 [307]
2015-03-12 09:05:59 sendUrl INFO 3 [307] R:OK
2015-03-12 09:06:49 queue INFO >>3 [308]
2015-03-12 09:06:50 sendUrl INFO 3 [308] R:OK
2015-03-12 09:07:39 queue INFO >>3 [309]
2015-03-12 09:07:39 sendUrl INFO 3 [309] R:OK
2015-03-12 09:08:29 queue INFO >>3 [310]
2015-03-12 09:08:30 sendUrl INFO 3 [310] R:OK
2015-03-12 09:09:20 queue INFO >>3 [311]
2015-03-12 09:09:20 sendUrl INFO 3 [311] R:OK
2015-03-12 09:10:10 queue INFO >>3 [312]
2015-03-12 09:10:10 sendUrl INFO 3 [312] R:OK
2015-03-12 09:10:15 queue INFO 7 [313]
2015-03-12 09:10:15 queue INFO >7 [314]
2015-03-12 09:10:16 sendUrl INFO 7 [313] R:OK
2015-03-12 09:10:16 sendUrl INFO 7 [314] R:OK
2015-03-12 09:10:17 queue INFO 3 [315]
2015-03-12 09:10:17 queue INFO >3 [316]
2015-03-12 09:10:17 sendUrl INFO 3 [315] R:OK
2015-03-12 09:10:18 sendUrl INFO 3 [316] R:OK
2015-03-12 09:11:07 queue INFO >>3 [317]
2015-03-12 09:11:07 sendUrl INFO 3 [317] R:OK
2015-03-12 09:11:57 queue INFO >>3 [318]
2015-03-12 09:11:57 sendUrl INFO 3 [318] R:OK
2015-03-12 09:12:47 queue INFO >>3 [319]
2015-03-12 09:12:48 sendUrl INFO 3 [319] R:OK
2015-03-12 09:13:37 queue INFO >>3 [320]
2015-03-12 09:13:38 sendUrl INFO 3 [320] R:OK
2015-03-12 09:14:27 queue INFO >>3 [321]
2015-03-12 09:14:28 sendUrl INFO 3 [321] R:OK
2015-03-12 09:15:18 queue INFO >>3 [322]
2015-03-12 09:15:18 sendUrl INFO 3 [322] R:OK
2015-03-12 09:16:08 queue INFO >>3 [323]
2015-03-12 09:16:08 sendUrl INFO 3 [323] R:OK
2015-03-12 09:16:58 queue INFO >>3 [324]
2015-03-12 09:16:58 sendUrl INFO 3 [324] R:OK
2015-03-12 09:17:06 queue INFO 7 [325]
2015-03-12 09:17:06 sendUrl INFO 7 [325] R:OK
2015-03-12 09:17:06 queue INFO >7 [326]
2015-03-12 09:17:06 sendUrl INFO 7 [326] R:OK
2015-03-12 09:17:07 queue INFO 3 [327]
2015-03-12 09:17:07 queue INFO >3 [328]
2015-03-12 09:17:08 sendUrl INFO 3 [327] R:OK
2015-03-12 09:17:08 sendUrl INFO 3 [328] R:OK
2015-03-12 09:17:57 queue INFO >>3 [329]
2015-03-12 09:17:58 sendUrl INFO 3 [329] R:OK
2015-03-12 09:18:47 queue INFO >>3 [330]
2015-03-12 09:18:48 sendUrl INFO 3 [330] R:OK
2015-03-12 09:19:38 queue INFO >>3 [331]
2015-03-12 09:19:38 sendUrl INFO 3 [331] R:OK
2015-03-12 09:20:28 queue INFO >>3 [332]
2015-03-12 09:20:28 sendUrl INFO 3 [332] R:OK
2015-03-12 09:21:18 queue INFO >>3 [333]
2015-03-12 09:21:18 sendUrl INFO 3 [333] R:OK
2015-03-12 09:22:08 queue INFO >>3 [334]
2015-03-12 09:22:08 sendUrl INFO 3 [334] R:OK
2015-03-12 09:22:58 queue INFO >>3 [335]
2015-03-12 09:22:59 sendUrl INFO 3 [335] R:OK
2015-03-12 09:23:48 queue INFO >>3 [336]
2015-03-12 09:23:49 sendUrl INFO 3 [336] R:OK
2015-03-12 09:23:55 queue INFO 7 [337]
2015-03-12 09:23:55 queue INFO >7 [338]
2015-03-12 09:23:56 sendUrl INFO 7 [337] R:OK
2015-03-12 09:23:56 sendUrl INFO 7 [338] R:OK
2015-03-12 09:23:57 queue INFO 3 [339]
2015-03-12 09:23:57 sendUrl INFO 3 [339] R:OK
2015-03-12 09:23:57 queue INFO >3 [340]
2015-03-12 09:23:57 sendUrl INFO 3 [340] R:OK
2015-03-12 09:24:47 queue INFO >>3 [341]
2015-03-12 09:24:47 sendUrl INFO 3 [341] R:OK
2015-03-12 09:25:37 queue INFO >>3 [342]
2015-03-12 09:25:38 sendUrl INFO 3 [342] R:OK
2015-03-12 09:26:27 queue INFO >>3 [343]
2015-03-12 09:26:27 sendUrl INFO 3 [343] R:OK
2015-03-12 09:27:17 queue INFO >>3 [344]
2015-03-12 09:27:18 sendUrl INFO 3 [344] R:OK
2015-03-12 09:28:08 queue INFO >>3 [345]
2015-03-12 09:28:08 sendUrl INFO 3 [345] R:OK
2015-03-12 09:28:58 queue INFO >>3 [346]
2015-03-12 09:28:58 sendUrl INFO 3 [346] R:OK
2015-03-12 09:29:48 queue INFO >>3 [347]
2015-03-12 09:29:48 sendUrl INFO 3 [347] R:OK
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
[id]
idxMacchina = 1007
[web]
URLBASE = http://192.168.51.71/MPIO/inputIOB.aspx?idxMacchina=
URLADV1 = &valore=
URLREBO = http://192.168.51.71/MPIO/sendReboot.aspx?idxMacchina=
[time]
SAMPLETIME = 0.5
TIMEOUTSHORT = 2
TIMEOUTLONG = 60
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
[comm]
port = /dev/ttyAMA0
+337
View File
@@ -0,0 +1,337 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# readParallela v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
#---------------------------------------------------------------
# COSTANTI
MSGLEN = 9
TIMEOUTSERIALE = 10
MAXRETRY = 3
PROGRAM_NAME ="ReadPar IOB-pi v.1.1"
# DA FILE CONF
idxMacchina = "1001"
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
# 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
#---------------------------------------------------------------
# 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 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
##### convertire in HEX !!!!
except:
pass
return current
#---------------------------------------------------------------
#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 )
print "Url aforte" , url
#---------------------------------------------------------------
# Funzione che verifica possibilità di creare log e include testo corrente
def logga(message) :
try:
log(message)
except :
pass
#---------------------------------------------------------------
def avviaParallela():
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' )
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)
# 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" + PROGRAM_NAME + "\n\n"
global startstatus
startstatus = 1
if startstatus == 1:
logga("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
logga ( "Start " + PROGRAM_NAME )
# lettura file configurazione
# [id]
# idxMacchina = 2001
# [time]
# SAMPLETIME = 0.1
# TIMEOUTSHORT = 200
# TIMEOUTLONG = 6000
print ( ' idxMacchina = %s' % ( idxMacchina ) )
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 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()
#---------------------------------------------------------------
# ciclo forever and ever
old = ''
while 1:
try:
time.sleep (SAMPLETIME)
except:
logga("First_SLEEP: errore attesa sampletime")
# lettura dati da IOB
value = readParallela()
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
+530
View File
@@ -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
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sendReboot v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
import logging
#---------------------------------------------------------------
# COSTANTI
PROGRAM_NAME ="SendReboot IOB-pi v.1.3"
# DA FILE CONF
idxMacchina = "99"
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLREBO + idxMacchina
urllib.urlopen ( url )
except:
logging.info ( "NETWORK:Errore http-no com rete-timeout per url: " + url )
print "Url aforte" , url
#---------------------------------------------------------------
# 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 ) )
chiamaUrl()
+31
View File
@@ -0,0 +1,31 @@
import fcntl
import os
import logging
#---------------------------------------------------------------
# meccanismo di file lock per evitare multiple instances
# The function will try to lock the file specified , if it success, return True, else return False.
# The nice thing is that the lock will be dropped when the program terminates.
# >>>Use :
# if not lockFile(".lock.pod"):
# sys.exit(0)
def lockFile ( lockfile ) :
fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY )
try:
# Request exclusive (EX) non-blocking (NB) advisory lock.
fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB )
except IOError:
return False
return True
if not lockFile ( ".lockfile" ) :
print '\n noi non siamo soli ...\n'
logging.error( "LOCK: Piu istanze aperte")
#sys.exit ( 0 )
#- print '\n running alone ...\n'
+23
View File
@@ -0,0 +1,23 @@
[id]
idxMacchina = 1008
[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.20
TIMEOUTSHORT = 0.30
TIMEOUTLONG = 50
SENDURLTIME = 0.50
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
LOGREBO = logReboot.txt
[comm]
port = /dev/ttyAMA0
+41
View File
@@ -0,0 +1,41 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start: $remote_fs $syslog ramlog
# Required-Stop: $remote_fs $syslog ramlog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Steamware's MapoIOB driver
# Description: Steamware's MapoIOB driver, versione lettura porta parallela
### END INIT INFO
#! /bin/sh
# /etc/init.d/MapoIOB
export HOME
case "$1" in
start)
echo "Starting readParallela"
cd /home/pi/steamware
/usr/bin/python ./readParallela.py 2>&1 &
;;
stop)
echo "Stopping readParallela"
RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'`
kill -9 $RS_PID
cd /home/pi/steamware
rm .lockfile
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
killall python
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
File diff suppressed because it is too large Load Diff
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia!
DATE=`date +%Y-%m-%d`
cd /var/log
if [ -f MapoIOB ]
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
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
DATE=`date +%Y-%m-%d_%T`
# log inizio pulizia
echo $DATE " - INIZIO pulizia processi python" >> clean.log
# effettua pulizia processi: killa tutti i processi python
killall python
# avvia MapoIob
/etc/init.d/MapoIOB start
# log fatto!
DATE=`date +%Y-%m-%d_%T`
echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
[id]
idxMacchina = 1008
[web]
URLBASE = http://192.168.51.71/MPIO/inputIOB.aspx?idxMacchina=
URLADV1 = &valore=
URLREBO = http://192.168.51.71/MPIO/sendReboot.aspx?idxMacchina=
[time]
SAMPLETIME = 0.5
TIMEOUTSHORT = 2
TIMEOUTLONG = 60
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
[comm]
port = /dev/ttyAMA0
+337
View File
@@ -0,0 +1,337 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# readParallela v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
#---------------------------------------------------------------
# COSTANTI
MSGLEN = 9
TIMEOUTSERIALE = 10
MAXRETRY = 3
PROGRAM_NAME ="ReadPar IOB-pi v.1.1"
# DA FILE CONF
idxMacchina = "1001"
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
# 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
#---------------------------------------------------------------
# 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 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
##### convertire in HEX !!!!
except:
pass
return current
#---------------------------------------------------------------
#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 )
print "Url aforte" , url
#---------------------------------------------------------------
# Funzione che verifica possibilità di creare log e include testo corrente
def logga(message) :
try:
log(message)
except :
pass
#---------------------------------------------------------------
def avviaParallela():
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' )
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)
# 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" + PROGRAM_NAME + "\n\n"
global startstatus
startstatus = 1
if startstatus == 1:
logga("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
logga ( "Start " + PROGRAM_NAME )
# lettura file configurazione
# [id]
# idxMacchina = 2001
# [time]
# SAMPLETIME = 0.1
# TIMEOUTSHORT = 200
# TIMEOUTLONG = 6000
print ( ' idxMacchina = %s' % ( idxMacchina ) )
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 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()
#---------------------------------------------------------------
# ciclo forever and ever
old = ''
while 1:
try:
time.sleep (SAMPLETIME)
except:
logga("First_SLEEP: errore attesa sampletime")
# lettura dati da IOB
value = readParallela()
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
+530
View File
@@ -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
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sendReboot v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
import logging
#---------------------------------------------------------------
# COSTANTI
PROGRAM_NAME ="SendReboot IOB-pi v.1.3"
# DA FILE CONF
idxMacchina = "99"
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLREBO + idxMacchina
urllib.urlopen ( url )
except:
logging.info ( "NETWORK:Errore http-no com rete-timeout per url: " + url )
print "Url aforte" , url
#---------------------------------------------------------------
# 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 ) )
chiamaUrl()
+31
View File
@@ -0,0 +1,31 @@
import fcntl
import os
import logging
#---------------------------------------------------------------
# meccanismo di file lock per evitare multiple instances
# The function will try to lock the file specified , if it success, return True, else return False.
# The nice thing is that the lock will be dropped when the program terminates.
# >>>Use :
# if not lockFile(".lock.pod"):
# sys.exit(0)
def lockFile ( lockfile ) :
fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY )
try:
# Request exclusive (EX) non-blocking (NB) advisory lock.
fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB )
except IOError:
return False
return True
if not lockFile ( ".lockfile" ) :
print '\n noi non siamo soli ...\n'
logging.error( "LOCK: Piu istanze aperte")
#sys.exit ( 0 )
#- print '\n running alone ...\n'
+23
View File
@@ -0,0 +1,23 @@
[id]
idxMacchina = 1009
[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.20
TIMEOUTSHORT = 0.30
TIMEOUTLONG = 50
SENDURLTIME = 0.50
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
LOGREBO = logReboot.txt
[comm]
port = /dev/ttyAMA0
+41
View File
@@ -0,0 +1,41 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start: $remote_fs $syslog ramlog
# Required-Stop: $remote_fs $syslog ramlog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Steamware's MapoIOB driver
# Description: Steamware's MapoIOB driver, versione lettura porta parallela
### END INIT INFO
#! /bin/sh
# /etc/init.d/MapoIOB
export HOME
case "$1" in
start)
echo "Starting readParallela"
cd /home/pi/steamware
/usr/bin/python ./readParallela.py 2>&1 &
;;
stop)
echo "Stopping readParallela"
RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'`
kill -9 $RS_PID
cd /home/pi/steamware
rm .lockfile
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
killall python
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia!
DATE=`date +%Y-%m-%d`
cd /var/log
if [ -f MapoIOB ]
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
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
DATE=`date +%Y-%m-%d_%T`
# log inizio pulizia
echo $DATE " - INIZIO pulizia processi python" >> clean.log
# effettua pulizia processi: killa tutti i processi python
killall python
# avvia MapoIob
/etc/init.d/MapoIOB start
# log fatto!
DATE=`date +%Y-%m-%d_%T`
echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
[id]
idxMacchina = 1009
[web]
URLBASE = http://192.168.51.71/MPIO/inputIOB.aspx?idxMacchina=
URLADV1 = &valore=
URLREBO = http://192.168.51.71/MPIO/sendReboot.aspx?idxMacchina=
[time]
SAMPLETIME = 0.5
TIMEOUTSHORT = 2
TIMEOUTLONG = 60
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
[comm]
port = /dev/ttyAMA0
+337
View File
@@ -0,0 +1,337 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# readParallela v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
#---------------------------------------------------------------
# COSTANTI
MSGLEN = 9
TIMEOUTSERIALE = 10
MAXRETRY = 3
PROGRAM_NAME ="ReadPar IOB-pi v.1.1"
# DA FILE CONF
idxMacchina = "1001"
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
# 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
#---------------------------------------------------------------
# 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 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
##### convertire in HEX !!!!
except:
pass
return current
#---------------------------------------------------------------
#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 )
print "Url aforte" , url
#---------------------------------------------------------------
# Funzione che verifica possibilità di creare log e include testo corrente
def logga(message) :
try:
log(message)
except :
pass
#---------------------------------------------------------------
def avviaParallela():
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' )
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)
# 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" + PROGRAM_NAME + "\n\n"
global startstatus
startstatus = 1
if startstatus == 1:
logga("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
logga ( "Start " + PROGRAM_NAME )
# lettura file configurazione
# [id]
# idxMacchina = 2001
# [time]
# SAMPLETIME = 0.1
# TIMEOUTSHORT = 200
# TIMEOUTLONG = 6000
print ( ' idxMacchina = %s' % ( idxMacchina ) )
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 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()
#---------------------------------------------------------------
# ciclo forever and ever
old = ''
while 1:
try:
time.sleep (SAMPLETIME)
except:
logga("First_SLEEP: errore attesa sampletime")
# lettura dati da IOB
value = readParallela()
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
+530
View File
@@ -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
+363
View File
@@ -0,0 +1,363 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#---------------------------------------------------------------
import serial
import time
import sys
import datetime
import urllib
import ConfigParser
import os, sys
#---------------------------------------------------------------
# COSTANTI
MSGLEN = 9
TIMEOUTSERIALE = 10
MAXRETRY = 3
# DA FILE CONF
idxMacchina = "2001"
SAMPLETIME = 0.1
TIMEOUTSHORT = (SAMPLETIME*20)
TIMEOUTLONG = (SAMPLETIME*600)
# VAR
to_enable = False
to_short = TIMEOUTSHORT
to_long = TIMEOUTLONG
to_serial = TIMEOUTSERIALE
to_retry = MAXRETRY
errormsglen = 0
#---------------------------------------------------------------
# classe logger
class Logger:
def __init__(self, filename):
try:
self.filename = filename
except:
logga("LOGGER: errore try su self.filename")
sys.exit(1)
def __call__(self, string):
try:
file = open(self.filename, 'a')
file.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + '] ')
file.write(string + '\n')
file.close()
except:
logga("LOGGER: errore try su scrittura")
sys.exit(1)
#---------------------------------------------------------------
# lettura buffer seriale e pulizia caratteri non stampabili
# ritorna '' se non c'è un messaggio buono o il messaggio pulito ( due bytes hex )
# il messaggio ha il formato xx<ACK>i00 00<CR><LF>xxx
def readSeriale():
global to_serial
global to_retry
global errormsglen
ret = ''
current = ''
i = 0
# ritorna '' se non ci sono abbastanza caratteri
try:
if ser.inWaiting() < MSGLEN :
#
# to_serial = to_serial - 1 # se non mi risponde, faccio un ' altra richiesta....
# if to_serial <= 0:
# try:
# requestData ()
# except:
# logga("SERIALE: errore su requestData")
# sys.exit(1)
# to_serial = TIMEOUTSERIALE # ripristino timer
# to_retry = to_retry - 1 # contatore retry
# if to_retry <= 0:
# logga ( 'IOB not responding' )
# return ret
logga("SERIALE: errore msglen < 9 char - Errore no. " + str(errormsglen))
errormsglen = errormsglen +1
avviaSeriale()
time.sleep(.2)
if errormsglen > 30:
sys.exit(1)
except:
if startstatus == 0:
logga ("Porta SERIALE non disponibile - ser.inWaiting error - exit... - Errore no. " + str(errormsglen))
errormsglen = errormsglen +1
avviaSeriale()
time.sleep(.2)
if errormsglen > 30:
sys.exit(1)
# finchè c'è robba .. leggi e tieni i buoni
to_serial = TIMEOUTSERIALE
to_retry = MAXRETRY
try:
while ser.inWaiting() > 0 :
try:
c = ser.read(1)
except:
logga("SERIALE: errore su try ser.read")
sys.exit(1)
# filtra caratteri non stampabili
if c > ' ' :
current += c
#sys.stdout.write(current + '<<<<\n')
# ora il messaggio ha il formato xxxxxi00 00xxx : cerco la 'i' iniziale
try:
while i < len(current) and current[i] != 'i':
i = i + 1
except:
logga("SERIALE: errore su ricerca i iniziale")
sys.exit(1)
# se non ho trovato la 'i' restituisco ''
if i == len(current)-1:
return ret
else:
current = current[i+1:i+3]
# richiesta dati ad IOB
requestData()
#sys.stdout.write ( current + '\n')
except:
if startstatus == 0:
logga ('Porta SERIALE non disponibile - ser.inWaiting e filtraggio error...exit')
sys.exit(1)
return current
#---------------------------------------------------------------
# richiesta dati ad IOB : scrittura su seriale
def requestData ():
try :
ser.write ("$i" + '\r\n')
ser.flush()
except :
if startstatus == 0:
logga ( "SERIAL: Errore di scrittura/flush")
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLBASE + idxMacchina + URLADV1 + value
urllib.urlopen ( url )
except:
logga ( "NETWORK:Errore http-no com rete-timeout" + url )
#---------------------------------------------------------------
# Funzione che verifica possibilità di creare log e include testo corrente
def logga(message) :
try:
log(message)
except :
pass
#---------------------------------------------------------------
def avviaSeriale():
global ser
try:
ser = serial.Serial(
port = comm_port ,
baudrate = 9600 ,
parity = serial.PARITY_NONE ,
stopbits = serial.STOPBITS_ONE ,
bytesize = serial.EIGHTBITS
)
startstatus = 0
except serial.serialutil.SerialException , e :
try:
if startstatus == 0:
logga ( "SERIAL:Errore apertura seriale - " + comm_port)
except:
pass
sys.stdout.write ( '\nErrore apertura seriale\n\n%s\n\n' % e )
if errormsglen > 30:
sys.exit (1)
#---------------------------------------------------------------
#---------------------------------------------------------------
# MAIN
try:
config = ConfigParser.RawConfigParser()
config.read ( 'readSeriale.cfg' )
SAMPLETIME = config.getfloat ( 'time' , 'SAMPLETIME' )
TIMEOUTSHORT = config.getfloat ( 'time' , 'TIMEOUTSHORT' )
TIMEOUTLONG = config.getfloat ( 'time' , 'TIMEOUTLONG' )
idxMacchina = config.get ( 'id' , 'idxMacchina' )
comm_port = config.get ( 'comm' , 'port' )
URLBASE = config.get ( 'web' , 'URLBASE' )
URLADV1 = config.get ( 'web' , 'URLADV1' )
LOGFILE = config.get ( 'log' , 'LOGFILE' )
LOGLEVEL = config.get ( 'log' , 'LOGLEVEL' )
except:
sys.exit(1)
# oggetto Logger
try:
log = Logger(LOGFILE)
except:
# manda mail o simili - FARE!!!
print "LOG: Impossibile creare file log con nome "
print (LOGFILE)
print '\n\n Read seriale IOB v.0.2 !!!!\n'
global startstatus
startstatus = 1
if startstatus == 1:
logga("Avvio Programma")
# Verifica l'OS e di conseguenza carica il file relativo con metodo di lockfile appropriato + check singola istanza
if os.name == 'posix':
import unix
else:
import win
logga ( "Start Read seriale IOB v.0.2")
# lettura file configurazione
# [comm]
# port = /dev/ttyS0
# [id]
# idxMacchina = 2001
# [time]
# SAMPLETIME = 0.1
# TIMEOUTSHORT = 200
# TIMEOUTLONG = 6000
print ( ' comm_port = %s' % ( comm_port ) )
print ( ' idxMacchina = %s' % ( idxMacchina ) )
print ( ' SAMPLETIME = %4.2f' % ( SAMPLETIME ) )
print ( ' TIMEOUTSHORT = %4.2f' % ( TIMEOUTSHORT ) )
print ( ' TIMEOUTLONG = %4.2f' % ( TIMEOUTLONG ) )
print ( ' URLBASE = %s' % ( URLBASE ) )
print ( ' URLADV1 = %s' % ( URLADV1 ) )
print ( ' LOGFILE = %s' % ( LOGFILE ) )
print ( ' LOGLEVEL = %s' % ( LOGLEVEL ) )
# -sys.stdout.write ( 'idxMacchina ?' + idxMacchina + '\n')
to_short = TIMEOUTSHORT
to_long = TIMEOUTLONG
#--------------------------------------------------------------
#---------------------------------------------------------------
# apertura seriale
avviaSeriale()
#try:
# ser = serial.Serial(
# port = comm_port ,
# baudrate = 9600 ,
# parity = serial.PARITY_NONE ,
# stopbits = serial.STOPBITS_ONE ,
# bytesize = serial.EIGHTBITS
# )
# print "Initialized!"
#except serial.serialutil.SerialException , e :
# try:
# logga ( "SERIAL:Errore apertura seriale - " + comm_port)
# except:
# pass
# sys.stdout.write ( '\nErrore apertura seriale\n\n%s\n\n' % e )
# sys.exit (1)
#---------------------------------------------------------------
# ciclo forever and ever
old = ''
# richiesta dati ad IOB
try:
requestData()
except:
logga("SERIALE: errore sul try di requestData")
sys.exit(1)
while 1:
try:
time.sleep (SAMPLETIME)
except:
logga("SERIALE_SLEEP: errore attesa sampletime")
# lettura dati da IOB
try:
value = readSeriale()
except:
if startstatus == 0:
logga("errore PRIMA LETTURA SERIALE")
sys.exit(1)
if ( value != '' ) :
if value != old :
#loggo e invio dati
try:
logga ( value )
errormsglen = 0
chiamaUrl()
except:
logga("URLBROWSER: errore registrazione valore e chiamaUrl")
pass
#enable e reset timer
to_enable = True
to_short = TIMEOUTSHORT
to_long = TIMEOUTLONG
old = value
# gestione timeout breve
if ( to_enable ) :
to_short = to_short - SAMPLETIME
if to_short <= 0:
#loggo e invio dati
try:
logga ( '>' + value )
errormsglen = 0
chiamaUrl()
except:
pass
to_short = TIMEOUTSHORT
to_enable = False # dopo un colpo il timer breve viene disabilitato
to_long = TIMEOUTLONG
# gestione timeout lungo
to_long = to_long - SAMPLETIME
if to_long <= 0:
#loggo e invio dati
try:
logga ( '>>' + value )
errormsglen = 0
chiamaUrl()
except:
pass
to_long = TIMEOUTLONG
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sendReboot v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
import logging
#---------------------------------------------------------------
# COSTANTI
PROGRAM_NAME ="SendReboot IOB-pi v.1.3"
# DA FILE CONF
idxMacchina = "99"
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLREBO + idxMacchina
urllib.urlopen ( url )
except:
logging.info ( "NETWORK:Errore http-no com rete-timeout per url: " + url )
print "Url aforte" , url
#---------------------------------------------------------------
# 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 ) )
chiamaUrl()
+31
View File
@@ -0,0 +1,31 @@
import fcntl
import os
import logging
#---------------------------------------------------------------
# meccanismo di file lock per evitare multiple instances
# The function will try to lock the file specified , if it success, return True, else return False.
# The nice thing is that the lock will be dropped when the program terminates.
# >>>Use :
# if not lockFile(".lock.pod"):
# sys.exit(0)
def lockFile ( lockfile ) :
fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY )
try:
# Request exclusive (EX) non-blocking (NB) advisory lock.
fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB )
except IOError:
return False
return True
if not lockFile ( ".lockfile" ) :
print '\n noi non siamo soli ...\n'
logging.error( "LOCK: Piu istanze aperte")
#sys.exit ( 0 )
#- print '\n running alone ...\n'
+23
View File
@@ -0,0 +1,23 @@
[id]
idxMacchina = 1010
[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.20
TIMEOUTSHORT = 0.30
TIMEOUTLONG = 50
SENDURLTIME = 0.50
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
LOGREBO = logReboot.txt
[comm]
port = /dev/ttyAMA0
+41
View File
@@ -0,0 +1,41 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start: $remote_fs $syslog ramlog
# Required-Stop: $remote_fs $syslog ramlog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Steamware's MapoIOB driver
# Description: Steamware's MapoIOB driver, versione lettura porta parallela
### END INIT INFO
#! /bin/sh
# /etc/init.d/MapoIOB
export HOME
case "$1" in
start)
echo "Starting readParallela"
cd /home/pi/steamware
/usr/bin/python ./readParallela.py 2>&1 &
;;
stop)
echo "Stopping readParallela"
RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'`
kill -9 $RS_PID
cd /home/pi/steamware
rm .lockfile
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
killall python
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia!
DATE=`date +%Y-%m-%d`
cd /var/log
if [ -f MapoIOB ]
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
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
DATE=`date +%Y-%m-%d_%T`
# log inizio pulizia
echo $DATE " - INIZIO pulizia processi python" >> clean.log
# effettua pulizia processi: killa tutti i processi python
killall python
# avvia MapoIob
/etc/init.d/MapoIOB start
# log fatto!
DATE=`date +%Y-%m-%d_%T`
echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
[id]
idxMacchina = 1010
[web]
URLBASE = http://192.168.51.71/MPIO/inputIOB.aspx?idxMacchina=
URLADV1 = &valore=
URLREBO = http://192.168.51.71/MPIO/sendReboot.aspx?idxMacchina=
[time]
SAMPLETIME = 0.5
TIMEOUTSHORT = 2
TIMEOUTLONG = 60
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
[comm]
port = /dev/ttyAMA0
+337
View File
@@ -0,0 +1,337 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# readParallela v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
#---------------------------------------------------------------
# COSTANTI
MSGLEN = 9
TIMEOUTSERIALE = 10
MAXRETRY = 3
PROGRAM_NAME ="ReadPar IOB-pi v.1.1"
# DA FILE CONF
idxMacchina = "1001"
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
# 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
#---------------------------------------------------------------
# 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 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
##### convertire in HEX !!!!
except:
pass
return current
#---------------------------------------------------------------
#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 )
print "Url aforte" , url
#---------------------------------------------------------------
# Funzione che verifica possibilità di creare log e include testo corrente
def logga(message) :
try:
log(message)
except :
pass
#---------------------------------------------------------------
def avviaParallela():
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' )
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)
# 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" + PROGRAM_NAME + "\n\n"
global startstatus
startstatus = 1
if startstatus == 1:
logga("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
logga ( "Start " + PROGRAM_NAME )
# lettura file configurazione
# [id]
# idxMacchina = 2001
# [time]
# SAMPLETIME = 0.1
# TIMEOUTSHORT = 200
# TIMEOUTLONG = 6000
print ( ' idxMacchina = %s' % ( idxMacchina ) )
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 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()
#---------------------------------------------------------------
# ciclo forever and ever
old = ''
while 1:
try:
time.sleep (SAMPLETIME)
except:
logga("First_SLEEP: errore attesa sampletime")
# lettura dati da IOB
value = readParallela()
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
+530
View File
@@ -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
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sendReboot v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
import logging
#---------------------------------------------------------------
# COSTANTI
PROGRAM_NAME ="SendReboot IOB-pi v.1.3"
# DA FILE CONF
idxMacchina = "99"
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLREBO + idxMacchina
urllib.urlopen ( url )
except:
logging.info ( "NETWORK:Errore http-no com rete-timeout per url: " + url )
print "Url aforte" , url
#---------------------------------------------------------------
# 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 ) )
chiamaUrl()
+31
View File
@@ -0,0 +1,31 @@
import fcntl
import os
import logging
#---------------------------------------------------------------
# meccanismo di file lock per evitare multiple instances
# The function will try to lock the file specified , if it success, return True, else return False.
# The nice thing is that the lock will be dropped when the program terminates.
# >>>Use :
# if not lockFile(".lock.pod"):
# sys.exit(0)
def lockFile ( lockfile ) :
fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY )
try:
# Request exclusive (EX) non-blocking (NB) advisory lock.
fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB )
except IOError:
return False
return True
if not lockFile ( ".lockfile" ) :
print '\n noi non siamo soli ...\n'
logging.error( "LOCK: Piu istanze aperte")
#sys.exit ( 0 )
#- print '\n running alone ...\n'
+23
View File
@@ -0,0 +1,23 @@
[id]
idxMacchina = 1011
[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.20
TIMEOUTSHORT = 0.30
TIMEOUTLONG = 50
SENDURLTIME = 0.50
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
LOGREBO = logReboot.txt
[comm]
port = /dev/ttyAMA0
+41
View File
@@ -0,0 +1,41 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start: $remote_fs $syslog ramlog
# Required-Stop: $remote_fs $syslog ramlog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Steamware's MapoIOB driver
# Description: Steamware's MapoIOB driver, versione lettura porta parallela
### END INIT INFO
#! /bin/sh
# /etc/init.d/MapoIOB
export HOME
case "$1" in
start)
echo "Starting readParallela"
cd /home/pi/steamware
/usr/bin/python ./readParallela.py 2>&1 &
;;
stop)
echo "Stopping readParallela"
RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'`
kill -9 $RS_PID
cd /home/pi/steamware
rm .lockfile
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
killall python
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia!
DATE=`date +%Y-%m-%d`
cd /var/log
if [ -f MapoIOB ]
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
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
DATE=`date +%Y-%m-%d_%T`
# log inizio pulizia
echo $DATE " - INIZIO pulizia processi python" >> clean.log
# effettua pulizia processi: killa tutti i processi python
killall python
# avvia MapoIob
/etc/init.d/MapoIOB start
# log fatto!
DATE=`date +%Y-%m-%d_%T`
echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
[id]
idxMacchina = 1011
[web]
URLBASE = http://192.168.51.71/MPIO/inputIOB.aspx?idxMacchina=
URLADV1 = &valore=
URLREBO = http://192.168.51.71/MPIO/sendReboot.aspx?idxMacchina=
[time]
SAMPLETIME = 0.5
TIMEOUTSHORT = 2
TIMEOUTLONG = 60
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
[comm]
port = /dev/ttyAMA0
+337
View File
@@ -0,0 +1,337 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# readParallela v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
#---------------------------------------------------------------
# COSTANTI
MSGLEN = 9
TIMEOUTSERIALE = 10
MAXRETRY = 3
PROGRAM_NAME ="ReadPar IOB-pi v.1.1"
# DA FILE CONF
idxMacchina = "1001"
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
# 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
#---------------------------------------------------------------
# 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 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
##### convertire in HEX !!!!
except:
pass
return current
#---------------------------------------------------------------
#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 )
print "Url aforte" , url
#---------------------------------------------------------------
# Funzione che verifica possibilità di creare log e include testo corrente
def logga(message) :
try:
log(message)
except :
pass
#---------------------------------------------------------------
def avviaParallela():
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' )
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)
# 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" + PROGRAM_NAME + "\n\n"
global startstatus
startstatus = 1
if startstatus == 1:
logga("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
logga ( "Start " + PROGRAM_NAME )
# lettura file configurazione
# [id]
# idxMacchina = 2001
# [time]
# SAMPLETIME = 0.1
# TIMEOUTSHORT = 200
# TIMEOUTLONG = 6000
print ( ' idxMacchina = %s' % ( idxMacchina ) )
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 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()
#---------------------------------------------------------------
# ciclo forever and ever
old = ''
while 1:
try:
time.sleep (SAMPLETIME)
except:
logga("First_SLEEP: errore attesa sampletime")
# lettura dati da IOB
value = readParallela()
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
+530
View File
@@ -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
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sendReboot v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
import logging
#---------------------------------------------------------------
# COSTANTI
PROGRAM_NAME ="SendReboot IOB-pi v.1.3"
# DA FILE CONF
idxMacchina = "99"
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLREBO + idxMacchina
urllib.urlopen ( url )
except:
logging.info ( "NETWORK:Errore http-no com rete-timeout per url: " + url )
print "Url aforte" , url
#---------------------------------------------------------------
# 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 ) )
chiamaUrl()
+31
View File
@@ -0,0 +1,31 @@
import fcntl
import os
import logging
#---------------------------------------------------------------
# meccanismo di file lock per evitare multiple instances
# The function will try to lock the file specified , if it success, return True, else return False.
# The nice thing is that the lock will be dropped when the program terminates.
# >>>Use :
# if not lockFile(".lock.pod"):
# sys.exit(0)
def lockFile ( lockfile ) :
fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY )
try:
# Request exclusive (EX) non-blocking (NB) advisory lock.
fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB )
except IOError:
return False
return True
if not lockFile ( ".lockfile" ) :
print '\n noi non siamo soli ...\n'
logging.error( "LOCK: Piu istanze aperte")
#sys.exit ( 0 )
#- print '\n running alone ...\n'
+23
View File
@@ -0,0 +1,23 @@
[id]
idxMacchina = 1012
[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.20
TIMEOUTSHORT = 0.30
TIMEOUTLONG = 50
SENDURLTIME = 0.50
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
LOGREBO = logReboot.txt
[comm]
port = /dev/ttyAMA0
+41
View File
@@ -0,0 +1,41 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start: $remote_fs $syslog ramlog
# Required-Stop: $remote_fs $syslog ramlog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Steamware's MapoIOB driver
# Description: Steamware's MapoIOB driver, versione lettura porta parallela
### END INIT INFO
#! /bin/sh
# /etc/init.d/MapoIOB
export HOME
case "$1" in
start)
echo "Starting readParallela"
cd /home/pi/steamware
/usr/bin/python ./readParallela.py 2>&1 &
;;
stop)
echo "Stopping readParallela"
RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'`
kill -9 $RS_PID
cd /home/pi/steamware
rm .lockfile
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
killall python
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia!
DATE=`date +%Y-%m-%d`
cd /var/log
if [ -f MapoIOB ]
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
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
DATE=`date +%Y-%m-%d_%T`
# log inizio pulizia
echo $DATE " - INIZIO pulizia processi python" >> clean.log
# effettua pulizia processi: killa tutti i processi python
killall python
# avvia MapoIob
/etc/init.d/MapoIOB start
# log fatto!
DATE=`date +%Y-%m-%d_%T`
echo $DATE " - FINE pulizia processi python + riavvio MapoIOB" >> clean.log
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+530
View File
@@ -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
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# sendReboot v. 1.1
#---------------------------------------------------------------
import time
import sys
from datetime import datetime
import urllib
import ConfigParser
import os, sys
import logging
#---------------------------------------------------------------
# COSTANTI
PROGRAM_NAME ="SendReboot IOB-pi v.1.3"
# DA FILE CONF
idxMacchina = "99"
#---------------------------------------------------------------
#Funzione di scrittura su url con try-except
def chiamaUrl():
try:
url = URLREBO + idxMacchina
urllib.urlopen ( url )
except:
logging.info ( "NETWORK:Errore http-no com rete-timeout per url: " + url )
print "Url aforte" , url
#---------------------------------------------------------------
# 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 ) )
chiamaUrl()
+31
View File
@@ -0,0 +1,31 @@
import fcntl
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 ) :
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'
logga ( "LOCK: Piu istanze aperte")
sys.exit ( 0 )
#- print '\n running alone ...\n'
+23
View File
@@ -0,0 +1,23 @@
[id]
idxMacchina = 1013
[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.20
TIMEOUTSHORT = 0.30
TIMEOUTLONG = 50
SENDURLTIME = 0.50
[log]
LOGLEVEL = 10
LOGFILE = logfile.txt
LOGREBO = logReboot.txt
[comm]
port = /dev/ttyAMA0
+41
View File
@@ -0,0 +1,41 @@
### BEGIN INIT INFO
# Provides: MapoIOB: script Steamware per avvio driver IOB
# Required-Start: $remote_fs $syslog ramlog
# Required-Stop: $remote_fs $syslog ramlog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Steamware's MapoIOB driver
# Description: Steamware's MapoIOB driver, versione lettura porta parallela
### END INIT INFO
#! /bin/sh
# /etc/init.d/MapoIOB
export HOME
case "$1" in
start)
echo "Starting readParallela"
cd /home/pi/steamware
/usr/bin/python ./readParallela.py 2>&1 &
;;
stop)
echo "Stopping readParallela"
RS_PID=`ps auxwww | grep readParallela.py | head -1 | awk '{print $2}'`
kill -9 $RS_PID
cd /home/pi/steamware
rm .lockfile
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
killall python
$0 start
;;
*)
echo "Usage: /etc/init.d/MapoIOB {start|stop|restart}"
exit 1
;;
esac
exit 0
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# controlla se il logfile è correntemente scritto (quindi MapoIOB è alive) altrimenti riavvia!
DATE=`date +%Y-%m-%d`
cd /var/log
if [ -f MapoIOB ]
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

Some files were not shown because too many files have changed in this diff Show More