Rajat sharma
Published © GPL3+

Pharma_Monitor

Temperature monitoring with a sense of sudden change and graphical prediction with time.

BeginnerFull instructions provided4 hours750
Pharma_Monitor

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Temperature Sensor
Temperature Sensor
×1
Buzzer
Buzzer
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
Mailgun
Ubuntu Core
Ubuntu Core

Story

Read more

Schematics

Pharma_Monitor

Code

Pharma_Monitor

Python
main code
import conf
import json, time, math, statistics
from boltiot import Email, Bolt

max_limit = 51
min_limit = -51

def compute(history_data,frame_size,factor):
    if len(history_data)<int(frame_size) :
        return None

    if len(history_data)>int(frame_size) :
        del history_data[0:len(history_data)-int(frame_size)]
    Mn=statistics.mean(history_data)
    Var=0
    for data in history_data :
        Var += math.pow((data-Mn),2)
    Zn = int(factor) * math.sqrt(int(Var) / int(frame_size))
    High_bound = history_data[int(frame_size)-1]+Zn
    Low_bound = history_data[int(frame_size)-1]-Zn
    return [High_bound,Low_bound]
    
def buzzer_action(pin, value):
    respo = mine.digitalWrite(pin, value)
    
mine = Bolt(conf.API, conf.DEVICE_ID)
mailer = Email(conf.MAILGUN, conf.SANDBOX, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
history_data=[]

while True:
    print("Collecting sensor value")
    response = mine.analogRead('A0')
    data = json.loads(response)
    print("Sensor value " +str(data['value']))
    try:
        sensor_value = int(data['value'])
        if sensor_value>max_limit or sensor_value<min_limit:
           buzzer_action('1','HIGH')
           buzzer_action('4','LOW')
           print("Making request to Mailgun to send an email")
           cel_value = sensor_value*0.097
           respo = mailer.send_email("Alert: Temprature exceeded thesold limit.", "The Current temperature is " +str(cel_value)+ "degree Celsius" )
           response_text = json.loads(respo.text)
           print("Response received from Mailgun is: " +str(response_text['message']))
           buzzer_action('1','LOW')
    except Exception as e:
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)

    bound = compute(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)
    if not bound:
        required_data_count=int(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] :
             buzzer_action('1','HIGH')
             buzzer_action('4','LOW')
             print ("The door is open. Sending an Email.")
             response = mailer.send_email("Alert","Someone opened fridge door")
             print("This is the response ",response)
             buzzer_action('1','LOW')
        history_data.append(sensor_value);
    except Exception as e:
          print ("Error occured",e)
    time.sleep(10)

prediction_graph

Java
multiplied 0.097 to convert sensor value to degree Celsius
setChartLibrary('google_chart');
setChartTitle('Pharma Monitor');
setChartType('predictionGraph');
setAxisName('Time','Temp');
mul(0.097);
plotChart('time_stamp','temp');

Credits

Rajat sharma
1 project • 0 followers
Thanks to Bolt Iot.

Comments