Browse Source

debug and docs

main
Peter Shipley 11 years ago
parent
commit
3ff208cccb
1 changed files with 40 additions and 3 deletions
  1. +40
    -3
      RainEagle/EagleClass.py

+ 40
- 3
RainEagle/EagleClass.py View File

@@ -83,17 +83,26 @@ class Eagle(object) :
self.addr = kwargs.get("addr", os.getenv('EAGLE_ADDR', None)) self.addr = kwargs.get("addr", os.getenv('EAGLE_ADDR', None))
self.port = kwargs.get("port", os.getenv('EAGLE_PORT', 5002)) self.port = kwargs.get("port", os.getenv('EAGLE_PORT', 5002))
self.getmac = kwargs.get("getmac", True) self.getmac = kwargs.get("getmac", True)
self.timeout = kwargs.get("timeout", 10)
self.soc = None self.soc = None
self.macid = None self.macid = None


if self.debug :
print "Addr : = ", self.addr
print "timeout : = ", self.timeout
print "debug : = ", self.debug

# preload # preload
if self.getmac : if self.getmac :
self.device_info = self.list_devices() self.device_info = self.list_devices()
if self.device_info == None :
raise IOError("Error connecting")
if self.debug : if self.debug :
print "__init__ ",
pprint(self.device_info) pprint(self.device_info)
# self.macid = self.device_info['DeviceInfo']['DeviceMacId'] # self.macid = self.device_info['DeviceInfo']['DeviceMacId']
if self.debug : if self.debug :
print "DeviceMacId = ", self.macid
print "Init DeviceMacId = ", self.macid






@@ -103,6 +112,8 @@ class Eagle(object) :
comm_responce = self._send_comm("list_devices") comm_responce = self._send_comm("list_devices")
if self.debug : if self.debug :
print "comm_responce =", comm_responce print "comm_responce =", comm_responce
if comm_responce == None:
return None
etree = ET.fromstring('<S>' + comm_responce + '</S>' ) etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = _et2d(etree) rv = _et2d(etree)
if self.macid == None : if self.macid == None :
@@ -115,6 +126,8 @@ class Eagle(object) :
if macid == None : if macid == None :
macid = self.macid macid = self.macid
comm_responce = self._send_comm("get_device_data", MacId=macid) comm_responce = self._send_comm("get_device_data", MacId=macid)
if comm_responce == None:
return None
etree = ET.fromstring('<S>' + comm_responce + '</S>' ) etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = _et2d(etree) rv = _et2d(etree)
return rv return rv
@@ -131,6 +144,8 @@ class Eagle(object) :
macid = self.macid macid = self.macid
comm_responce = self._send_comm("get_instantaneous_demand", comm_responce = self._send_comm("get_instantaneous_demand",
MacId=macid) MacId=macid)
if comm_responce == None:
return None
etree = ET.fromstring('<S>' + comm_responce + '</S>' ) etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = _et2d(etree) rv = _et2d(etree)
return rv return rv
@@ -151,6 +166,8 @@ class Eagle(object) :
if frequency : if frequency :
kwargs["Frequency"] = frequency kwargs["Frequency"] = frequency
comm_responce = self._send_comm("get_demand_values", **kwargs) comm_responce = self._send_comm("get_demand_values", **kwargs)
if comm_responce == None:
return None
etree = ET.fromstring('<S>' + comm_responce + '</S>' ) etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = _et2d(etree) rv = _et2d(etree)
return rv return rv
@@ -168,6 +185,8 @@ class Eagle(object) :
macid = self.macid macid = self.macid
comm_responce = self._send_comm("get_summation_values", comm_responce = self._send_comm("get_summation_values",
MacId=macid, Interval=interval ) MacId=macid, Interval=interval )
if comm_responce == None:
return None
etree = ET.fromstring('<S>' + comm_responce + '</S>' ) etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = _et2d(etree) rv = _et2d(etree)
return rv return rv
@@ -191,6 +210,8 @@ class Eagle(object) :


comm_responce = self._send_comm("get_instantaneous_demand", comm_responce = self._send_comm("get_instantaneous_demand",
MacId=macid, Frequency=frequency, Duration=duration) MacId=macid, Frequency=frequency, Duration=duration)
if comm_responce == None:
return None
etree = ET.fromstring('<S>' + comm_responce + '</S>' ) etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = _et2d(etree) rv = _et2d(etree)
return rv return rv
@@ -206,6 +227,8 @@ class Eagle(object) :
if macid == None : if macid == None :
macid = self.macid macid = self.macid
comm_responce = self._send_comm("get_fast_poll_status", MacId=macid) comm_responce = self._send_comm("get_fast_poll_status", MacId=macid)
if comm_responce == None:
return None
etree = ET.fromstring('<S>' + comm_responce + '</S>' ) etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = _et2d(etree) rv = _et2d(etree)
return rv return rv
@@ -215,6 +238,12 @@ class Eagle(object) :
def get_history_data(self, macid=None, starttime="0x00000000", endtime=None, frequency=None ) : def get_history_data(self, macid=None, starttime="0x00000000", endtime=None, frequency=None ) :
""" Send the GET_HISTORY_DATA command """ Send the GET_HISTORY_DATA command
get a series of summation values over an interval of time get a series of summation values over an interval of time

args:
MacId 16 hex digits, MAC addr of EAGLE ZigBee radio
StartTime the start of the history interval (default oldest sample)
EndTime the end of the history interval (default current time)
Frequency Requested number of seconds between samples.
""" """
if macid == None : if macid == None :
macid = self.macid macid = self.macid
@@ -224,6 +253,8 @@ class Eagle(object) :
if frequency : if frequency :
kwargs["Frequency"] = frequency kwargs["Frequency"] = frequency
comm_responce = self._send_comm("get_history_data", **kwargs) comm_responce = self._send_comm("get_history_data", **kwargs)
if comm_responce == None :
return None
etree = ET.fromstring('<S>' + comm_responce + '</S>' ) etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = _et2d(etree) rv = _et2d(etree)
return rv return rv
@@ -250,21 +281,25 @@ class Eagle(object) :
else : else :
command_tag = "LocalCommand" command_tag = "LocalCommand"



commstr = "<{0}>\n ".format(command_tag) commstr = "<{0}>\n ".format(command_tag)
commstr += "<Name>{0!s}</Name>\n".format(cmd) commstr += "<Name>{0!s}</Name>\n".format(cmd)
for k, v in kwargs.items() : for k, v in kwargs.items() :
commstr += "<{0}>{1!s}</{0}>\n".format(k, v) commstr += "<{0}>{1!s}</{0}>\n".format(k, v)
commstr += "</{0}>\n".format(command_tag) commstr += "</{0}>\n".format(command_tag)
replystr = ""


try: try:
self._connect() self._connect()

if cmd == "get_history_data" :
self.soc.settimeout(45)
self.soc.sendall(commstr) self.soc.sendall(commstr)
if self.debug : if self.debug :
print "commstr : \n", commstr print "commstr : \n", commstr


# time.sleep(1) # time.sleep(1)


replystr = ""
while 1 : while 1 :
buf = self.soc.recv(1000) buf = self.soc.recv(1000)
if not buf: if not buf:
@@ -273,10 +308,12 @@ class Eagle(object) :


except Exception: except Exception:
print("Unexpected error:", sys.exc_info()[0]) print("Unexpected error:", sys.exc_info()[0])
print(ddat)
print "Error replystr = ", replystr
replystr = None replystr = None
finally: finally:
self._disconnect() self._disconnect()
if self.debug > 1 :
print "_send_comm replystr :\n", replystr
return replystr return replystr


def to_unix_time(self, t) : def to_unix_time(self, t) :


Loading…
Cancel
Save