def _addNewMote(self, mac): # add mote to GUI # Note: if you're reconnecting, mote already exists columnvals = { COL_PKGEN_NUM: 0, COL_PKGEN_PPS: '-', COL_PKGEN_CLR: { 'text': 'clear', 'callback': self._moteListFrameCb_clearPkGen, }, COL_PKGEN_RATE: { 'min2': 100, 'max2': 60000, 'min3': 0, 'max3': 60, 'cb_set': self._moteListFrameCb_PkGenSet, }, } if mac not in self.oap_clients: self.moteListFrame.addMote( mac, columnvals, ) # create OAPClient # Note: if you're reconnecting, this recreates the OAP client self.oap_clients[mac] = OAPClient.OAPClient( mac, self._sendDataToConnector, self.notifClientHandler.getOapDispatcher())
def getOperationalMotes(): operationalmotes = [] # get list of operational motes currentMac = (0,0,0,0,0,0,0,0) # start getMoteConfig() iteration with the 0 MAC address continueAsking = True while continueAsking: try: res = AppData().get('connector').dn_getMoteConfig(currentMac,True) except APIError: continueAsking = False else: if ((not res.isAP) and (res.state in [4,])): operationalmotes += [tuple(res.macAddress)] currentMac = res.macAddress AppData().set('operationalmotes',operationalmotes) # create an oap_client for each operational mote oap_clients = AppData().get('oap_clients') for mac in operationalmotes: if mac not in oap_clients: oap_clients[mac] = OAPClient.OAPClient( mac, AppData().get('connector').dn_sendData, AppData().get('oap_dispatch'), ) return len(operationalmotes)
def _addNewMote(self,mac): # add mote to GUI # Note: if you're reconnecting, mote already exists columnvals = { # role COL_ROLE: ROLE_UNKNOWN, # bridge COL_BRIDGE: '-', # temperature COL_TEMPERATURE: '-', # led COL_LED: { 'text': 'ON', 'callback': self._moteListFrameCb_toggleLed, }, # counters COL_NOTIF_DATA: 0, COL_NOTIF_HEALTHREPORT: 0, } if mac not in self.oap_clients: self.moteListFrame.addMote( mac, columnvals, ) # create OAPClient # Note: if you're reconnecting, this recreates the OAP client self.oap_clients[mac] = OAPClient.OAPClient( mac, self._sendDataToConnector, self.notifClientHandler.getOapDispatcher() )
def _addNewMote(self, mac): # add mote to GUI # Note: if you're reconnecting, mote already exists columnvals = { # led COL_LED: { 'text': 'ON', 'callback': self._moteListFrameCb_toggleLed, }, # counters and latency COL_NOTIF_DATA: 0, COL_NOTIF_IPDATA: 0, COL_NOTIF_HR: 0, COL_LAT_MIN: '-', COL_LAT_CUR: '-', COL_LAT_MAX: '-', COL_NOTIF_CLR: { 'text': 'clear', 'callback': self._moteListFrameCb_clearCtrs, }, # temperature COL_TEMPERATURE: '-', COL_TEMP_NUM: 0, COL_TEMP_CLR: { 'text': 'clear', 'callback': self._moteListFrameCb_clearTemp, }, COL_TEMP_RATE: { 'min': 1000, 'max': 60000, 'cb_get': self._moteListFrameCb_rateGet, 'cb_set': self._moteListFrameCb_rateSet, }, COL_ACTION1: { 'text': 'action1', 'callback': self._moteListFrameCb_action1, }, } if mac not in self.oap_clients: self.moteListFrame.addMote( mac, columnvals, ) # create OAPClient # Note: if you're reconnecting, this recreates the OAP client self.oap_clients[mac] = OAPClient.OAPClient( mac, self._sendDataToConnector, self.notifClientHandler.getOapDispatcher())
def _addNewMote(self,mac): # add mote to GUI # Note: if you're reconnecting, mote already exists columnvals = { # led COL_LED: { 'text': 'ON', 'callback': self._moteListFrameCb_Led, }, COL_LEDOFF: { 'text': 'OFF', 'callback': self._moteListFrameCb_Ledoff, }, COL_GETD0: { 'text': 'GET', 'callback': self._moteListFrameCb_getd0, }, COL_GETD1: { 'text': 'GET', 'callback': self._moteListFrameCb_getd1, }, COL_GETD2: { 'text': 'GET', 'callback': self._moteListFrameCb_getd2, }, COL_GETD3: { 'text': 'GET', 'callback': self._moteListFrameCb_getd3, }, # counters and latency COL_D0: 0, COL_D1: 0, COL_D2: 0, COL_D3: 0, } if mac not in self.oap_clients: self.moteListFrame.addMote( mac, columnvals, ) # create OAPClient # Note: if you're reconnecting, this recreates the OAP client self.oap_clients[mac] = OAPClient.OAPClient(mac, self._sendDataToConnector, self.notifClientHandler.getOapDispatcher())
def _LEDPingFrameCb_startPressed(self, mac): # remember that the app is started self.pingOngoing = True # disable further editing of MAC address self.LEDPingFrame.disableMacText() # create OAPClient if not self.oap_client: self.oap_client = OAPClient.OAPClient(mac, self.connector.dn_sendData, self.oap_dispatch) # initiate first LED toggle self._toggleLed()
def _oap_add_client_if_needed(self, mac): if type(mac) == str: macString = mac mac = [int(b, 16) for b in mac.split('-')] else: macString = u.formatMacString(mac) with self.dataLock: if macString not in self.oapClients: # get MACs per manager for (manager, motes) in self.motes_GET().items(): if macString in manager: break # create OAPClient self.oapClients[macString] = OAPClient.OAPClient( mac, self.managerHandlers[manager].connector.dn_sendData, self.oapDispatch, )
def _handle_oap_notif(self, mac, notif): # convert MAC to tuple mac = tuple(mac) if isinstance(notif, OAPNotif.OAPTempSample): # this is a temperature notification value = float( notif.samples[0]) / 100.0 # /100 since unit in 100th of C xivelyConnectorThread().publish( mac=mac, datastream='temperature', value=value, ) if mac not in self.oap_clients: publisher = xivelyConnectorThread().publisher if publisher: try: # create datastream publisher.publish( mac=mac, datastream='led', value=0, ) # subscribe publisher.subscribe( mac=mac, datastream='led', callback=self._led_cb, ) # create OAP client self.oap_clients[mac] = OAPClient.OAPClient( mac, self._sendDataToConnector, self.oap_dispatch, ) except Exception as err: output = [] output += ['==============='] output += [ '{0}: Exception when creating and subscribing to datastream' ] output += [ '- mac: {0}'.format( FormatUtils.formatMacString(mac)) ] output += ['{0}'.format(type(err))] output += ['{0}'.format(err)] output += [''] output = '\n'.join(output) log.error(output) print output