Ayush Kumar
Published

Temperature Monitoring Project using Bolt Wifi Module

Monitoring of temperature kept in fridge and sends alert when anomaly is detected or temperature crosses threshold limits.

BeginnerFull instructions provided3 hours462
Temperature Monitoring Project using Bolt Wifi Module

Things used in this project

Hardware components

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

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Mailgun Email API Service
Ubuntu Server

Story

Read more

Schematics

Circuit Diagram

Code

Code.py

Python
import conf
from boltiot import Bolt, Email
import json, time, math, statistics
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]
	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:
	response = mybolt.analogRead('A0')
	data = json.loads(response)
	if data['success'] != 1:
		print("There was an error while retriving the data.")
		time.sleep(10)
		continue
	try:
		sensor_value = ((int(data['value']))/(10.24))
	except e:
		print("There was an error while parsing the response: ",e)
		continue
	print("the temperature is ",sensor_value)

	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(sensor_value)
		time.sleep(10)
		continue
	try:
		if sensor_value > bound[0]:
			print("The temperature increased suuddenly.")
			print("Someone opened the fridge door. Sending an Email.")
			response = mailer.send_email("Alert! The temperature increased suddenly. Someone has opened the fridge door.")
			print("Response received:",response)
		if sensor_value < conf.LOW_THRESHOLD or sensor_value > HIGH_THRESHOLD:
			print("The temperature crossed threshold limits. Sending an Email.")
			response = mailer.send_email("Alert!, The temperature crossed threshold limits. The current temperature is:"+str(sensor_value))
			print("Response received: ",response)
		history_data.append(sensor_value)
	except Exception as e:
	    print("Error!",e)
	    time.sleep(10)

Conf.py

Python
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"
MUL_FACTOR = 5
FRAME_SIZE = 10
HIGH_THRESHOLD = 4
LOW_THRESHOLD = -1

Credits

Ayush Kumar
2 projects • 0 followers

Comments