pamoja.coap

Idiomatic CoAP facade.

CoAP is the transport for links where MQTT is more than the budget allows: it runs over UDP, its headers are a handful of bytes, and a node can fire a reading and forget it rather than holding a session open.

 1"""Idiomatic CoAP facade.
 2
 3CoAP is the transport for links where MQTT is more than the budget allows: it
 4runs over UDP, its headers are a handful of bytes, and a node can fire a reading
 5and forget it rather than holding a session open.
 6"""
 7
 8from __future__ import annotations
 9
10import enum
11
12from pamoja._native import CoapClient, Message
13
14__all__ = [
15    "CoapClient",
16    "Message",
17    "Reliability",
18]
19
20
21class Reliability(str, enum.Enum):
22    """Whether a request is acknowledged and retried."""
23
24    #: Fire and forget: the request is sent once and not acknowledged.
25    NON_CONFIRMABLE = "NonConfirmable"
26    #: The request is acknowledged, and retransmitted until an ACK arrives.
27    CONFIRMABLE = "Confirmable"
class CoapClient:

A CoAP endpoint.

def connect(self, /):

Binds the local socket so the endpoint can carry traffic.

def send(self, /, topic, payload):

Sends a payload to a resource path.

def subscribe(self, /, topic):

Observes a resource path, so messages published to it reach recv.

def recv(self, /):

Waits for the next message on an observed path, or None once closed.

def is_connected(self, /):

Whether the local socket is bound.

def disconnect(self, /):

Releases the socket the endpoint holds.

class Message:

A message that arrived on a subscribed topic.

CoAP and the loopback broker both hand back a topic and a payload, so one class serves them rather than a near-identical type per transport.

payload

The raw payload bytes.

topic

The topic it was published to.

class Reliability(builtins.str, enum.Enum):
22class Reliability(str, enum.Enum):
23    """Whether a request is acknowledged and retried."""
24
25    #: Fire and forget: the request is sent once and not acknowledged.
26    NON_CONFIRMABLE = "NonConfirmable"
27    #: The request is acknowledged, and retransmitted until an ACK arrives.
28    CONFIRMABLE = "Confirmable"

Whether a request is acknowledged and retried.

NON_CONFIRMABLE = <Reliability.NON_CONFIRMABLE: 'NonConfirmable'>
CONFIRMABLE = <Reliability.CONFIRMABLE: 'Confirmable'>