Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Archit Gupta
Published

Industry Grade Temperature Monitoring System Using IoT

Aims at providing a cheap but a great industry grade temperature monitoring system which uses machine learning to detect any anomaly.

IntermediateShowcase (no instructions)1,028
Industry Grade Temperature Monitoring System Using IoT

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Temperature Sensor
Temperature Sensor
LM35 Range: -55 to 150 degree Celsius.
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
Also a DC supply of 5V is required.
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
Digital Ocean
Mailgun
PuTTY

Story

Read more

Schematics

connections

Code

email_config

Python
configurations to send the email via Mailgun
"""api keys and emails for sending the alert email"""

MAILGUN_API_KEY = 'private API key for Mailgun' 
SANDBOX_URL= 'sandbox url for mailgun' 
SENDER_EMAIL = 'postmaster@sandbox_url'
RECIPIENT_EMAIL = 'receiver email id'
API_KEY = 'Bolt Cloud accout API key'
DEVICE_ID = 'Bolt device id' 

ad_conf

Python
configurations of the device
"""api key and device id are stored here"""

API_KEY = 'Bolt Cloud account API key'
DEVICE_ID = 'ID of the Bolt module'
FRAME_SIZE = 10
MUL_FACTOR = 6

temp_email_anomaly

Python
"""Code for Capestone project"""

import email_config, json, time, ad_conf, math, statistics, datatime
from boltiot import Email, Bolt

min_limit=0
max_limit=41

"""function to compute thresholds"""

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(ad_conf.API_KEY, ad_conf.DEVICE_ID)
mybolt= Bolt(email_config.API_KEY, email_config.DEVICE_ID)
mailer= Email(email_config.MAILGUN_API_KEY, email_config.SANDBOX_URL,email_config.SENDER_EMAIL, email_config.RECIPIENT_EMAIL)
history_data=[]

"""to take sensor values from bolt module"""

while True: 
	now=datetime.datetime.now()
	print("  ***************\n\n",now.strftime("%Y-%m-%d %H:%M:%S),"\n") """to display the current date and time"""
	response = mybolt.analogRead('A0') 
    	data = json.loads(response) 
    	print ("sensor value: ",data['value'])
    	try: 
        		sensor_value = int(data['value']) 
        		print ("Current Temperature: ",((sensor_value*100)/1024),"'C")
        		
		"""to check the temperature is within the set limit and
		to send an email if the temperature is not within the limits""" 
		
		if sensor_value > max_limit or sensor_value < min_limit:
            			response = mailer.send_email("Temperature Alert", "The Current temperature is (in 'C) " +str(sensor_value*100/1024))
            			print("a mail has been sent\n")
    	except Exception as e: 
        		print ("Error 1",e)
        		continue
     	
	"""anomaly detection to tell if the door has been opened"""

	bound = compute_bounds(history_data,ad_config.FRAME_SIZE,ad_config.MUL_FACTOR)
    	if not bound:
        		required_data_count=conf.FRAME_SIZE-len(history_data)
        		print("Need ",required_data_count," more data points to calculate Z-score")
        		history_data.append(int(data['value']))
        		time.sleep(10)
        		continue
    	try:
        		if sensor_value > bound[0] :
            			print ("SOMEONE HAS OPENED THE FRIDGE DOOR")
        		elif sensor_value < bound[1]:
            			print ("SOMEONE HAS OPENED THE FRIDGE DOOR")
        		history_data.append(sensor_value)
            
    	except Exception as e:
        		print ("Error 2",e)
    	time.sleep(10)

temp prediction

JavaScript
to predict the temperature for next 20 minutes
setChartLibrary('google-chart');
setChartTitle('Temperature Prediction For Pharmaceuticals');
setChartType('predictionGraph');
setAxisName('Time','Temperature');
setCrosshair('True');
mul(0.097);
plotChart('time_stamp','temp_in');

Credits

Archit Gupta

Archit Gupta

1 project • 0 followers

Comments