Skip to content

Network

skydance.network.session.Session

A session object handling connection re-creation in case of its failure.

__aenter__(self) async special

Return auto-closing context manager.

close(self) async

Close connection.

read(self, n=-1) async

Read up to n bytes from the transport.

This is a wrapper on top of asyncio.streams.StreamReader.read()

write(self, data) async

Write a data to the transport and drain immediatelly.

This is a wrapper on top of asyncio.streams.StreamWriter.write()

Discovery

skydance.network.discovery.discover_ips_by_mac(ip, *, broadcast=False, retry=3, sleep=1) async

Discover Skydance Wi-Fi relays.

Parameters:

Name Type Description Default
ip str

IP target of discovery protocol. Can be either individual device IP (to get its MAC address), or broadcast address (to discover present devices).

required
broadcast bool

Whether the IP is broadcast address. On most systems, requires sudo to operate (to bind 0.0.0.0).

False
retry int

How many times to retry sending discovery request.

3
sleep float

Sleep time between subsequent discovery requests.

1

Returns:

Type Description
Mapping[bytes, Iterable[ipaddress.IPv4Address]]

Mapping of found Skydance Wi-Fi relays. Their MAC address is the key and their IP addresses are the values (stored in set).

skydance.network.discovery.DiscoveryProtocol

Implement discovery protocol used by Skydance Wi-Fi relays.

Skydance uses HF-LPT130 chip for network communication (Wi-Fi settings, passing network data to another chips inside, network discovery).

See Also: - HF-LPT130 product page - Similar protocol description

Examples:

>>> protocol = DiscoveryProtocol()
>>> await asyncio.get_event_loop().create_datagram_endpoint(
>>>     lambda: protocol,
>>>     remote_addr=("192.168.1.255", DiscoveryProtocol.PORT),
>>>     allow_broadcast=True,
>>> )
>>>
>>> for _ in range(3):
>>>     protocol.send_discovery_request()
>>>     await asyncio.sleep(1)
>>>
>>> for mac, ips in protocol.get_discovery_result():
>>>     print(mac.hex(":"), *ips)
98:d8:63:a5:9e:5c 192.168.1.5
98:d8:63:a5:8a:35 192.168.1.8 192.168.1.9

skydance.network.buffer.Buffer

A buffer which allows feeding chunks of messages and reading them out complete.

It is specificaly tailored for:

  • Protocols sending byte messages ending with pre-defined tail sequence.
  • Tail sequence length must be 2 bytes.

is_message_ready property readonly

Return whether at least one message is ready to read.

__init__(self, tail) special

Create a Buffer.

Parameters:

Name Type Description Default
tail bytes

Tail byte sequence.

required

feed(self, chunk)

Feed byte chunk into a buffer.

Update count of messages contained in the buffer.

Parameters:

Name Type Description Default
chunk bytes

Byte chunk of any length.

required

get_message(self)

Return a single message.

Exceptions:

Type Description
ValueError

If message is incomplete.

reset(self)

Clear state without a need to create a new one.