Ashir Mehta
Published © GPL3+

Temperature Intrusion Detection System

The purpose of the project is to determine whether the anomaly is due to some human error or due to the intruder trying to access it.

BeginnerShowcase (no instructions)2 hours556
Temperature Intrusion Detection System

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LM35 Temperature Sensor
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Digital Ocean
SMS Messaging API
Twilio SMS Messaging API
Mailgun Email

Story

Read more

Code

conf.py

Python
This file contains the configuration of Bolt, Twilio, Mailgun for the working of the project.
SSID = 'SSID' #You can find SID in Twilio Dashboard
AUTH_TOKEN = 'TOKEN' #You can find TOKEN in Twilio Dashboard
MAILGUN_API_KEY = 'API_KEY' #This API key will be on yourMailgun Dashboard
SANDBOX_URL = ' sandboxurl.mailgun.org' #You can find this on Mailgun Dashboard
SENDER_EMAIL = 'test@sandboxurl.mailgun.org' #test@your SANDBOX_URL
RECIPIENT_EMAIL = 'abc@gmail.com' #Enter your Email ID Here
FROM_NUMBER = '+1XXXXXXXXXX' #No. generated by Twilio.
TO_NUMBER = '+91XXXXXXXXXX' #Enter your Number Here
API_KEY = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' #Your BOlT API KEY
DEVICE_ID = 'BOLTXXXXXX' #YOUR BOLT DEVICE ID

lm_sms.py

Python
This is the file that contains the code for the detection of the anomaly and requests for the alert.
import conf
from boltiot import Sms, Bolt, Email
import json, time
from datetime import datetime
import pytz

L = []
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)

def Average(L):
        return sum(L) / len(L)
def buzzeron():
        output = mybolt.analogWrite('0','100');
        return output

def buzzon():
        output = mybolt.analogWrite('0','255');
        return output
def buzzeroff():
        output = mybolt.digitalWrite("0","LOW")
        return output

while True:
        response = mybolt.analogRead('A0')
        data = json.loads(response)
        try:

                sensor_value = int(data['value'])
                T = sensor_value/10.24
                print("The Tempreture inside is : " ,T)
                L.append(T)
                average = Average(L)
                if( len(L) >= 2 ):
                        if( (T > (average + 0.20)) and (T < (average + 0.30)) ):
                                print("STAGE 01 ANOMALY : " , T)
                                print("Making request to Mailgun to send email")
                                response = mailer.send_email("Alert", "Looks like door of Refrigerator is open Please close the door"  + str(T) )
                                response_text = json.loads(response.text)
                                print("Response received from MAILGUN is : " + str(response_text['message']))
                                buzzeron()
                                time.sleep(5)
                                buzzeroff()
                                tz_IN = pytz.timezone('Asia/Kolkata')
				datetime_IN = datetime.now(tz_IN)
                                print("Door is Open since :", datetime_IN.strftime("%H:%M:%S"))
                                break
                        elif( (T > (average + 0.30  )) ):
                                print("STAGE 02 ANOMALY  : " , T)
                                print("Making request to Twilio to send SMS")
                                response = sms.send_sms("Someone Has Opened the Door: " +str(T))
                                print("Response received from Twilio : " +str(response))
                                print("Status of SMS at Twilio : " +str(response.status))
                                buzzon()
                                time.sleep(5)
                                buzzeroff()
                                tz_IN = pytz.timezone('Asia/Kolkata')
                                datetime_IN = datetime.now(tz_IN)
                                print("Someone Opened the door at : " , datetime_IN.strftime("%H:%M:%S"))
                                break
        except Exception as e:
                print(e)
        time.sleep(1)

Credits

Ashir Mehta

Ashir Mehta

1 project • 1 follower

Comments