BOLT TEMPERATURE DATALOGGER AND PREDICTOR WITH ANOMALY DETECTION
1.OVERVIEW:
A temperature data logger and predictor is a portable device used to monitor temperature over a period of time and to predict the temperature over a certain period of time. The data can be viewed, retrieved and evaluated after it has been recorded.
2.STORY:
a.INTRODUCTION:
A temperature data logger and predictor plays a vital role in industrial appliances. If a product is to be maintained at a particular temperature and for the temperature to remain constant, a temperature monitor and predictor should be used.
A temperature monitor and predictor is mostly used in areas like:
Motors: To ensure that the motor doesn't overheat.
Pharmaceuticals: To ensure that certain pharmaceutical products remain at a particular temperature.
FoodProducts: To ensure that the temperature required for particular food product doesn't exceed.
Computers: To ensure that the system doesn't overheat.
b.STEPSFORBUILDINGPROJECT:
STEP1: Hold the Temperature sensor LM35 in a manner that you can read LM35 written on it.
STEP2: In this position, identify the pins of the sensor as VCC, Output, Ground from your left to right.
STEP3: Use Jumper female to male to connect temperature sensor LM35 and Bolt wifi module.
STEP4: Connect Vcc pin of LM35 to 5V of the Bolt wifi module.
STEP5: Connect Outputpin of LM35 to A0 of Bolt wifi module.
STEP6: Connect Groundpin of LM35 to Ground of Bolt wifi module.
STEP7: Now, connect the Bolt wifi module to your laptop or desktop computer and power up the circuit.
STEP8: Login into your Bolt cloud account and go to products tab.
STEP9: Create new product and choose product type as Inputdevice and interface type as GPIO. Then click configure icon.
STEP10: In the hardware tab, select radio button next to A0 pin. Give a pin name and save the configuration using save icon.
STEP 11: Go to the code tab, give a suitable name for the code and select the extension for code as.js
STEP12: Type the following code:
SetChartLibrary('google_chart');
SetChartTitle('Polynomial Regression');
SetChartType('Prediction Graph');
SetAxisName('time_stamp','temp');
mul(0.097)
plotchart('time_stamp','temp');
STEP13: Save the code and go to devices tab. Now you will be able to see that your device is online.
STEP14: Select view this device option, you will be able to see your prediction graph. Select Deployconfiguration to get more temperature values. You can use your Bolt IOT mobile app to check on the graphs.
CREATINGTWILIOACCOUNT:
STEP15: Now to create a Twilioaccount, go to https://www.twilio.com/login.
STEP16; Login using your mail id. Use a working Mobile number for Mobile number verification.
STEP17: Now inside twilio dashbord you will be having unique auth number, SID number. Select generate number option to generate a phone number from which you will be receiving the SMS.
ACCESSINGREPLFORCODING:
STEP18: I have used a website called repl.it instead of digital ocean and Virtual box.
STEP19: To use repl go to repl.it website and create an account using your gmail.
STEP20: After Login, select the create new repl icon and select the language as Python and give your project a suitable name.
STEP21: Type the following code:
SID ="XXXXXXXXXXXXXXXXXXXXXXX"
AUTH_TOKEN ="XXXXXXXXXXXXXXXXXX"
FROM_NUMBER = "+12058968099"
TO_NUMBER = "+91XXXXXXXXXXXX"
API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
DEVICE_ID = "BOLTXXXXXXXX"
from boltiot import Sms, Bolt
import json, time
minimum_limit = 300
maximum_limit = 600
mybolt = Bolt( API_KEY,DEVICE_ID)
sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)
while True:
print ("Reading sensor value")
response = mybolt.analogRead('A0')
data = json.loads(response)
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)
time.sleep(10)
STEP22: Now you will receive a message to your registered number if the temperature value exceeds threshold value.
ANOMALYDETECTION:
STEP23: Anomaly detection detection is used so that we can know when temperature increases or decreases suddenly.
STEP24: Again create a new repl and give an appropriate name and select the language as python.
STEP25: Now, type the following code:
SID ="XXXXXXXXXXXXXXXXX"
AUTH_TOKEN = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
FROM_NUMBER = '+12058968099'
TO_NUMBER = '+91XXXXXXXXXXXXX'
API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
DEVICE_ID = 'BOLTXXXXXXXX'
FRAME_SIZE = 10
MUL_FACTOR = 6
import json, time, math, statistics
from boltiot import Sms, Bolt
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(API_KEY,DEVICE_ID)
sms = Sms(SID,AUTH_TOKEN,TO_NUMBER,FROM_NUMBER)
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.")
print("This is the error:"+data['value'])
time.sleep(10)
continue
print ("This is the value "+data['value'])
sensor_value=0
try:
sensor_value = int(data['value'])
except e:
print("There was an error while parsing the response: ",e)
continue
bound = compute_bounds(history_data,FRAME_SIZE,MUL_FACTOR)
if not bound:
required_data_count=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] :
print ("The Temperature level increased suddenly. Sending a SMS.")
response = sms.send_sms("Temperture level increased")
print("This is the response ",response)
elif sensor_value < bound[1]:
print ("The Temperature level is decreased suddenly. Sending a SMS .")
response = sms.send_sms("Temperature level decreased")
print("This is the response ",response)
history_data.append(sensor_value);
except Exception as e:
print ("Error",e)
time.sleep(10)
STEP26: Again you will recieve a message when the temperature increases or decreases. You can even plot a graph to know when anomaly happened, if needed.
#Bolt
#BoltIOT
#TemperatureMonitor
#Twilio
#repl
#Project
#SimpleandEasy
Comments