Komal Monga
Created May 4, 2019

Temptor System

This is a temperature monitoring system which sends email alerts once the temperature crosses a particular level.

Intermediate1 hour28
Temptor System

Things used in this project

Hardware components

Temperature Sensor
Temperature Sensor
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud

Story

Read more

Code

Temperature Monitoring System

Python
import conf, json, time,math,statistics
from boltiot  import Bolt,Email
minimum_limit=100
maximum_limit=400
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)
mailer =Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL,conf.SENDER_EMAIL,conf.RECIPIENT_EMAIL)
history_data=[]

while True:
 print("reading sensor value")
 response= mybolt.analogRead('A0')

 data=json.loads(response)
 if data['success']!='1':
   print("error while recieving data")
   print("this is the error"+data['value'])
   time.sleep(10)
   continue
 sensor_value=int(data['value'])
 sensor_value1=sensor_value/10.24
 print("current refrigerator temperature is:"+str(sensor_value))
 # print("making request to mailgun to send email")
 # response = mailer.send_email("alert","current temp value is"+str(sensor_value))
 sensor_value=0
 try:
 sensor_value=int(data['value'])
    if sensor_value> maximum_limit or sensor_value<minimum_limit:
        print("making request to mailgun")
        response=mailer.send_email("alert","current temp value is:"+str(sensor_value))
        response_text=json.loads(response.text)
        print("response recieved from mailgun")
 except Exception as  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("more data needed")
   history_data.append(int(data['value']))
   time.sleep(10)
   continue
 try:
     if sensor_value>bound[0]:
       sensor_value1=sensor_value/10.24
       print("The temperature value has increased")
 response=mailer.send_email("Alert","Someone opened the fridge door")
       print("email response is:",response)
     history_data.append(sensor_value1);
 except Exception as e:
   print("error",e)
 time.sleep(10)

Credits

Komal Monga
1 project • 0 followers

Comments