Meenal Shah
Published © GPL3+

Mominator

An innovative device which checks if the user is on the laptop in their usual sleeping time and if so, beeps till they go to sleep

BeginnerFull instructions provided1 hour268
Mominator

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Jumper wires (generic)
Jumper wires (generic)
Male to male
×2

Story

Read more

Schematics

Circuit Image

Use a breadboard to make the connections easier

Code

Python code for Mominator

Python
Easy code to check processes working in the laptop and acting accordingly
import psutil
import time
import datetime
from boltiot import Bolt
import pandas as pd

api_key = "84137bd7-1888-4a22-83cf-7c55473e2a11"
device_id = "BOLT6097390"
mybolt = Bolt(api_key, device_id)
response = mybolt.digitalWrite('0', 'LOW')

def isTimeFormat(input):
    try:
        time.strptime(input, '%H:%M')
        return True
    except ValueError:
        return False

def check(bhr, bmin):
    hr,minu = gettime()
    processName = 0
    app = input("Enter the name of the application you wish to check for: ")
    
    while(hr != bhr or minu != bmin):
        # Find PIDs od all the running instances of process that contains 'chrome' in it's name
        listOfProcessIds = findProcessIdByName(app)
        if len(listOfProcessIds) > 0:
           print(app,"is running. You have made a severe mistake. Now Die!!")
           for elem in listOfProcessIds:
               processID = elem['pid']
               processName = elem['name']
               processCreationTime =  time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(elem['create_time']))
               #print((processID ,processName,processCreationTime ))
        if(processName):
           response = mybolt.analogWrite('0', '225')
        else:
           response = mybolt.analogWrite('0', '0')
           #print(response)
        time.sleep(60)
        hr, minu = gettime()
        processName = 0

    response = mybolt.digitalWrite('0', 'LOW')

def findProcessIdByName(processName):
    '''
    Get a list of all the PIDs of a all the running process whose name contains
    the given string processName
    '''
    listOfProcessObjects = []
    #Iterate over the all the running process
    for proc in psutil.process_iter():
       try:
           pinfo = proc.as_dict(attrs=['pid', 'name', 'create_time'])
           # Check if process name contains the given name string.
           if processName.lower() in pinfo['name'].lower() :
               listOfProcessObjects.append(pinfo)
       except (psutil.NoSuchProcess, psutil.AccessDenied , psutil.ZombieProcess) :
           pass
    return listOfProcessObjects;

def gettime():
    hours = int(pd.datetime.datetime.now().hour)
    minutes = int(pd.datetime.datetime.now().minute)
    return [hours,minutes]

def alarm_time():
    a = input("Enter the time you wish to go to sleep: ")
    b = input("Enter the time you wish to continue the no laptop rule: ")
    l1 = a.split(":")
    l2 = b.split(":")
    if(isTimeFormat(a) and isTimeFormat(b)):
        return l1,l2
    else:
        print("Wrong Input.... Try Again")
        alarm_time()

def main():
    response = mybolt.analogWrite('0', '0')
    
    l1,l2 = alarm_time()
    print("Alarm Time Detected")
    ahr = int(l1[0])
    amin = int(l1[1])
    bhr = int(l2[0])
    bmin = int(l2[1])
    hr,minu = gettime()

    while(True):
        if(hr == ahr and minu == amin):
            check(bhr, bmin)
            break
        time.sleep(60)
        hr,minu = gettime()
    print("Success")

main()

Credits

Meenal Shah
1 project • 0 followers

Comments