Esempio n. 1
0
def runMainLoop():
    lastgoodtime = 0
    port = None
    manualTimeout = 40

    if stomp:
        stomp.connect(clientid="serial port listener",
                      username="******",
                      password="******")

    while (1):
        if time.time() - lastgoodtime > manualTimeout:
            log.warn("XXX Reopening the serial port, no data for %d seconds!",
                     manualTimeout)
            if port:
                port.close()
            port = serial.Serial(options.port, 19200, timeout=10)
        packet = xbee_receiver.find_packet(port)
        if packet:
            xb = xbee_receiver(packet)
        else:
            log.warn("NO PACKET FOUND")
            continue

        try:
            if xb.app_id == xbee.SERIES1_RXPACKET_16:
                lastgoodtime = time.time()
                kp = kpacket.wire_packet(xb.rfdata)
            else:
                log.warn(
                    "Received a packet, but not a normal rx, was instead: %#x",
                    xb.app_id)
                qq = kpacket.wire_packet(xb.rfdata)
                qqhp = kpacket.human_packet(node=xb.address_16,
                                            sensors=qq.sensors)
                log.info("was actually: %s", qqhp)
                lastgoodtime = time.time()
                continue
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        lastgoodtime = time.time()
        hp = kpacket.human_packet(node=xb.address_16, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp),
                      destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
Esempio n. 2
0
def runMainLoop():
    data_queue = Queue.Queue()
    teensy = Usbreader(data_queue)
    teensy.daemon = True
    teensy.start()

    serial = FakeSerial(data_queue)

    if stomp:
        stomp.connect(clientid="teensy usb listener", username="******", password="******")

    while 1:
        packet = xbee_receiver.find_packet(serial)
        if packet:
            xb = xbee_receiver(packet)
        else:
            continue

        try:
            if xb.app_id == xbee.SERIES1_RXPACKET_16:
                kp = kpacket.wire_packet(xb.rfdata)
            else:
                log.warn("Received a packet, but not a normal rx, was instead: %#x", xb.app_id)
                continue
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        hp = kpacket.human_packet(node=xb.address_16, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp), destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
Esempio n. 3
0
def runMainLoop():
    lastgoodtime = 0
    port = None
    manualTimeout = 40

    if stomp:
        stomp.connect(clientid="serial port local listener", username="******", password="******")

    while(1):
        if time.time() - lastgoodtime > manualTimeout:
            log.warn("XXX Reopening the serial port, no data for %d seconds!", manualTimeout)
            if port:
                port.close()
            port = serial.Serial(options.port, 19200, timeout=10)

        wireRx = kpacket.wire_receiver()
        raw = wireRx.find_raw_packet(port)
        if not raw:
            log.warn("NO PACKET FOUND")
            continue

        try:
            kp = kpacket.wire_packet(raw)
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        lastgoodtime = time.time()
        hp = kpacket.human_packet(node=0x0001, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp), destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
def runMainLoop():
    lastgoodtime = 0
    port = None
    manualTimeout = 40

    if mqttc:
        mqttc.connect("localhost")

    while mqttc.loop() == 0:
        if time.time() - lastgoodtime > manualTimeout:
            log.warn("XXX Reopening the serial port, no data for %d seconds!", manualTimeout)
            if port:
                port.close()
            port = serial.Serial(options.port, 19200, timeout=10)
        packet = xbee_receiver.find_packet(port)
        if packet:
            xb = xbee_receiver(packet)
        else:
            log.warn("NO PACKET FOUND")
            continue

        try:
            if xb.app_id == xbee.SERIES1_RXPACKET_16:
                lastgoodtime = time.time()
                kp = kpacket.wire_packet(xb.rfdata)
            else:
                log.warn("Received a packet, but not a normal rx, was instead: %#x", xb.app_id)
                qq = kpacket.wire_packet(xb.rfdata)
                qqhp = kpacket.human_packet(node=xb.address_16, sensors=qq.sensors)
                log.info("was actually: %s", qqhp)
                lastgoodtime = time.time()
                continue
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        lastgoodtime = time.time()
        hp = kpacket.human_packet(node=xb.address_16, sensors=kp.sensors)
        hp.time_received = time.time()
        if mqttc:
            mqttc.publish("karlnet/readings/%d" % hp.node, jsonpickle.encode(hp))
            #stomp.put(jsonpickle.encode(hp), destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
Esempio n. 5
0
def runMainLoop():
    data_queue = Queue.Queue()
    teensy = Usbreader(data_queue)
    teensy.daemon = True
    teensy.start()

    serial = FakeSerial(data_queue)

    if stomp:
        stomp.connect(clientid="teensy usb listener",
                      username="******",
                      password="******")

    while 1:
        packet = xbee_receiver.find_packet(serial)
        if packet:
            xb = xbee_receiver(packet)
        else:
            continue

        try:
            if xb.app_id == xbee.SERIES1_RXPACKET_16:
                kp = kpacket.wire_packet(xb.rfdata)
            else:
                log.warn(
                    "Received a packet, but not a normal rx, was instead: %#x",
                    xb.app_id)
                continue
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        hp = kpacket.human_packet(node=xb.address_16, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp),
                      destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
Esempio n. 6
0
def runMainLoop():
    lastgoodtime = 0
    port = None
    manualTimeout = 40

    if stomp:
        stomp.connect(clientid="serial port local listener",
                      username="******",
                      password="******")

    while (1):
        if time.time() - lastgoodtime > manualTimeout:
            log.warn("XXX Reopening the serial port, no data for %d seconds!",
                     manualTimeout)
            if port:
                port.close()
            port = serial.Serial(options.port, 19200, timeout=10)

        wireRx = kpacket.wire_receiver()
        raw = wireRx.find_raw_packet(port)
        if not raw:
            log.warn("NO PACKET FOUND")
            continue

        try:
            kp = kpacket.wire_packet(raw)
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        lastgoodtime = time.time()
        hp = kpacket.human_packet(node=0x0001, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp),
                      destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)