Ankur Tripathi
Published © GPL3+

Freezer Monitor & Anomaly System

This system used to detect anomaly obtained in the temperature in the freezer and send an alert via message & tweet.

IntermediateFull instructions provided2 hours918
Freezer Monitor & Anomaly System

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Temperature Sensor
Temperature Sensor
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Software apps and online services

Bolt IoT Android App
Bolt IoT Android App
Bolt Cloud
Bolt IoT Bolt Cloud
AWS EC2
Amazon Web Services AWS EC2
Snappy Ubuntu Core
Snappy Ubuntu Core
SMS Messaging API
Twilio SMS Messaging API
Twitter
Twitter
Tweepy: Twitter for Python!

Story

Read more

Schematics

Freezer Monitor Hardware Connection

Freezer Monitor Base Circuit

Code

Configuration File

Python
""" TWILIO CONFIGURATION """

SSID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
AUTH_TOKEN = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
FROM_NUMBER='+12674151466'
TO_NUMBER = '+9194XXXXXXX'

""" BOLT IOT CONFIGURATION """

API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'
DEVICE_ID = 'BOLTXXXXXX'
FRAME_SIZE = 10
MUL_FACTOR = 6


""" TWITTER CONFIGURATION"""

consumer_key = 'XXXXXXXXXXXXXXXXX'
consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
access_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
access_token_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

Freezer Monitor

Python
import json,time,math,statistics,conf,requests,tweepy
from boltiot import Bolt,Sms,Email
config = {
"consumer_key"    : conf.consumer_key,
"consumer_secret"     :conf.consumer_secret ,
"access_token"        : conf.access_token,
"access_token_secret" :conf.access_token_secret
}
def get_api_object(cfg):
    auth =tweepy.OAuthHandler(cfg['consumer_key'],
                                  cfg['consumer_secret'])
    auth.set_access_token(cfg['access_token'],
                              cfg['access_token_secret'])
    return tweepy.API(auth)
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=0
    Zn = factor*math.sqrt(history_data[frame_size-1])+Zn
    Low_bound = history_data[frame_size-1]-Zn
    High_bound = history_data[frame_size-1]+Zn
    return [High_bound,Low_bound]
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
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
    sensor_value= int(data['value'])
    sensor_valuec = sensor_value/10.24
    print("Current Freezer Temperature is •C  "+str(sensor_valuec))
    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 > bound[0] :
            buzz=mybolt.digitalWrite('1',"HIGH")
            print(buzz)
            time.sleep(2)
            api_object = get_api_object(config)
            tweet = ("Temperature increased suddenly Current Temperature is: "+str(sensor_valuec))
            status = api_object.update_status(status=tweet)
            print("Tweeted")
            response = sms.send_sms("Temperature increased suddenly Current Temperature is: "+str(sensor_valuec))
            print("Response:",response)
            print("Anomaly of the temperature occured because of increase in temperature.")
            buzzoff=mybolt.digitalWrite('1',"LOW")
            print(buzzoff)
        elif sensor_value < bound[1]:
             buzz=mybolt.digitalWrite('1',"HIGH")
             print(buzz)
             time.sleep(2)
             print("Anomaly of the temperature occured because of decrease in temperature.")
             buzzoff=mybolt.digitalWrite('1',"LOW")
             print(buzzoff)
        history_data.append(sensor_value);
    except Exception as e:
        print ("Error",e)
    time.sleep(10)

Credits

Ankur Tripathi

Ankur Tripathi

1 project • 2 followers

Comments