Virinchi Tirumaladas
Published © GPL3+

Industry Grade Temperature Monitoring System

Building an industry grade temperature monitoring system which uses machine learning to detect any anomaly.

IntermediateFull instructions provided3 hours970
Industry Grade Temperature Monitoring System

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Temperature Sensor
Temperature Sensor
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
SMS Messaging API
Twilio SMS Messaging API
Twilio API for WhatsApp
Twilio API for WhatsApp
Linux Ubuntu 16.04 LTS
Mailgun

Story

Read more

Schematics

Connecting the LM35 sensor to BOLT.

Code

conf.py

Python
SSID = 'AC201XXXXXXXXXXXXXXXXXXXXXXXX1ac73ae' 
AUTH_TOKEN = '82757dXXXXXXXXXXXXXXXa6ca56' 
FROM_NUMBER = '+12XXXXXXXX42'
TO_NUMBER = '+91XXXXXXXX5'
API_KEY = '471a1bb2-2cXXXXXXXXXXXXXXXX5a2'
DEVICE_ID = 'BOLTXXXXXX20'
FRAME_SIZE = 10
MUL_FACTOR = 6
FROM_WHATSAPP = 'whatsapp:+14XXXXXX6'
TO_WHATSAPP = 'whatsapp:+919XXXXXX5'
MAILGUN_API_KEY = '5c0e9bac5553334af8XXXXXXXXXXXXXXXXXXXXXX14dd6'
SANDBOX_URL= 'sandboxXXXXXXXXXXXXXXX468fad4380.mailgun.org'
SENDER_EMAIL = 'test@sandboxXXXXXXXXXXXXXXXXXXXXXXad4380.mailgun.org'
RECIPIENT_EMAIL = 'virinchiXXXXXXXX@gmail.com'

anomaly_detection1.py

Python
import 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)
sms_whatsapp = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_WHATSAPP, conf.FROM_WHATSAPP)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
history_data=[]
  
while True:
   response = mybolt.analogRead('A0')
   response1 = mybolt.analogRead('A0')
   response2 = 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(5)
       continue
   sensor_value1 = int(data['value'])
   sensor_value1 = sensor_value1/10.24
   print ("The current temperature of your refrigerator is "+ str(sensor_value1)+" degree celsius. And the sensor Value is "+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(5)
       continue
   try:
       if sensor_value > bound[0] :
           sensor_value1 = sensor_value/10.24
           print ("The temperature level has INCREASED suddenly.Sending SMS")
           response = sms.send_sms("Someone Opened the fridge door. The current temperature is " + str(sensor_value1)+ " degree celsius")
           response1 = mailer.send_email("ALERT", "The temperature of your refrigarator has been INCREASED suddenly because someone opened the fridge door. The current temperature is " + str(sensor_value1)+" degree celsius")
           response2 = sms_whatsapp.send_sms("The temperature of your Refrigerator has been INCREASED suddenly. The current temperature sensor value is " + str(sensor_value1)+ " degree celsius")
           print("This is the response for SMS ",response)
           print("This is the response for EMAIL ",response1)
           print("This is the response for WHATSAPP ",response2)
       history_data.append(sensor_value);
   except Exception as e:
       print ("Error",e)
   time.sleep(5)

Credits

Virinchi Tirumaladas

Virinchi Tirumaladas

1 project • 2 followers

Comments