def run(s, db): trc = CurrentCostTracer() trc.EnableTrace(True) trc.InitialiseTraceFile() myparser = CurrentCostDataParser() while True: try: line = s.readline() except Exception, why: print why sleep(1) else: if line: line = line.strip() currentcoststruct = myparser.parseCurrentCostXML(line) if currentcoststruct: print currentcoststruct if currentcoststruct["msg"].has_key("ch1"): w1 = int(currentcoststruct["msg"]["ch1"]["watts"]) w2 = int(currentcoststruct["msg"]["ch2"]["watts"]) w3 = int(currentcoststruct["msg"]["ch3"]["watts"]) t = (w1**2 + w2**2 + w3**2)**0.5 print "watts are :", t if currentcoststruct["msg"].has_key("hist"): print "storing history data" myparser.storeTimedCurrentCostData(db)
# import os import sys import time import string import wx from datetime import datetime from string import atoi, atof from mqttClient import * from currentcostdata import CurrentCostUpdate from tracer import CurrentCostTracer # this class provides logging and diagnostics trc = CurrentCostTracer() # # Many CurrentCost users have their meters connected to a RSMB (Really Small # Message Broker) which means they may not want to disconnect it from this to # be able to use this app. # # So we provide the ability to receive CurrentCost data via MQTT. This also # lets us use the program remotely. # # This class is used to provide the MQTT connection to download history data. # # # Dale Lane (http://dalelane.co.uk/blog) receivedHours = False
# along with this program. If not, see <http://www.gnu.org/licenses/>. # # The author of this code can be contacted at [email protected] # Any contact about this application is warmly welcomed. # import os import serial import time import string from currentcostparser import CurrentCostDataParser from currentcostdb import CurrentCostDB from tracer import CurrentCostTracer # class for logging diagnostics trc = CurrentCostTracer() # # # # # Dale Lane (http://dalelane.co.uk/blog) class CurrentCostSerialHistoryConnection(): guicallback = None # # Establish a connection to the CurrentCost meter #
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # The author of this code can be contacted at [email protected] # Any contact about this application is warmly welcomed. # import numpy as np import time from threading import Thread, Lock, Condition from gridsourcedata import ElectricityGenerationDataSource from tracer import CurrentCostTracer # this class provides logging and diagnostics trc = CurrentCostTracer() # # Displays a graph showing live CurrentCost data divided by the way the # electricity was generated. # # Dale Lane (http://dalelane.co.uk/blog) # class CurrentCostElectricityGeneration(): livegraph = None energyMix = { 'CCGT': 0.0000000000000000000000000001, 'OCGT': 0.0000000000000000000000000001,
# along with this program. If not, see <http://www.gnu.org/licenses/>. # # The author of this code can be contacted at [email protected] # Any contact about this application is warmly welcomed. # import datetime import xml.parsers.expat # this class converts relative timestamps into absolute timestamps from currentcostdataconvert import CurrentCostDataConverter # this class provides logging and diagnostics from tracer import CurrentCostTracer trc = CurrentCostTracer() # # CurrentCost XML parser written to handle CC128 data # # Note that this is provided to help get you started, but it lacks careful # error-handling or proper documentation. # # If you have any questions about it, or even just find it useful, please do # let me know - [email protected] # # # Dale Lane (http://dalelane.co.uk/blog) # class CurrentCostDataParser:
# Any contact about this application is warmly welcomed. # from tracer import CurrentCostTracer import serial import threading # this class needs to be thread-safe # # Opens a serial connection to CurrentCost meters # # Dale Lane (http://dalelane.co.uk/blog) # # class for logging diagnostics trc = CurrentCostTracer() class CurrentCostConnection: connection = None connerr = None lock = threading.Lock() # # connect to the specified COM port (or serial device for Linux etc.) # # it attempts to make connections using settings appropriate to all known # models of CurrentCost meter #