Commit 8fd1c0e2 authored by Fardale's avatar Fardale

Mel imprimante est débranché ou plus de papier

parent d1ef6493
......@@ -3,11 +3,16 @@
from __future__ import print_function
import sys,os,pwd,grp
# Bad namming: change namming
from AdafruitThermal import Adafruit_Thermal as AdafruitThermal
import common
import pika
import json
import dump
import config
import threading, time, smtplib
from email.mime.text import MIMEText
from config import DEVICE
def run():
conn = pika.BlockingConnection(config.PARAMS)
......@@ -22,9 +27,60 @@ def run():
conn.close()
# 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 '-fg' in sys.argv:
thHasPaper = threading.Thread(target = checkPaper, name = 'checkPaper')
thHasPaper.start()
run()
exit()
# 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)
sys.exit(1)
# start the daemon main loop
# start the daemon thread
thHasPaper = threading.Thread(target = checkPaper, name = 'checkPaper')
thHasPaper.start()
#main loop
run()
Retour du papier !
Le sain papier est de retour, loue soit il !
--
Oison
Help !!!
Gentils cableurs, je n'ai plus de papier.
--
Oison
Le courant est revenue !
Merci de m'avoir branche.
--
Oison
Help !!!
Gentils cableurs derriere le bar, rebranchez moi, please !
--
Oison
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment