From 44121358fee5bd934e4b567415cb611d9833a1cc Mon Sep 17 00:00:00 2001 From: Peter Shipley Date: Tue, 4 Mar 2014 17:33:28 -0800 Subject: [PATCH 1/5] may cause API to stop responding --- Tests/get_hist.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 Tests/get_hist.py diff --git a/Tests/get_hist.py b/Tests/get_hist.py new file mode 100755 index 0000000..30ce7ec --- /dev/null +++ b/Tests/get_hist.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +""" +based on TalkToEagle.py +""" + + +import socket +import sys +import time + +my_macid = "0xd8d5b90000001296" + + + +# Enter your Eagle's IP below +Eagle_IP = "10.1.1.39" + +## list_devices + +s = socket.create_connection( (Eagle_IP, 5002), 10) +print s +time.sleep(1) + +sendstr = "\nlist_devices\n\n" + +s.sendall(sendstr) +print +print "sending to Eagle: \n\r" +print sendstr +print + +time.sleep(1) + +print "Eagle response: \n\r" + +while 1: + buf = s.recv(1000) + if not buf: + break + sys.stdout.write(buf) + +s.close() + + +## get_history_data + +s = socket.create_connection( (Eagle_IP, 5002), 10) +print s + +time.sleep(1) + +sendstr = "\nget_history_data\n0xd8d5b90000001296\n0x00000000\n\n".format(my_macid) + +s.sendall(sendstr) +print +print "sending to Eagle: \n\r" +print sendstr +print + +time.sleep(1) + +print "Eagle response: \n\r" + +while 1: + buf = s.recv(1000) + if not buf: + break + sys.stdout.write(buf) + +s.close() + + +exit(0) From 44a86721993b960d24e6caab53fe5a757e3ee7fd Mon Sep 17 00:00:00 2001 From: Peter Shipley Date: Tue, 4 Mar 2014 17:51:43 -0800 Subject: [PATCH 2/5] crash Eagle --- Tests/get_hist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/get_hist.py b/Tests/get_hist.py index 30ce7ec..f50a525 100755 --- a/Tests/get_hist.py +++ b/Tests/get_hist.py @@ -50,7 +50,7 @@ print s time.sleep(1) -sendstr = "\nget_history_data\n0xd8d5b90000001296\n0x00000000\n\n".format(my_macid) +sendstr = "\nget_history_data\n\n0x00000000\n\n".format(my_macid) s.sendall(sendstr) print From d1f622c292954a9e1090d412d1963951d6551201 Mon Sep 17 00:00:00 2001 From: Peter Shipley Date: Tue, 4 Mar 2014 17:54:34 -0800 Subject: [PATCH 3/5] clean up --- Tests/get_hist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/get_hist.py b/Tests/get_hist.py index f50a525..c51ab96 100755 --- a/Tests/get_hist.py +++ b/Tests/get_hist.py @@ -50,7 +50,7 @@ print s time.sleep(1) -sendstr = "\nget_history_data\n\n0x00000000\n\n".format(my_macid) +sendstr = "\nget_history_data\n\n0x00000000\n\n".format(my_macid) s.sendall(sendstr) print From 7ed00575c35d1adca013584b01ecce15afdd86c4 Mon Sep 17 00:00:00 2001 From: Peter Shipley Date: Tue, 4 Mar 2014 17:56:06 -0800 Subject: [PATCH 4/5] clean up --- Tests/get_hist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/get_hist.py b/Tests/get_hist.py index c51ab96..a664293 100755 --- a/Tests/get_hist.py +++ b/Tests/get_hist.py @@ -50,7 +50,7 @@ print s time.sleep(1) -sendstr = "\nget_history_data\n\n0x00000000\n\n".format(my_macid) +sendstr = "\nget_history_data\n{0}\n0x00000000\n\n".format(my_macid) s.sendall(sendstr) print From 3ff208cccbe5278d2d1c96c54020b5c7bdeab1f2 Mon Sep 17 00:00:00 2001 From: Peter Shipley Date: Tue, 4 Mar 2014 18:01:41 -0800 Subject: [PATCH 5/5] debug and docs --- RainEagle/EagleClass.py | 43 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/RainEagle/EagleClass.py b/RainEagle/EagleClass.py index 5d94be4..4341de2 100644 --- a/RainEagle/EagleClass.py +++ b/RainEagle/EagleClass.py @@ -83,17 +83,26 @@ class Eagle(object) : self.addr = kwargs.get("addr", os.getenv('EAGLE_ADDR', None)) self.port = kwargs.get("port", os.getenv('EAGLE_PORT', 5002)) self.getmac = kwargs.get("getmac", True) + self.timeout = kwargs.get("timeout", 10) self.soc = None self.macid = None + if self.debug : + print "Addr : = ", self.addr + print "timeout : = ", self.timeout + print "debug : = ", self.debug + # preload if self.getmac : self.device_info = self.list_devices() + if self.device_info == None : + raise IOError("Error connecting") if self.debug : + print "__init__ ", pprint(self.device_info) # self.macid = self.device_info['DeviceInfo']['DeviceMacId'] 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") if self.debug : print "comm_responce =", comm_responce + if comm_responce == None: + return None etree = ET.fromstring('' + comm_responce + '' ) rv = _et2d(etree) if self.macid == None : @@ -115,6 +126,8 @@ class Eagle(object) : if macid == None : macid = self.macid comm_responce = self._send_comm("get_device_data", MacId=macid) + if comm_responce == None: + return None etree = ET.fromstring('' + comm_responce + '' ) rv = _et2d(etree) return rv @@ -131,6 +144,8 @@ class Eagle(object) : macid = self.macid comm_responce = self._send_comm("get_instantaneous_demand", MacId=macid) + if comm_responce == None: + return None etree = ET.fromstring('' + comm_responce + '' ) rv = _et2d(etree) return rv @@ -151,6 +166,8 @@ class Eagle(object) : if frequency : kwargs["Frequency"] = frequency comm_responce = self._send_comm("get_demand_values", **kwargs) + if comm_responce == None: + return None etree = ET.fromstring('' + comm_responce + '' ) rv = _et2d(etree) return rv @@ -168,6 +185,8 @@ class Eagle(object) : macid = self.macid comm_responce = self._send_comm("get_summation_values", MacId=macid, Interval=interval ) + if comm_responce == None: + return None etree = ET.fromstring('' + comm_responce + '' ) rv = _et2d(etree) return rv @@ -191,6 +210,8 @@ class Eagle(object) : comm_responce = self._send_comm("get_instantaneous_demand", MacId=macid, Frequency=frequency, Duration=duration) + if comm_responce == None: + return None etree = ET.fromstring('' + comm_responce + '' ) rv = _et2d(etree) return rv @@ -206,6 +227,8 @@ class Eagle(object) : if macid == None : macid = self.macid comm_responce = self._send_comm("get_fast_poll_status", MacId=macid) + if comm_responce == None: + return None etree = ET.fromstring('' + comm_responce + '' ) rv = _et2d(etree) return rv @@ -215,6 +238,12 @@ class Eagle(object) : def get_history_data(self, macid=None, starttime="0x00000000", endtime=None, frequency=None ) : """ Send the GET_HISTORY_DATA command 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 : macid = self.macid @@ -224,6 +253,8 @@ class Eagle(object) : if frequency : kwargs["Frequency"] = frequency comm_responce = self._send_comm("get_history_data", **kwargs) + if comm_responce == None : + return None etree = ET.fromstring('' + comm_responce + '' ) rv = _et2d(etree) return rv @@ -250,21 +281,25 @@ class Eagle(object) : else : command_tag = "LocalCommand" + commstr = "<{0}>\n ".format(command_tag) commstr += "{0!s}\n".format(cmd) for k, v in kwargs.items() : commstr += "<{0}>{1!s}\n".format(k, v) commstr += "\n".format(command_tag) + replystr = "" try: self._connect() + + if cmd == "get_history_data" : + self.soc.settimeout(45) self.soc.sendall(commstr) if self.debug : print "commstr : \n", commstr # time.sleep(1) - replystr = "" while 1 : buf = self.soc.recv(1000) if not buf: @@ -273,10 +308,12 @@ class Eagle(object) : except Exception: print("Unexpected error:", sys.exc_info()[0]) - print(ddat) + print "Error replystr = ", replystr replystr = None finally: self._disconnect() + if self.debug > 1 : + print "_send_comm replystr :\n", replystr return replystr def to_unix_time(self, t) :