Suranani Lohith Kumar
Published

Pharmacy industry temperature Monitoring

This is a model which uses boltiot to keep an eye on temperature in a Pharmaceutical companies

BeginnerShowcase (no instructions)5 hours269
Pharmacy industry temperature Monitoring

Things used in this project

Story

Read more

Code

conf.

Python
this is used so that the main code doesn't contain all your credentails.
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'
FRAME_SIZE=10
MUL_FACTOR=3

pharmacy

Python
the main code
which reads the temperature for every 10 seconds and send alerts through mail
import conf,json, time, math, statistics
from boltiot import Email, Bolt

max_limit = 105
min_limit = 10

def compute_the_boundary(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))
    bound_high = history_data[int(frame_size)-1]+Zn
    bound_low = history_data[int(frame_size)-1]-Zn
    return [bound_high,bound_low]
    
def buzzer_action(pin, value):
    response = mybolt.digitalWrite(pin, value)
    
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("Collecting sensor value")
    response = mybolt.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
           response = mailer.send_email("Alert: Temprature exceeded threshold limit.", "The Current temperature is " +str(cel_value)+ "degree Celsius" )
           response_text = json.loads(response.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_the_boundary(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)

pharmacy_moniter

JavaScript
this for polynomial regression
setChartLibrary('google_chart');
setChartTitle('Pharmacy Monitor');
setChartType('predictionGraph');
setAxisName('time_stamp','Temp');
setCrosshair(true);
mul(0.097);
plotChart('time_stamp','temp');

Credits

Suranani Lohith Kumar
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.