PRACHI AGARWAL
Published © GPL3+

$m@rt_Refrigerator

Cool and easy way to check if someone has opened your fridge without your knowledge.

IntermediateShowcase (no instructions)5 hours2,200
$m@rt_Refrigerator

Things used in this project

Hardware components

Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Temperature Sensor
Temperature Sensor
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

SMS Messaging API
Twilio SMS Messaging API
mailgun
Bolt Cloud
Bolt IoT Bolt Cloud

Story

Read more

Schematics

ESP8266 set up

Code

conf

Python
This stores the configurations for receiving sms using twilio API.
These field values can be found in Twilio dashboard.
SSID='AC83a0446a145d########################'
AUTH_TOKEN='5386c4d########################'
FROM_NUMBER="+##########" # enter the mobile number generated using twilio
TO_NUMBER="##########"   # enter your mobile number

API_KEY="c5434250-5f81-##################"
DEVICE_ID="BOLT1115978" # enter your device id. Check bolt cloud dashboard
FRAME_SIZE=10
MUL_FACTOR=6

anomalydetection

Python
import conf,email_conf, json, time, math, statistics
from boltiot import Sms, Bolt,Email
def compute_bounds(history_data,frame_size,factor):
    if len(history_data)<frame_size :
        return None

    if len(history_data)>frame_size :
        del history_data[0:len(history_data)-frame_size]
    Mn=statistics.mean(history_data)
    Variance=0
    for data in history_data :
        Variance += math.pow((data-Mn),2)
    Zn = factor * math.sqrt(Variance / frame_size)
    High_bound = history_data[frame_size-1]+Zn
    Low_bound = history_data[frame_size-1]-Zn
    return [High_bound,Low_bound]

critical_limit = 20 #the critical_value of temperature
maximum_limit = 35 #the maximum_value of temperature
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOXURL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)
history_data=[]

while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    if data['success'] != 1:
        print("There was an error while retriving the data.")
        print("This is the error:"+data['value'])
        time.sleep(10)
        continue

    print ("This is the value "+data['value'])
    sensor_value=0
    try:
        sensor_value = int(data['value'])
    except e:
        print("There was an error while parsing the response: ",e)
        continue

    bound = compute_bounds(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)
    if not bound:
        required_data_count=conf.FRAME_SIZE-len(history_data)
        print("Not enough data to compute Z-score. Need ",required_data_count," more data points")
        history_data.append(int(data['value']))
        time.sleep(10)
        continue

    try:
        if sensor_value/10.24 > maximum_limit:
            print ("The Temperature value increased suddenly. Sending an sms.")
            # display the temeprature value in degree celsus
            print ("The Current temperature is: "+str(sensor_value/10.24)+" °C")
            response = sms.send_sms("Alert ! Someone has opened the fridge door")
            response1 = mailer.send_email("Alert !","The level temperature can destroy the tablets.")
        # condition for the temperature value is between  the critical_limit and the maximum_limit
        elif sensor_value/10.24 > critical_limit or sensor_value/10.24 < maximum_limit:
            print("Urgent! Temperature condition can destroy the tablets. Sending an email.")
            #display the temperature value in degree celsus
            print (" The Current temperature is:" +str(sensor_value/10.24)+ "°C")
            response = mailer.send_email("Alert !","The level temperature can destroy the tablets.")
            print("This is the response",response)
        history_data.append(sensor_value)
    except Exception as e:
            print ("Error",e)

    time.sleep(10)







	
	
	

email_conf

Python
This stores the required values of the fields.
MAILGUN_API_KEY = '######8f456b8ab626a######3271579-87cdd773-########' 
SANDBOXURL= 'sandbox#############################.mailgun.org' 
SENDER_EMAIL = 'test@sandbox########################.mailgun.org'
RECIPIENT_EMAIL = '201751034@iiitvadodara.ac.in' # enter your email 

API_KEY="c5434250-5f81-4eb7-########"
DEVICE_ID="BOLT1115978" # enter your bolt device id
FRAME_SIZE=10
MUL_FACTOR=6

	

predict

JavaScript
This is the code for prediction using Polynomial Regression.
/ *start typing your code here */


setChartLibrary('google-chart');
setChartTitle('Polynomial Regression');
setChartType('predictionGraph');
setAxisName('time_stamp','temp');
mul(0.0977);
plotChart('time_stamp','temp'); 

Credits

PRACHI AGARWAL

PRACHI AGARWAL

1 project • 3 followers

Comments