-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodem.py
39 lines (34 loc) · 1.31 KB
/
modem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from gsmmodem.modem import GsmModem
from gsmmodem.exceptions import TimeoutException
import threading
import time
import logging
import sys, traceback
class Modem(threading.Thread):
def __init__(self, smsq, device, *a,**kw):
self.modem = GsmModem(device,9600,dsrdtr=True,rtscts=True)
self.smsq = smsq
return super(Modem,self).__init__(*a,**kw)
def run(self):
while True:
try:
self.modem.connect()
except (TimeoutException,IOError) as e:
self.modem.close()
exc_type, exc_value, exc_traceback = sys.exc_info()
logging.debug(traceback.format_tb(exc_traceback))
time.sleep(10)
continue
try:
while True:
phone,text = self.smsq.get()
logging.debug(u'modem to {} text: {}'.format(phone,text))
sms = self.modem.sendSms(phone,text)
self.smsq.task_done()
time.sleep(10)
except Exception as e:
self.modem.close()
exc_type, exc_value, exc_traceback = sys.exc_info()
logging.error(type(e))
logging.error(e.message)
logging.debug(traceback.format_tb(exc_traceback))