To detect anomalies found in Temperature of something like a refrigerator which may help you from getting your vegetables safe or for a cooling chamber in a firm that might save you a lot of money from losing.
Apparatus:1. Bolt IoT Device
2. Temperature Sensor (LM35)
3. Jumper Wires
4. Breadboard
5. USB Cable & Power Bank for input power for Bolt IoT Module.
Circuit Diagram:setChartLibrary('google-chart');
setChartTitle('Polynomial Regression Curve');
setChartType('predictionGraph');
setAxisName('Time Stamp','Temperature(Celsius)');
mul(0.0977);
setAnimation(true);
setCrosshair(true);
plotChart('time_stamp','input');- Write this code in the configuration of your product in Bolt Cloud as a javascript Code by using the extension 'js'. and save
(Again All the codes are accessible through the GitHub link, you can clone or download the code or project from there.)
Bolt with thecircuit in Refrigerator | Readings:
As according to the readings, Temperature varies from 7 degrees to 0 degree Celsius. Hence, I have set boundaries from 0 to 10.
Python Code:This is done on Linux.
I have used gedit File.py command instead of nano File.py as I found it more comfortable, I also had kali Linux installed so, I performed everything there, hence the layout might look a bit different though ORIGINAL.Conf.py- You can enter your own credentials over here of Twilio, Mailgun or any other SMS/email provider for the detection notifications.
"""//Everything here is encrypted , please enter your own Credentials"""
"""For SMS"""
SSID = 'ACd4d24bf6770284eXXXXXX4f347af237b'
AUTH_TOKEN = 'afd8a3d47XXXXXX7bcd8459843aa1d43'
FROM_NUMBER = '+13342XXX511'
TO_NUMBER = '+918527XXX287'
API_KEY = '748b4302-0c4d-43ce-aaee-3c5XXXe4acd7'
DEVICE_ID = 'BOLT29XXX4'
"""FOR EMAIL"""
MAILGUN_API_KEY = 'c2abe147695f14eac73cd1XXXd82e890-a9919d1f-02894bb7'
SANDBOX_URL= 'sandbox82a4fab99cf74b17XXXf46c824c70d78.mailgun.org'
SENDER_EMAIL = 'test@sandbox82a4XXX99cf74b17879f46c824c70d78.mailgun.org'
RECIPIENT_EMAIL = 'bhavyatyagi16@gmail.com'
API_KEY = '748b4302-0c4d-43ce-aaee-3c5XXXe4acd7'
DEVICE_ID = 'BOLT2XXX34'
FRAME_SIZE = 10
MUL_FACTOR = 6Anomaly.pyimport 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]
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
history_data=[]
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
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 ("Raw Temperature in Refrigerator is"+data['value'])
degree=(float(data['value'])/10.24)
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)
print("Temperature Altered anomously, sending alerts!")
""" SMS """
print ("The temperature level increased suddenly. Sending an SMS")
response = sms.send_sms("Someone Opened the Refrigerator, The temperature has raised to:"+str(sensor_value))
print("This is the response ",response)
""" MAIL """
print("Making request to Mailgun to send an email")
response = mailer.send_email("Alert","The Current temperature sensor value is " +str(sensor_value))
response_text = json.loads(response.text)
print("Response received from Mailgun is:"+str(response_text['message']))
print("Temperature in Degree celsius is "+str(degree))
elif sensor_value < bound[1]:
buzz=mybolt.digitalWrite('1',"HIGH")
print(buzz)
print("Temperature altered anomously, sending sms and mail alert!")
""" SMS """
print ("The temperature level decreased suddenly. Sending an SMS")
response = sms.send_sms("The temperature has decreased to : "+str(sensor_value))
print("This is the response ",response)
""" MAIL """
print("Making request to Mailgun to send an email")
response = mailer.send_email("Alert","The Current temperature sensor value is " +str(sensor_value))
response_text = json.loads(response.text)
print("Response received from Mailgun is:"+str(response_text['message']))
print("Temperature in Degree celsius is "+str(degree))
history_data.append(sensor_value);
except Exception as e:
print ("Error",e)
time.sleep(10)- The Z-Score analysis is also taken into account.
- In Virtual Box:
- On Mobile Phone
- Graphical Representation
Thankyou For Checking This Project Out.











Comments