import json, time, requests
from boltiot import Sms, Bolt
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
email = ''
password = ''
send_to_email = ' '
subject = 'intrusion'
message = 'Someone Entered !!'
msg = MIMEMultipart()
msg['From'] = email
msg['To'] = send_to_email
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
SID=" "
AUTH_TOKEN=" "
FROM_NUMBER=" "
TO_NUMBER=" "
sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)
while True:
response = requests.get('http://cloud.boltiot.com/remote/e0f2449f-c1b0-483c-8bd8-f4ba5fc32a89/digitalRead?pin=0&deviceName=BOLT6094123')
data=json.loads(response.text)
print(data)
sensor_value = int(data['value'])
if sensor_value == 1:
print("MOTION DETECTED")
print("sending SMS")
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email, password)
text = msg.as_string()
server.sendmail(email, send_to_email, text)
sms.send_sms("SOMEONE ENTERED")
server.quit()
elif sensor_value ==0:
print("SENSOR IS READY")
time.sleep(5)
Comments
Please log in or sign up to comment.