aiocoap.transports.slipmux module

This module implements slipmux-03, with some adjustments regarding URI design taken from transport-indication: It chooses the pattern {NAME}.dev.alt for devices named /dev/{NAME}, which are treated case-insensitively.

Configuration

While the slipmux transport is implicitly enabled whenever its dependencies are met, it has no effect on servers (because devices are not automatically bound to: a slipmux device is not generally recognizable as such).

To set up server configuration, or for extra options such as the use or creation of UNIX sockets, this transport can be configured by setting aiocoap.config.SlipmuxParameters in the transports configured at context creation (Context.create_client_context() / create_server_context()).

Usage example

Client with physical hardware

Assuming you have a constrained device that suports slipmux connected to a PC as /dev/ttyACM0, you can run:

$ aiocoap-client coap://ttyacm0.dev.alt/.well-known/core

and interact with resources as found there; no further configuration is needed.

Server with test peer

To mock slipmux without a real serial connection, you can configure a slipmux host name to open up a UNIX socket instead. Write this configuration into config-unix-listen.toml:

[transport.slipmux.devices]
my-listener = { unix-listen = "/tmp/coap.socket" }

Then run a server such as the file server:

$ aiocoap-fileserver --server-config config-unix-listen.toml

You can then run a client such as Jelly intreactively with that server:

$ cargo install Jelly
$ Jelly /tmp/coap.socket

Beware that the aiocoap based server needs to be restarted when the client disconnects (see Caveats below).

Client with test peer

You can also run aiocoap as a test client, but as that doesn’t take a file name argument to connect to (because it operates on URIs’ host components), some configuration is necessary. Store this in config-unix-connect.toml:

[transport.slipmux.devices]
my-connection = { unix-connect = "/tmp/coap.socket" }

Then run:

$ aiocoap-client coap://my-connection.dev.alt/.well-known/core --config config-unix-connect.toml

Caveats

While servers do connect automatically to any configured slipmux endpoint, they do not reconnect automatically when that device goes away or is replaced (as may happen when resetting a development board, depending on its USB UART implementation). The same is true for UNIX sockets.

Error handing is generally incomplete when it comes to I/O errors.

This transport is currently not tested automatically, as only the client side is implemented, with no mechanism for acting on (eg.) a UNIX socket instead.


class aiocoap.transports.slipmux.SlipmuxAddress(hostname, interface)

Bases: EndpointAddress

scheme = 'coap'
is_multicast = False
is_multicast_locally = False
property interface
property hostinfo

The authority component of URIs that this endpoint represents when request are sent to it

Note that the presence of a hostinfo does not necessarily mean that globally meaningful or even syntactically valid URI can be constructed out of it; use the uri property for this.

property hostinfo_local

The authority component of URIs that this endpoint represents when requests are sent from it.

As with hostinfo, this does not necessarily produce sufficient input for a URI; use uri_local instead.

property uri_base

The base URI for the peer (typically scheme plus .hostinfo).

This raises error.AnonymousHost when executed on an address whose peer coordinates can not be expressed meaningfully in a URI.

property uri_base_local

The base URI for the local side of this remote.

This raises error.AnonymousHost when executed on an address whose local coordinates can not be expressed meaningfully in a URI.

property blockwise_key

A hashable (ideally, immutable) value that is only the same for remotes from which blocks may be combined. (With all current transports that means that the network addresses need to be in there, and the identity of the security context).

It does not just hinge on the identity of the address object, as a first block may come in an OSCORE group request and follow-ups may come in pairwise requests. (And there might be allowed relaxations on the transport under OSCORE, but that’d need further discussion).

class aiocoap.transports.slipmux.MessageInterfaceSlipmux(params: TransportParameters, ctx: MessageManager, log, loop)

Bases: MessageInterface

Message Interface for Slipmux.

As serial ports generally not be opened multiple times, this does not even try to manage running connections in the Endpoint objects, but spools endpoints until they break, at which point any attempt to send a message reconnects.

This keeps any number of connections open with no attempts to limit them, as the number of serial connections a system has is generally way lower than any RAM limits.

async shutdown()

Deactivate the complete transport, usually irrevertably. When the coroutine returns, the object must have made sure that it can be destructed by means of ref-counting or a garbage collector run.

send(message)

Send a given Message object

async recognize_remote(remote)

Return True if the remote is one belonging to this transport

async determine_remote(message)

Return a value suitable for the message’s remote property based on its .opt.uri_host or .unresolved_remote.

May return None, which indicates that the MessageInterface can not transport the message (typically because it is of the wrong scheme).

async classmethod create_transport_endpoint(params: TransportParameters, ctx: MessageManager, log, loop)
unixlisten_available(remote, protocol)
received(remote, data)
terminated(remote, exception)
class aiocoap.transports.slipmux.SlipmuxProtocol(starting_future, weakinstance, remote_handle, log)

Bases: Protocol

send_control(data: bytes)
connection_made(transport)

Called when a connection is made.

The argument is the transport representing the pipe connection. To receive data, wait for data_received() calls. When the connection is closed, connection_lost() is called.

data_received(data)

Called when some data is received.

The argument is a bytes object.

connection_lost(exc)

Called when the connection is lost or closed.

The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).