forked from adammck/pygsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
executable file
·43 lines (29 loc) · 953 Bytes
/
demo.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
40
41
42
43
#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
# see LICENSE file (it's BSD)
import time
from pygsm import GsmModem
class CountLettersApp(object):
def __init__(self, modem):
self.modem = modem
def incoming(self, msg):
msg.respond("Thanks for those %d characters!" %\
len(msg.text))
def serve_forever(self):
while True:
print "Checking for message..."
msg = self.modem.next_message()
if msg is not None:
print "Got Message: %r" % (msg)
self.incoming(msg)
time.sleep(2)
# all arguments to GsmModem.__init__ are optional, and passed straight
# along to pySerial. for many devices, this will be enough:
gsm = GsmModem(
port="/dev/ttyUSB0",
logger=GsmModem.debug_logger).boot()
print "Waiting for network..."
s = gsm.wait_for_network()
# start the demo app
app = CountLettersApp(gsm)
app.serve_forever()