Aditya Bhatnagar
Published © GPL3+

BOLTIOT CPU usage indicator

We dont know when our laptop cpu load gets too high. This project will indicate you cpu load with alert, means time to give rest to it.

IntermediateFull instructions provided6 hours451
BOLTIOT CPU usage indicator

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Buzzer
Buzzer
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Male/Male Jumper Wires
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API

Story

Read more

Code

BOLTIOT CPU usage indicator

Python
This is the python code for this project
import psutil ,time ,conf ,json   #conf is the name of configuration file
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   #1st threshold value
cpu_comp2=9.3   #2nd threshold value

while True:
   try:
      cpu_usage = psutil.cpu_percent(interval=0)    #to get the cpu percent usage
      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')     #ring the buzzer with 1/2 freq.
           response = sms.send_sms("ALERT! The Current CPU percent usage is " +str( cpu_usage))             #alert sms 
      elif cpu_usage > cpu_comp2:
           print("ALERT! cpu has reached its 2nd stress level")
           response = mybolt.analogWrite( '0' , '255')    #ring the buzzer with full freq.
           response = sms.send_sms("ALERT! the current cpu percent usage is" +str(cpu_usage))
      time.sleep(3)
      response = mybolt.digitalWrite('0' , 'LOW')     #stop the ringing 
   except Exception as e:
           print("Error occured : Below are the details")
           print(e)

   time.sleep(5)              #read values after every 5 seconds

Credits

Aditya Bhatnagar
1 project • 0 followers

Comments