While doing any type of work or specific be gaming or for data scientist which consumes lots `of cpu power and tends to stressed it out, so after that it needs rest otherwise it will damage your cpu, no matter it is single core, double or even octa core everyone needs rest.
As I am a gamer while playing I too get involved in gaming too much that I forget to open task manager and see it myself. So it would be nice if pc or laptop tells itself how much it is stressed out. So this BOLT cpu usage meter will automatically tell you.
2. HARDWARE SETUPHardware setup is quite simple means very simple.
There is one one buzzer or you can call it speaker which is an output device so it is connected to digital pin 0 and other pin of buzzer is connected to GND of bolt wifi module.
3. WORKING & DEMONSTRATIONHere is the video of the working of this project with explanation-------->
3.1psutil library
In this we will be reading cpu percent usage through psutil. Psutil is used in python which includes functions related to hardware like retrieving information about cpu temperature, usage, disk. We will be using psutil to read cpu usage.
Here is the link to to psutil documentation https://psutil.readthedocs.io/en/latest/.
3.2In this after getting thereading we will be comparing with two threshhold values. After surpassing 1st threshhold value buzzer rings with half of its frequency and a sms will be sent to mobile with alert and after surpassing 2nd threshhold value, buzzer rings with its full frequency and again a sms will be sent.
3.3 CODE
Here is the code for this project----------------------------------------------------------->
3.3.1 CONFIGURATION FILE
- First we have to create n file name conf.py using terminal.
like this---------------->
using command "sudo nano conf.py ", which will create a new python file.
First of all we need to create an account in Twilio which is an loud communication platform which allows developers programmatically to make and receive calls, send and receive messages, and perform other communication functions using its APIs.
Steps to create Twilio account---------------------------------------------->
- First of all click on this link ---->https://www.twilio.com/
- Then click on sign up and t follow the given procedures there
- After completing your sign up, you will get this type of interface--->
-------X---------X---------
- Inside this file you have to to write the following----->
SID = 'XXXXXXXXXX' //You can find SID in your Twilio Dashboard
AUTH_TOKEN = 'XXXX' //You can find on your Twilio Dashboard
FROM_NUMBER = 'XXXXX' //This is the no. generated by Twilio.
TO_NUMBER = '+91XXXXXXXXXX' //This is your number
API_KEY = 'XXXX' //This is your Bolt Cloud accout API key
DEVICE_ID = 'BOLTXXXX' //This is the ID of your Bolt device- Now again make a new file named " cpu_usage_alert.py" by following the above steps.
And write the following code inside that---------------------------------------->
import psutil ,time ,conf ,json
from boltiot import Sms ,Bolt
mybolt = Bolt(conf.API_KEY ,conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
cpu_comp1=4.3
cpu_comp2=9.3
while True:
try:
cpu_usage = psutil.cpu_percent(interval=0)
print("The current cpu percent usage is" , cpu_usage)
if cpu_usage >cpu_comp1 and cpu_usage <cpu_comp2:
print("ALERT !:CPU has reached its 1st stress level")
response = mybolt.analogWrite( '0' , '127')
response = sms.send_sms("ALERT! The Current CPU percent usage is " +str( cpu_usage))
elif cpu_usage > cpu_comp2:
print("ALERT! cpu has reached its 2nd stress level")
response = mybolt.analogWrite( '0' , '255')
response = sms.send_sms("ALERT! the current cpu percent usage is" +str(cpu_usage))
time.sleep(3)
response = mybolt.digitalWrite('0' , 'LOW')
except Exception as e:
print("Error occured : Below are the details")
print(e)
time.sleep(5)3.3.2 SCREENSHOT OF THE OUTPUT---------------->
- When it reaches 1st threshold value it gives the following sms----->
- And when it reaches 2nd threshold value it gives the following sms---->












Comments