NILESH TIWARI
Published © LGPL

CPU Stress Level Alert

How much CPU is utilised in your PC? This project indicates the CPU load percentage on LEDs using the Bolt and warns if CPU is overloaded.

BeginnerFull instructions provided1 hour615
CPU Stress Level Alert

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Resistor 330 ohm
Resistor 330 ohm
×2
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
Male/Male Jumper Wires
×3
Breadboard (generic)
Breadboard (generic)
×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
Bolt IoT Android App
Bolt IoT Android App

Story

Read more

Schematics

Circuit connection

Circuit connection for the project.

Code

cpu_stress_level

Python
This code finds the percentage of CPU utilised and accordingly indicates it through red and green LEDs based on a threshold value.
import psutil, conf, time, json
from boltiot import Bolt

cpu_stress_threshold = 40 # Threshold is set as 40 percent. When CPU utilisation is more than 40 percent the program will give a warning.
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)

#interval in seconds to check CPU usage
interval = 10

# function to control green led
def control_green_led(pin, value) :
    response = json.loads(mybolt.digitalWrite(pin, value))
    if response["success"] == 1 and value == 'HIGH' :
        print('Green LED turned on.')
    elif response["success"] == 1 and value == 'LOW' :
        print('Green LED turned off.')

# function to control red led
def control_red_led(pin, value) :
    response = json.loads(mybolt.digitalWrite(pin, value))
    if response["success"] == 1 and value == 'HIGH' :
        print('Red LED turned on.')
    elif response["success"] == 1 and value == 'LOW' :
        print('Red LED turned off.')

while True :
    cpu_usage = psutil.cpu_percent(interval = interval)
    print("CPU usage is", cpu_usage)
    if cpu_usage > cpu_stress_threshold :
        print('Warning ! CPU is under stress.')
        control_green_led('0','LOW') # turn off green led
        control_red_led('1', 'HIGH') # turn on red led
        print()
    else :
        print('CPU is not under stress.')
        control_green_led('0', 'HIGH') # turn on green led
        control_red_led('1', 'LOW') # turn off red led
        print()

conf.py

Python
This configuration file contains the API Key and the device id of Bolt module.
API_KEY = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" # your bolt API key
DEVICE_ID = "BOLTXXXXXXX" # your bolt device id

Credits

NILESH TIWARI

NILESH TIWARI

1 project • 1 follower
Thanks to Mayank Joneja and Rahul Singh.

Comments