@@ -0,0 +1,1854 @@
+#!/usr/bin/env python%0A%0Aimport threading%0Aimport time%0A%0Afrom motes import motes%0Aimport moteconfig%0Aimport sensor_data%0Aimport configuration%0Aimport data_utils%0A%0AisListening = False%0AlistenThread = None%0A%0Adef listenSerial():%0A    global isListening%0A    %0A    while isListening:%0A        for m in motes.getMotes():%0A%0A            length = m.tryRead(binaryToo = moteconfig.instance.configMode)%0A            if length == 0:%0A                continue%0A%0A            if moteconfig.instance.configMode:%0A                for c in m.buffer:%0A                    moteconfig.instance.byteRead(c)%0A                m.buffer = %22%22%0A                continue%0A%0A            while '%5Cn' in m.buffer:%0A                pos = m.buffer.find('%5Cn')%0A                if pos != 0:%0A                    newString = m.buffer%5B:pos%5D.strip()%0A                    saveToDB = configuration.c.getCfgValue(%22saveToDB%22)%0A                    sendToOpenSense = configuration.c.getCfgValue(%22sendToOpenSense%22)%0A                    if saveToDB or sendToOpenSense:%0A                        data_utils.maybeAddDataToDatabase(m.port.port, newString)%0A                    # print %22got%22, newString%0A                    sensor_data.moteData.addNewData(newString, m.port.portstr)%0A                m.buffer = m.buffer%5Bpos + 1:%5D%0A%0A        sensor_data.moteData.fixSizes()%0A        # pause for a bit%0A        time.sleep(0.01)%0A        %0Adef openAllSerial():%0A    global isListening%0A    global listenThread%0A    %0A    if isListening: return%0A    isListening = True%0A    listenThread = threading.Thread(target = listenSerial)%0A    listenThread.start()%0A    for m in motes.getMotes():%0A        m.tryToOpenSerial(False)%0A%0Adef closeAllSerial():%0A    global isListening%0A    global listenThread%0A    %0A    isListening = False%0A    if listenThread:%0A        listenThread.join()%0A        listenThread = None%0A    for m in motes.getMotes():%0A        m.ensureSerialIsClosed()

Add helper tools