-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2sendmsg.py
65 lines (46 loc) · 1.28 KB
/
2sendmsg.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import RPi.GPIO as GPIO
import time
import serial
import MySQLdb #for farmer's contact no.
db=MySQLdb.connect("localhost", "alka", "root", "group13") #cinfo is username, new is database name
port=serial.Serial("/dev/ttyS0",9600,timeout=3.0)
cur=db.cursor()
GPIO.setmode(GPIO.BCM)
pir=23 #pin no. 16
GPIO.setup(pir,GPIO.IN)
while True:
if GPIO.input(pir):
print "\n"
print"INTRUDER DETECTED!!!!!"
print "\n"
try:
port=serial.Serial("/dev/ttyS0",9600,timeout=3.0)
print "GSM SIM9600\n"
print "OK"
#print"AT to check operation"
port.write('AT\r\n')
rcv=port.read(20)
#print"GSM Working:"+rcv
rcv=port.read(20)
cur.execute("SELECT phoneNum FROM contact")
for row in cur.fetchall():
number=str(row[0]) #row=no of attributes
msg1="SOMEONE JUST ENTERED THE FARM"
print"message passed to the farmer"
port.write('AT+CMGS="'+number+'"\r\n')
time.sleep(1)
port.flushInput()
port.flushOutput()
port.write(msg1)
time.sleep(1)
port.write('\x1A\r\n')
#print port.read(50)
port.flushInput()
port.flushOutput()
exit(0)
except:
port.close()
time.sleep(1)
else:
print"no motion"
time.sleep(1)