Ashwin Raina
Published

Temperature monitoring and prediction

It monitors the temperature and sends an sms & email alert when the temperature doesn't fall in specified range and also helps in prediction

IntermediateFull instructions provided309
Temperature monitoring and prediction

Things used in this project

Hardware components

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

Software apps and online services

VirtualBox
Used to create a ubuntu server
SMS Messaging API
Twilio SMS Messaging API
Used to send SMS
mailgun
Used to send eMail

Story

Read more

Code

temp_sms.py

Python
main file containing code to send SMS.
import conf #importing the configuration file saved as conf.py
from boltiot import Sms, Bolt '''importing bolt python library and also sms library to send sms'''
import json, time #importing python json and and time libraries

minimum_limit = #Enter minimum limit
maximum_limit = #Enter maximum limit


mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID) '''fetches your Bolt API KEY and DEVICE ID that is stored in conf.py'''
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)'''fetches your SID, AUTH_TOKEN, TO_NUMBER and FROM_NUMBER from conf.py'''

while True: 
    print ("Reading sensor value")
    response = mybolt.analogRead('A0') '''Since sensor is connected on A0 pin of     the module we perform analogRead on A0 pin'''
    data = json.loads(response) '''loading data sent by Bolt Cloud in json format     using Python's json library'''
    print("Sensor value is: " + str(data['value']))
    try: 
        sensor_value = int(data['value']) 
        if sensor_value > maximum_limit or sensor_value < minimum_limit:
            print("Making request to Twilio to send a SMS")
            response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    '''Placing in try except block to handle any error if any occurs'''
    time.sleep(10) #puts the execution on hold for 10 seconds(changeable)

temp_email.py

Python
main file containing code to send Email
import email_conf #importing the configuration file email_conf.py
from boltiot import Email, Bolt '''importing the Bolt python library and email library to send email'''
import json, time #importing the python json and time libraries

minimum_limit = #Enter the minimum value
maximum_limit = #Enter the maximum value


mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID) '''fetches the API KEY and DEVICE ID stored in email_conf.py file'''
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL) '''automatically fetches MAILGUN API KEY, SANDBOX URL, SENDER EMAIL and RECIPIENT EMAIL from email_conf.py file'''

while True: 
    print ("Reading sensor value")
    response = mybolt.analogRead('A0') '''Since sensor is connected on A0 pin of     the module we perform analogRead on A0 pin'''
    data = json.loads(response) '''loading data sent by Bolt Cloud in json format     using Python's json library'''
    print ("Sensor value is: " + str(data['value']))
    try: 
        sensor_value = int(data['value']) 
        if sensor_value > maximum_limit or sensor_value < minimum_limit:
            print("Making request to Mailgun to send an email")
            response = mailer.send_email("Alert", "The Current temperature sensor value is " +str(sensor_value))
            response_text = json.loads(response.text)
            print("Response received from Mailgun is: " + str(response_text['message']))
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    '''Placing in try except block to handle any error if any occurs'''
    time.sleep(10) #puts the execution on hold for 10 seconds(changeable)

conf.py

Python
A configuration file containing details of your Twilio and Bolt Cloud Account.
Stored in a separate file for security purposes
SID = 'You can find SID in your Twilio Dashboard' 
AUTH_TOKEN = 'You can find  on your Twilio Dashboard' 
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
API_KEY = 'This is your Bolt Cloud accout API key'
DEVICE_ID = 'This is the ID of your Bolt device'

email_conf.py

Python
A configuration file containing your mailgun and Bolt Cloud account details.
Stored in a separate file for security purposes.
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'

predict.js

JavaScript
Used for prediction of temperature using Polynomial Regression
setChartLibrary('google-chart');
setChartTitle('Polynomial Regression');
setChartType('predictionGraph');
setAxisName('time_stamp','temp');
mul(0.0977);
plotChart('time_stamp','temp');

Credits

Ashwin Raina
1 project • 0 followers

Comments