Skip to content

Commit

Permalink
Updated with live monitor and updatenotifying scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
elsmorian committed Oct 25, 2011
1 parent 02b0a7b commit 19c0a37
Show file tree
Hide file tree
Showing 19 changed files with 4,521 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Prescott.py
Expand Up @@ -171,4 +171,4 @@ def __str__(self):
return "An array of "+str(self.clamp_rating)+"A clamp meters"+mystr

def __len__(self):
return len(self.clamp_array)
return len(self.clamp_array)
Binary file added Prescott.pyc
Binary file not shown.
14 changes: 14 additions & 0 deletions TermColour.py
@@ -0,0 +1,14 @@
class Colours:
PINK = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
ENDC = "\033[0m"

def disable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
4 changes: 2 additions & 2 deletions clampmonitor.py
Expand Up @@ -8,7 +8,7 @@
import re
import sys

CONST_CLAMP_RATING = 50
CONST_CLAMP_RATING = 25
#ideal NOTIFY_DIFF seems to be half device rated wattage for old-style lightbulbs
NOTIFY_DIFF = 30
LOOP_TIME = 1
Expand Down Expand Up @@ -53,4 +53,4 @@ def diff(arg1, arg2):
time.sleep(LOOP_TIME)


sys.exit()
sys.exit()
65 changes: 65 additions & 0 deletions polling.py
@@ -0,0 +1,65 @@
#!/usr/bin/env python

from Prescott import Clamp, ClampArray
from TermColour import Colours
import time
import os
import serial
import struct
import re
import sys

CONST_CLAMP_RATING = 25
#ideal NOTIFY_DIFF seems to be half device rated wattage for old-style lightbulbs
NOTIFY_DIFF = 3
LOOP_TIME = 1


def poll_clamps(clamparray):
clamplist = []
for clamp in clamparray:
tmpdict = {
'port':clamp.serial_port,
'serial':clamp.serial_number,
'power':clamp.get_power_last_second()
}
clamplist.append(tmpdict)
return clamplist

def diff(arg1, arg2):
return abs(arg1-arg2)


clamps = ClampArray("auto", "/dev/", CONST_CLAMP_RATING)
print str(clamps)

firstloop = True
oldlist = []
newlist = []

while (True):
if firstloop:
newlist = oldlist = poll_clamps(clamps)
firstloop = False
else:
oldlist = newlist
newlist = poll_clamps(clamps)
#oldlist = sorted(oldlist.items(), key=lambda c: c['serial'])
#newlist = sorted(newlist.items(), key=lambda c: c['serial'])
oldlist.sort(key = lambda c: c['serial'])
newlist.sort(key = lambda c: c['serial'])
for i in range(0, len(newlist)):
oldpow = oldlist[i]['power']
newpow = newlist[i]['power']
powdiff = diff(oldpow, newpow)
if (powdiff >= NOTIFY_DIFF):
print Colours.GREEN+"Sensor "+newlist[i]['serial']+" on "+newlist[i]['port']+" : "+str(round(newlist[i]['power'],1))+"W, changed by: "+str(round(powdiff,1))+"W"+Colours.ENDC
# print "Sensor "+oldlist[i]['serial']+" on "+oldlist[i]['port']+" changed by: "+str(powdiff)+"W!"
# print "Sensor "+oldlist[i]['serial']+" was: "+str(oldpow)+"W, now: "+str(newpow)+"W."
else:
print "Sensor "+newlist[i]['serial']+" on "+newlist[i]['port']+" : "+str(round(newlist[i]['power']))+"W"
time.sleep(LOOP_TIME)
os.system("clear")


sys.exit()
60 changes: 60 additions & 0 deletions serial/__init__.py
@@ -0,0 +1,60 @@
#!/usr/bin/env python

# portable serial port access with python
# this is a wrapper module for different platform implementations
#
# (C) 2001-2010 Chris Liechti <cliechti@gmx.net>
# this is distributed under a free software license, see license.txt

VERSION = '2.5'

import sys

if sys.platform == 'cli':
from serialcli import *
else:
import os
# chose an implementation, depending on os
if os.name == 'nt': #sys.platform == 'win32':
from serialwin32 import *
elif os.name == 'posix':
from serialposix import *
elif os.name == 'java':
from serialjava import *
else:
raise Exception("Sorry: no implementation for your platform ('%s') available" % os.name)


def serial_for_url(url, *args, **kwargs):
"""Get a native, a RFC2217 or socket implementation of the Serial class,
depending on port/url. The port is not opened when the keyword parameter
'do_not_open' is true, by default it is."""
# check remove extra parameter to not confuse the Serial class
do_open = 'do_not_open' not in kwargs or not kwargs['do_not_open']
if 'do_not_open' in kwargs: del kwargs['do_not_open']
# the default is to use the native version
klass = Serial # 'native' implementation
# check port type and get class
try:
url_nocase = url.lower()
except AttributeError:
# its not a string, use default
pass
else:
if url_nocase.startswith('rfc2217://'):
import rfc2217 # late import, so that users that don't use it don't have to load it
klass = rfc2217.Serial # RFC2217 implementation
elif url_nocase.startswith('socket://'):
import socket_connection # late import, so that users that don't use it don't have to load it
klass = socket_connection.Serial
elif url_nocase.startswith('loop://'):
import loopback_connection # late import, so that users that don't use it don't have to load it
klass = loopback_connection.Serial
else:
klass = Serial # 'native' implementation
# instantiate and open when desired
instance = klass(None, *args, **kwargs)
instance.port = url
if do_open:
instance.open()
return instance
Binary file added serial/__init__.pyc
Binary file not shown.

0 comments on commit 19c0a37

Please sign in to comment.