Beispiel #1
0
def onRadiation():
    # Get back to our main eventlet thread using a Queue
    # to transfer the signal from the interrupt thread
    # to the main thread.
    # TODO Or use a Python socketio client to communicate with this server.
    q.put_nowait(None)


def listenToQueue():
    while 1:
        try:
            data = q.get_nowait()
            socketio.emit("ray", data)
            readings = radiationWatch.status()
            readings["timestamp"] = datetime.datetime.now().isoformat() + "Z"
            # Send current readings.
            socketio.emit("readings", readings, json=True)
            # Persist historical data.
            history.append(readings)
            while len(history) > HISTORY_LENGTH:
                del history[0]
            # Dispatch readings.
            forwarder.dispatch(readings)
        except queue.Empty:
            eventlet.sleep(0.1)


eventlet.spawn_n(listenToQueue)
radiationWatch.registerRadiationCallback(onRadiation)