Mel imprimante est débranché ou plus de papier
This commit is contained in:
parent
d1ef64937f
commit
8fd1c0e272
5 changed files with 84 additions and 1 deletions
61
daemon.py
61
daemon.py
|
@ -3,11 +3,16 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,pwd,grp
|
import sys,os,pwd,grp
|
||||||
|
# Bad namming: change namming
|
||||||
|
from AdafruitThermal import Adafruit_Thermal as AdafruitThermal
|
||||||
import common
|
import common
|
||||||
import pika
|
import pika
|
||||||
import json
|
import json
|
||||||
import dump
|
import dump
|
||||||
import config
|
import config
|
||||||
|
import threading, time, smtplib
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from config import DEVICE
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
conn = pika.BlockingConnection(config.PARAMS)
|
conn = pika.BlockingConnection(config.PARAMS)
|
||||||
|
@ -22,9 +27,60 @@ def run():
|
||||||
conn.close()
|
conn.close()
|
||||||
# fork en arrière plan + pidfile
|
# fork en arrière plan + pidfile
|
||||||
|
|
||||||
|
def checkPaper():
|
||||||
|
printer = AdafruitThermal(DEVICE, 19200, timeout=5)
|
||||||
|
messageCourant = False
|
||||||
|
messagePapier = False
|
||||||
|
|
||||||
|
def sendMel(msgfile, etat):
|
||||||
|
fp = open(msgfile, 'rb')
|
||||||
|
# Create a text/plain message
|
||||||
|
msg = MIMEText(fp.read())
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
# me == the sender's email address
|
||||||
|
# you == the recipient's email address
|
||||||
|
msg['Subject'] = '''Etat de l'imprimante thermique : %s''' % etat
|
||||||
|
msg['From'] = 'oison@crans.org'
|
||||||
|
msg['To'] = 'arrighi@crans.org'
|
||||||
|
|
||||||
|
# Send the message via our own SMTP server, but don't include the
|
||||||
|
# envelope header.
|
||||||
|
s = smtplib.SMTP('smtp.crans.org', 25)
|
||||||
|
s.sendmail('oison@crans.org', ['arrighi@crans.org'], msg.as_string())
|
||||||
|
s.quit()
|
||||||
|
|
||||||
|
def checkPrinter(dejaVu, messageCourant, messagePapier):
|
||||||
|
try:
|
||||||
|
papier = printer.hasPaper()
|
||||||
|
if messageCourant:
|
||||||
|
sendMel('melSecteur', 'alimentation')
|
||||||
|
messageCourant = False
|
||||||
|
else:
|
||||||
|
if not (messagePapier or papier):
|
||||||
|
sendMel('melPasPapier', 'papier')
|
||||||
|
messagePapier = True
|
||||||
|
if messagePapier and papier:
|
||||||
|
sendMel('melPapier', 'papier')
|
||||||
|
messagePapier = False
|
||||||
|
except TypeError:
|
||||||
|
if not messageCourant:
|
||||||
|
if dejaVu:
|
||||||
|
sendMel('melSurBatterie', 'alimentation')
|
||||||
|
messageCourant = True
|
||||||
|
else:
|
||||||
|
time.sleep(600)
|
||||||
|
messageCourant, messagePapier = checkPrinter(True, messageCourant, messagePapier)
|
||||||
|
return messageCourant, messagePapier
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(60)
|
||||||
|
messageCourant, messagePapier = checkPrinter(False, messageCourant, messagePapier)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if '-fg' in sys.argv:
|
if '-fg' in sys.argv:
|
||||||
|
thHasPaper = threading.Thread(target = checkPaper, name = 'checkPaper')
|
||||||
|
thHasPaper.start()
|
||||||
run()
|
run()
|
||||||
exit()
|
exit()
|
||||||
# do the UNIX double-fork magic, see Stevens' "Advanced
|
# do the UNIX double-fork magic, see Stevens' "Advanced
|
||||||
|
@ -55,6 +111,9 @@ if __name__ == "__main__":
|
||||||
print("fork #2 failed: %d (%s)" % (e.errno, e.strerror),file=sys.stderr)
|
print("fork #2 failed: %d (%s)" % (e.errno, e.strerror),file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# start the daemon main loop
|
# start the daemon thread
|
||||||
|
thHasPaper = threading.Thread(target = checkPaper, name = 'checkPaper')
|
||||||
|
thHasPaper.start()
|
||||||
|
#main loop
|
||||||
run()
|
run()
|
||||||
|
|
||||||
|
|
6
melPapier
Normal file
6
melPapier
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Retour du papier !
|
||||||
|
|
||||||
|
Le sain papier est de retour, loue soit il !
|
||||||
|
|
||||||
|
--
|
||||||
|
Oison
|
6
melPasPapier
Normal file
6
melPasPapier
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Help !!!
|
||||||
|
|
||||||
|
Gentils cableurs, je n'ai plus de papier.
|
||||||
|
|
||||||
|
--
|
||||||
|
Oison
|
6
melSecteur
Normal file
6
melSecteur
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Le courant est revenue !
|
||||||
|
|
||||||
|
Merci de m'avoir branche.
|
||||||
|
|
||||||
|
--
|
||||||
|
Oison
|
6
melSurBatterie
Normal file
6
melSurBatterie
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Help !!!
|
||||||
|
|
||||||
|
Gentils cableurs derriere le bar, rebranchez moi, please !
|
||||||
|
|
||||||
|
--
|
||||||
|
Oison
|
Loading…
Add table
Add a link
Reference in a new issue