Abhishek Wadke
Published © GPL3+

CPU Stress-teller

CPU Stress-Teller is basically a tool that will help you to check whether your computer’s CPU is facing stress or not.

BeginnerProtip1 hour277
CPU Stress-teller

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LED (generic)
LED (generic)
×2

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App

Story

Read more

Schematics

Hardware

HARDWARE SETUP.
The hardware connections are quite straightforward if you've already gone through the steps in the Quickstart guide to set up the Bolt device.
https://cloud.boltiot.com/docs
There are two LEDs which we use in the project. The Green LED is on if the CPU load is less than the threshold. Once the CPU load goes above the threshold, the Red LED comes on.
The Green LED is connected between digital pin 0 and GND.
The Red LED is connected between digital pins 1 and 2. When pin 1 is High and 2 is Low, the Red LED comes on. In order to switch it off, we toggle pin 1 to Low while 2 remains low.

Software

SOFTWARE SETUP.
In order to control the BOLT IOT Module, we will be using BOLT-IOT cloud.
http://www.cloud.boltiot.com
Clicking the above link you will be taken to BOLT IOT Webpage.
Copy the API Key and the Bolt Device ID after setting up your Bolt IoT Cloud account from the dashboard. In case this is unclear, have a look at one of our previous posts like the one about a Crypto/Bitcoin Price Notification system
Other than that, run the Python script on your machine by running the below command on your PC or remote server and you're done!

And so, this is it! The easiest way to bridge the cyber with the physical world to let you know if your CPU is having a hard day.

Output

After running the code we get the following output.

Graph

During the project, we observed the following graph

Code

Python code

Python
It is a normal pyhton code, but before using this code you should have Bolt Iot device ID and API Key. To get your device ID and API key visit the following link
https://cloud.boltiot.com/
import psutil
from boltiot import Bolt

api_key = "API KEY"
d_id = "DEVICE ID"

cpu_red_threshold = 0.4
client= Bolt(api_key, d_id)

#interval in seconds to check cpu usage
interval = 5

def control_green_led(pin, value):
    response = client.digitalWrite(pin, value)

def control_red_led(pin, value):
    response = client.digitalWrite(pin, value)

while True:
    cpu_usage = psutil.cpu_percent(interval = interval)
    print ("CPU usage is", cpu_usage)
    if cpu_usage > cpu_red_threshold:
        control_green_led('0','LOW')
        control_red_led('1', 'HIGH')
        control_red_led('2', 'LOW')
    else:
        control_green_led('0', 'HIGH')
        control_red_led('1', 'LOW')

Credits

Abhishek Wadke

Abhishek Wadke

1 project • 0 followers

Comments