Пример #1
0
async def test_ws_remote_server(event_loop):
    p1 = next(port)
    p2 = next(port)

    start_server = websockets.serve(my_server, 'localhost', p2)
    x = await start_server

    line1 = ns.WSLine(port=p1)
    line2 = ns.WSLine(port=p2, remote_is_server=True)

    ns.junction.route(line1, line2)

    await ns.junction.init()

    sock = await ns.wsconnect('0.0.0.0', p1)
    await sock.send('hola\n')
    
    #await sock.close()

    await asyncio.sleep(3)
    await ns.junction.shutdown()

    x.close()
    await x.wait_closed()
    cancel_tasks()
Пример #2
0
async def test_ws_remote_connection_refused(event_loop):
    p1 = next(port)
    p2 = next(port)

    line1 = ns.WSLine(port=p1)
    line2 = ns.WSLine(port=p2, remote_is_server=True)

    await ns.junction.init()

    await asyncio.sleep(3)

    await ns.junction.shutdown()
    cancel_tasks()
Пример #3
0
async def test_junction_ws(event_loop, shutdown):

    port1 = 3010
    port2 = 3011
    line1 = ns.WSLine(port=port1)
    line2 = ns.WSLine(port=port2)

    ns.junction.route(line1, line2)

    task = asyncio.ensure_future(ws_run(port1, port2))
    await asyncio.sleep(0.1)
    await ns.junction.init()

    await task

    await shutdown()
Пример #4
0
async def test_ws_connection_closed(event_loop):
    p1 = next(port)
    p2 = next(port)

    line1 = ns.WSLine(port=p1)
    line2 = ns.WSLine(port=p2)

    await ns.junction.init()

    sock = await ns.wsconnect('0.0.0.0', p1)

    await asyncio.sleep(0.2)
    await sock.close()

    await ns.junction.shutdown()
    cancel_tasks()
Пример #5
0
async def test_tcp_to_ws(event_loop):
    p1 = next(port)
    p2 = next(port)

    start_server = websockets.serve(my_server, 'localhost', p2)
    x = await start_server

    line1 = ns.TcpLine(port=p1)
    line2 = ns.WSLine(port=p2, remote_is_server=True)

    ns.junction.route(line1, line2)

    await ns.junction.init()

    profile = ns.msg.Profile(uid='uid', pwd='pwd')
    sock = await ns.connect('0.0.0.0', p1)
    await ns.proto_send(sock, profile)
    
    #await sock.close()

    await asyncio.sleep(3)
    await ns.junction.shutdown()

    x.close()
    await x.wait_closed()
    cancel_tasks()
Пример #6
0
async def test_mqtt(event_loop):
    """ mqtt line linked to tcp and ws lines
    """
    topic = "a/b"

    # start broker
    broker = hbmqtt.broker.Broker(CONFIG)
    await broker.start()

    # start the junction
    port1 = 1883
    port2 = 3001
    port3 = 9000

    line1 = ns.MqttLine(topic=topic, port=port1)
    line2 = ns.TcpLine(port=port2)
    line3 = ns.WSLine(port=port3)

    ns.junction.route(line1, line2)
    ns.junction.route(line1, line3)

    await ns.junction.init()

    await asyncio.sleep(0.1)

    #start tcp client
    channel = await ns.connect('0.0.0.0', port2)

    #start ws client
    ws_socket = await ns.wsconnect('0.0.0.0', port3)

    #start mqtt client
    mqtt_client = hbmqtt.client.MQTTClient()
    await mqtt_client.connect('mqtt://127.0.0.1')

    await mqtt_client.subscribe([('hb/' + topic, QOS_1)])

    #send a message from tcp client
    ascii_msg = b'pippo\n'
    await ns.msg_send(channel, ascii_msg)

    json_msg = "'JSON_MSG'"
    await ws_socket.send(json_msg)

    #wait for a mqtt packet
    message = await mqtt_client.deliver_message()
    LOG.debug("received mqtt message: %s", message.publish_packet.payload.data)
    await mqtt_client.publish(topic, b'PLUTO\n', QOS_1)

    response = await ns.msg_receive(channel)

    #print the response from mqtt
    LOG.debug("response from mqtt client: %s", response)

    await mqtt_client.disconnect()
    await ns.junction.shutdown()
    await broker.shutdown()
    cancel_tasks()
Пример #7
0
    async def init_tcp_junction_impl(expect_json=False, src_to_dst=None):
        port1 = next(port)
        port2 = next(port)
        line1 = ns.TcpLine(port=port1)
        line2 = ns.WSLine(port=port2)

        ns.junction.route(line1, line2, src_to_dst=src_to_dst)
        await ns.junction.init()
        await asyncio.sleep(0.1)

        return (port1, port2)
Пример #8
0
def main(serial):

    web_page = ns.WSLine(port=3000)
    if (serial):
        # the real board
        board = ns.SerialLine()
    else:
        # a software simulator
        board = ns.TcpLine(port=2001)

    ns.junction.route(src=web_page,
                      dst=board,
                      src_to_dst=to_protobuf,
                      dst_to_src=to_json)

    ns.junction.run()
Пример #9
0
def main(serial):
    """Configure the junction endpoints
    """

    web_page = ns.WSLine(port=3000)
    if serial:
        # the real board
        board = ns.SerialLine()
    else:
        # a software simulator or a tcp connected cc3200 board
        board = ns.TcpLine(port=3001)

    script = ns.TcpLine(port=3002)  # scripting endpoint, eg provisioning

    # ns.junction.route(src=web_page, dst=board, src_to_dst=to_protobuf, dst_to_src=to_json)
    ns.junction.route(src=web_page,
                      dst=board,
                      src_to_dst=to_protobuf,
                      dst_to_src=to_json)

    ns.junction.route(src=board, dst=script)

    ns.junction.run()
Пример #10
0
async def test_junction_ws_init(event_loop, shutdown):
    board = ns.WSLine(port=next(port))
    await ns.junction.init()

    await shutdown()