def run(self): log("Spontaneous Data Logger for %s started." % (self.name)) self.running = True while self.running: data = self.bridge.spontaneous().next() now = datetime.now() data['timevalue'] = floattime() m = None for mote in self.bridge.motes: if mote.unitId == data['unitId']: m = mote break if m is not None: hasLast = m.lastCommunication is not None if m.inRapidMode and hasLast and (data['timevalue'] - m.lastCommunication) > 1.5: log("Communication has slowed. Mote %s is not in rapid mode anymore." % m.unitId) m.inRapidMode = False elif hasLast and (data['timevalue'] - m.lastCommunication) < 1.5: m.inRapidMode = True m.lastCommunication = data['timevalue'] data['timestamp'] = str(now) self.bridge.spontaneousDataCache[str(data['unitId'])] = data log("Logging spontaneous data from %s." % data['unitId']) results = [ now, data['unitId'], data['Temp'], data['Light'], data['Bump'], data['RxLQI'], data['TxLQI'], data['Battery']] self.csvWriter.writerow(results) print "Spontaneous Data Logger for %s stopped." % (self.name)
def scanBridge(self, serial): results = dict() b = self.getBridge(serial) # Check if the device is free, if we're blocked just keep moving. if b.deviceLock.acquire(0): b.deviceLock.release() numMotes = b.numMotes() if numMotes != len(b.motes): b.motes = b.listMotes() for mote in b.motes: t = PlaceMoteInRapidModeThread(mote) t.start() results['Number of Connected Motes'] = len(b.motes) motes = dict() for m in b.motes: moteDict = moteAsDict(m) moteDict['nickname'] = moteDict['name'] data = b.spontaneousDataCache.get(str(m.unitId), {}) if data: tableData = list() tableData.append(createFeedbackDict('Temperature',data['Temp'])) tableData.append(createFeedbackDict('Light',data['Light'])) tableData.append(createFeedbackDict('Bump',data['Bump'])) tableData.append(createFeedbackDict('Tx Link Quality',data['TxLQI'])) tableData.append(createFeedbackDict('Rx Link Quality',data['RxLQI'])) tableData.append(createFeedbackDict('Vbatt',data['Battery'])) moteDict['tableData'] = tableData moteDict['transId'] = data['transId'] try: moteDict['missed'] = int((floattime() - m.lastCommunication) / m.checkinInterval) except: moteDict['missed'] = 0 if m.lastCommunication is not None: moteDict['lastComm'] = m.lastCommunication else: moteDict['lastComm'] = -1 moteDict['inRapidMode'] = m.inRapidMode motes[str(m.unitId)] = moteDict results['Connected Motes'] = motes # Not implemented: results['Temperature'] = return results