def take_led_control(self): ''' Take control from the OS for the LEDs, if needed. Returns whether we need to return control when done. ''' self.tracer.info("Testing for OS Control of the LED") request = """ <rci_request version="1.1"> <query_setting> <led_control/> </query_setting> </rci_request>""" resp = rci.process_request(request) if resp.find("Setting group unknown") != -1: ## This is a platform that doesn't have OS control of the user LED. self.tracer.info("OS doesn't have control of LED.") return False else: self.tracer.info( "OS controls LED, configuring to be user controlled.") set_request = """ <rci_request version="1.1"> <set_setting> <led_control> <network_connectivity>user</network_connectivity> </led_control> </set_setting> </rci_request>""" ##Disabling OS control of user LED for now. set_resp = rci.process_request(set_request) return True
def run(self): try: self.time_offest() except: pass time.sleep(20) print "#### first run ####" while True: try: print "#############" print "##updating!##" print "#############" #self.weather() try: self.time_offest() except: pass self.property_set("hb", Sample(time.time(), "On", "")) time.sleep(1200) try: self.time_offest() except: pass self.property_set("hb", Sample(time.time(), "On", "")) self.updateMisting() time.sleep(1200) except: print "rebooting now from MA main, see ya" process_request('<rci_request><reboot /></rci_request>') """count = 4
def run(self): while self.offset is None: try: time.sleep(120) self.getOffest() except: pass try: count = 0 #self.my_queue = Queue.Queue(maxsize=5) while True: # list = threading.enumerate() # #print len(list) # for item in list: # #print item #print "#############" #print "##looping! ##" #print "#############" count += 1 #msg = self.my_queue.get() if self.send == True: #if self.sending == False: #if self.upload_lock.acquire(0) == False: #time.sleep(3) #continue if self.sending == False: # self.lock.acquire() #print "##################" #print "##sending start!##" #print "##################" self.__upload_data() # self.lock.release() #print "###################" #print "##sending finish!##" #print "###################" #self.upload_lock.release() self.send = False time.sleep(5) else: time.sleep(5) if count > 6: count = 0 self.send = True except: print "rebooting now from MA uploader, see ya" process_request('<rci_request><reboot /></rci_request>')
def return_led_control(self): if self.OS_LED_CONTROL: self.tracer.debug("Returning control of LED to OS") os_control_request = """ <rci_request version="1.1"> <set_setting> <led_control> <network_connectivity>os</network_connectivity> </led_control> </set_setting> </rci_request>""" rci.process_request(os_control_request)
def __do_dia_shutdown(self, attrs): """ Build a response for a 'shutdown' request. Keyword arguments: attrs -- Dictionary of attributes. Returns a shutdown XML element. (No attributes are supported.) """ process_request('<rci_request><reboot /></rci_request>') #self.__core.request_shutdown() return "<shutdown>"
def get_free_memory(self): response = process_request('''\ <rci_request><query_state><device_stats /></query_state></rci_request>''') response = etree.XML(response) freeMemory = int(response.find('freemem').text) return freeMemory
def performRciCall(rci_command, rci_url=None, proxies={}): if (on_digi_board): response = rci.process_request(rci_command) else: opener = urllib.FancyURLopener(proxies) f = opener.open(rci_url, rci_command) try: for line in f: print line finally: f.close() opener.close()
def getLocalIP(self): if sys.platform.startswith("linux"): return self.__getLocalIPLinux() query_string = """\ <rci_request version="1.1"> <query_state><boot_stats/></query_state> </rci_request>""" response = rci.process_request(query_string) ip_beg, ip_end = (0, 0) if sys.platform == "digix3": ip_beg = response.find("<ip_address>")+1 ip_end = response.find("</ip_address>") else: ip_beg = response.find("<ip>") ip_end = response.find("</ip>") return response[ip_beg+4:ip_end].strip()
def getLocalIP(self): if sys.platform.startswith("linux"): return self.__getLocalIPLinux() query_string = """\ <rci_request version="1.1"> <query_state><boot_stats/></query_state> </rci_request>""" response = rci.process_request(query_string) ip_beg, ip_end = (0, 0) if sys.platform == "digix3": ip_beg = response.find("<ip_address>") + 1 ip_end = response.find("</ip_address>") else: ip_beg = response.find("<ip>") ip_end = response.find("</ip>") return response[ip_beg + 4:ip_end].strip()
def reset(self): process_request('<rci_request><reboot /></rci_request>') # Give us some time to reboot. We should not return. while True: time.sleep(60)
def reset(self): process_request('<rci_request><reboot /></rci_request>') # Give us some time to reboot. We should not return. while True: digitime.sleep(60)
self.connected = 0 else: self.connected += 1 #print "idigi_db (%s): Upload failed to HouseLynx" % (self.__name) else: #print "idigi_db (%s): No new Sample data to send to HouseLynx" % \ (self.__name) xml.close() self.sending = False if self.connected > 10: print "rebooting due to too many failed uploads" process_request('<rci_request><reboot /></rci_request>') def __make_xml(self, channel_name, sample): data = "<sample>" data += "<name>%s</name>" data += "<value>%s</value>" data += "<unit>%s</unit>" data += "<timestamp>%s</timestamp>" data += "</sample>" return data % (channel_name, self.__escape_entities(sample.value), sample.unit, self.convert_timestamp(sample.timestamp)) def __make_compact_xml(self, channel_name, sample):
def poll_stats(self): """rci and cli requests for digi device stats""" print "SystemStatus: Polling system stats" #find cpu utilization percent and free memory try: msg = "<rci_request version=\"1.1\"><query_state><device_stats/></query_state></rci_request>" resp = rci.process_request(msg) cpuPercent = re.search("<cpu>(\S+)</cpu>", resp).group(1) self.property_set("cpu_utilization", Sample(0, int(cpuPercent), "%")) freeMemory = re.search("<freemem>(\S+)</freemem>", resp).group(1) self.property_set("free_memory", Sample(0, int(freeMemory), "bytes")) self.schedule_polling() except: pass if not SettingsBase.get_setting(self,"no_zigbee"): try: # look for configure and read from all active XBee nodes node_list = [] print 'Device discovery in progress. Please wait ...' nodes = zigbee.getnodelist(True) print '\nActive node list of extended addresses' for node in nodes: print node.addr_short, ' ', node.addr_extended, ' ', node.label # now for each node try to retrieve a sample for node in nodes: if node.type != "router": xtn_addr = node.addr_extended # store the active node extended addr for later use node_list.append(xtn_addr) # print the attributes of each active node # print '\naddr_extended: %s' % node.addr_extended # print 'addr_short: %s' % node.addr_short # print 'addr_parent: %s' % node.addr_parent # print 'profile_id: %s' % node.profile_id # print 'manufacturer_id: %s' % node.manufacturer_id # print 'label: %s' % node.label # print 'type: %s' % node.type # try: # module_type, product_type = GetXBeeDeviceType(xtn_addr) # print 'module_type: %s' % module_type # print 'product_type: %s' % product_type # except Exception, e: # print 'GetXBeeDeviceType error: %s' % e # # get some node configuration info using ddo_get try: rssi_raw = zigbee.ddo_get_param(xtn_addr,'DB') zb_rssi = 0-struct.unpack('=B',rssi_raw)[0] print 'Zigbee Coordinator rssi : %s ' % zb_rssi self.property_set("zigbee_coord_rssi", Sample(0, zb_rssi)) vr_raw = zigbee.ddo_get_param(xtn_addr,'VR') #print 'firmware version: %s' % hex(struct.unpack('>H',vr_raw)[0]) except Exception, e: print 'ddo_get error: %s' % e except: pass #find mobile connectivity status if not SettingsBase.get_setting(self,"no_mobile"): try: msg = "<rci_request version=\"1.1\"><query_state><mobile_stats/></query_state></rci_request>" resp = rci.process_request(msg) rssi = re.search("<rssi>(\S+)</rssi>", resp).group(1) try: i_rssi = int(rssi) except ValueError: i_rssi = 0 self.property_set("mobile_rssi", Sample(0, i_rssi)) statsIndex = re.search("<stats_index>(\S+)</stats_index>", resp).group(1) msg = "<rci_request version=\"1.1\"><query_state><ppp_stats index=\""+statsIndex+"\"/></query_state></rci_request>" resp = rci.process_request(msg) mobileStatus = re.search("<ppp_stats index=\""+statsIndex+"\"><state>(\S+)</state>", resp).group(1) self.property_set("mobile_status", Sample(0, mobileStatus)) except: pass #find idigi connectivity status try: msg = "who" status, response = digicli.digicli(msg) if status: #response is a list of strings for each line. Convert into single string. responseStr = string.join(response, "") #responseStr = "" #for line in response: # responseStr += line if ((responseStr.find("connectware") == -1) and (responseStr.find("idigi") == -1)): self.property_set("idigi_status", Sample(0, "disconnected")) else: self.property_set("idigi_status", Sample(0, "connected")) except: pass