Beispiel #1
0
async def main():
    """Connect to a tunnel, send 2 telegrams and disconnect."""
    xknx = XKNX()
    gatewayscanner = GatewayScanner(xknx)
    gateways = await gatewayscanner.scan()

    if not gateways:
        print("No Gateways found")
        return

    gateway = gateways[0]
    # an individual address will most likely be assigned by the tunnelling server
    xknx.own_address = IndividualAddress("15.15.249")

    print(
        f"Connecting to {gateway.ip_addr}:{gateway.port} from {gateway.local_ip}"
    )

    tunnel = UDPTunnel(
        xknx,
        telegram_received_callback=received_callback,
        gateway_ip=gateway.ip_addr,
        gateway_port=gateway.port,
        local_ip=gateway.local_ip,
        local_port=0,
        route_back=False,
    )

    await tunnel.connect()

    await tunnel.send_telegram(
        Telegram(
            destination_address=GroupAddress("1/0/15"),
            payload=GroupValueWrite(DPTBinary(1)),
        ))
    await asyncio.sleep(2)
    await tunnel.send_telegram(
        Telegram(
            destination_address=GroupAddress("1/0/15"),
            payload=GroupValueWrite(DPTBinary(0)),
        ))
    await asyncio.sleep(2)

    await tunnel.disconnect()
Beispiel #2
0
async def main():
    """Connect to a tunnel, send 2 telegrams and disconnect."""
    xknx = XKNX()
    gatewayscanner = GatewayScanner(xknx)
    gateways = await gatewayscanner.scan()

    if not gateways:
        print("No Gateways found")
        return

    gateway = gateways[0]
    # an individual address will most likely be assigned by the tunnelling server
    xknx.own_address = PhysicalAddress("15.15.249")

    print("Connecting to {}:{} from {}".format(gateway.ip_addr, gateway.port,
                                               gateway.local_ip))

    tunnel = Tunnel(
        xknx,
        local_ip=gateway.local_ip,
        gateway_ip=gateway.ip_addr,
        gateway_port=gateway.port,
    )

    await tunnel.connect_udp()
    await tunnel.connect()

    await tunnel.send_telegram(
        Telegram(GroupAddress("1/0/15"), payload=DPTBinary(1)))
    await asyncio.sleep(2)
    await tunnel.send_telegram(
        Telegram(GroupAddress("1/0/15"), payload=DPTBinary(0)))
    await asyncio.sleep(2)

    await tunnel.connectionstate()
    await tunnel.disconnect()