Annalie D'Almeida
Published © LGPL

Capstone Project

Alerts you if the temperature of the cooler exceeds its thresholds or if the cooler door is opened!!

IntermediateFull instructions provided7 hours335
Capstone Project

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Temperature Sensor
Temperature Sensor
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Snappy Ubuntu Core
Snappy Ubuntu Core

Hand tools and fabrication machines

Premium Female/Male 'Extension' Jumper Wires, 40 x 3" (75mm)
Premium Female/Male 'Extension' Jumper Wires, 40 x 3" (75mm)

Story

Read more

Schematics

connections

Connect the wires according to the colors

Code

capstone_project

Python
Upload this code and run to carry out the project.
import email_conf, json, time, math, statistics
from boltiot import Email, Bolt

max_limit = 52
min_limit = -52

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]

mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, 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'])
        if sensor_value > max_limit or sensor_value < min_limit:
            print("Making request to Mailgun to send an email")
            temperature = (100*sensor_value)/1024
            response = mailer.send_email("Alert!!", "The temperature of the refrigerator is " +str(temperature))
            response_text = json.loads(response.text)
            print("Response received from Mailgun is: " + str(response_text['message']))
    except e:
        print("There was an error while parsing the response: ",e)
        continue

    bound = compute_bounds(history_data,email_conf.FRAME_SIZE,email_conf.MUL_FACTOR)
    if not bound:
        required_data_count=email_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 > bound[0] or sensor_value < bound[1]:
            print ("Someone has opened the refrigerator door.")
        history_data.append(sensor_value);
    except Exception as e:
        print ("Error",e)
    time.sleep(10)

email_conf

Python
credentials required
MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 
SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 
SENDER_EMAIL = 'This would be test@your SANDBOX_URL'
RECIPIENT_EMAIL = 'Enter your Email ID Here'
API_KEY = 'This is your Bolt Cloud account API key'
DEVICE_ID = 'This is the ID of your Bolt device' 
FRAME_SIZE = 10
MUL_FACTOR = 6

Credits

Annalie D'Almeida
2 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.