siddhant srivastava
Published

CPU usage monitoring using Bolt

Aim of this project is to tell you how to monitor the load on your CPU by cheking its CPU usage.

BeginnerFull instructions provided30 minutes321
CPU usage monitoring using Bolt

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Breadboard (generic)
Breadboard (generic)
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
pycharm
(optional)

Story

Read more

Schematics

Circuit

Code

alert.py

Python
import psutil, time
from boltiot import Bolt, Sms
from config import *


mydevice = Bolt(API_KEY, DEVICE_ID)
sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)

cpu_stress_threshold = 5.0 #threshold  after which buzzer start buzz

interval = 5


# define a function named buzzer having two parameters
def buzzer(pin, value):
    response = mydevice.analogWrite(pin, value)


while True:
    cpu_usage = psutil.cpu_percent(interval = interval)
    print ("CPU usage:", cpu_usage)
    try:

       if cpu_usage > cpu_stress_threshold:
        buzzer('1', '255')
        buzzer('2', '0')
        # Now a message is sent to your mobile through twilio
        response = sms.send_sms("The Current CPU usage is " + str(cpu_usage))
        print("Response from Twilio is: " + str(response))
        print("Status of SMS at Twilio is :" + str(response.status))
 
       else:
        buzzer('1', '0')
    except Exception as e:
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)

config.py

Python
SID = 'SID is given on Twilio Dashboard'
AUTH_TOKEN = 'It can be find on Twilio Dashboard'
FROM_NUMBER = 'Twilio generated number'
TO_NUMBER = 'your phone number'
API_KEY = 'BOLT API KEY'
DEVICE_ID = 'BOLT DEVICE ID'

Credits

siddhant srivastava
1 project • 0 followers

Comments