Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated with live monitor and updatenotifying scripts
- Loading branch information
Showing
19 changed files
with
4,521 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 not shown.
Oops, something went wrong.