-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplecode.py
More file actions
45 lines (32 loc) · 874 Bytes
/
simplecode.py
File metadata and controls
45 lines (32 loc) · 874 Bytes
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
44
45
#!/usr/bin/env python
import time
from pygsm import GsmModem
import RPi.GPIO as GPIO
#set pin12 to output
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
class SwitchLED(object):
def __init__(self, modem):
self.modem = modem
def incoming(self, msg):
if msg=="on":
GPIO.output(12, GPIO.HIGH) #switch on the led
elif msg=="off":
GPIO.output(12, GPIO.LOW) #switch off the led
else:
msg.respond("worong command use on or off")
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)
DRIVER="/dev/ttyUSB0"
gsm = GsmModem(port=DRIVER,baudrate=115200,logger=GsmModem.debug_logger).boot()
print "Waiting for network..."
s = gsm.wait_for_network()
# demo
app = SwitchLED(gsm)
app.serve_forever()