Пример #1
0
        raise Exception("No Bridge Detected")

#cloud_variable_ep = CloudVariableEp(hub_variables)

#this class can be used to poll an endpoint, I didn't find a real use for it.
# ep_poller = EndpointPoller(translations, hub_variables)

serial_handler = SerialHandler(selected)

# while true swap between polling EPs and receiving / sending.
while (True):

    # if the bridged micro:bit has sent us data, process
    if serial_handler.buffered() > 0:
        rPacket = RadioPacket(serial_handler.read_packet())
        translationsFile = open("./translations.json")
        translations = json.load(translationsFile)
        requestHandler = RequestHandler(rPacket, translations, hub_variables,
                                        None)
        bytes = requestHandler.handleRequest()
        serial_handler.write_packet(bytes)
#   else:
# otherwise check if our asynchronous socket io ep has packets to transmit.
#      bytes = cloud_variable_ep.drain()

#     if len(bytes) > 0:
#        serial_handler.write_packet(bytes)

# prevent burning the processor :)
    sleep(0.01)