:py:mod:`expliot.core.protocols.internet.coap` ============================================== .. py:module:: expliot.core.protocols.internet.coap .. autoapi-nested-parse:: Wrapper for the CoAP communication. Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: expliot.core.protocols.internet.coap.Discovery expliot.core.protocols.internet.coap.WKResource expliot.core.protocols.internet.coap.CoapClient expliot.core.protocols.internet.coap.CoapDiscovery Functions ~~~~~~~~~ .. autoapisummary:: expliot.core.protocols.internet.coap.bstr Attributes ~~~~~~~~~~ .. autoapisummary:: expliot.core.protocols.internet.coap.COAP_STR expliot.core.protocols.internet.coap.COAP_PORT expliot.core.protocols.internet.coap.ROOTPATH expliot.core.protocols.internet.coap.WKRPATH .. py:function:: bstr(byts) Converts a bytes or a bytearray object to a str (string) preserving the binary data as is. Args: byts(bytes or bytearray): A bytes/bytearray object that needs to be converted to binary string. Returns: str: The converted string that preserves the binary data as is. .. py:class:: Discovery Representation of a discovery entity. .. py:method:: devices() :abstractmethod: Return the found devices. This should be called after scan() Args: Nothing Returns: list: List of all devices discovered in scan() .. py:method:: services() :abstractmethod: Return the found services. This should be called after scan() Args: Nothing Returns: list: List of all devices discovered in scan() .. py:method:: scan() :abstractmethod: Scan for devices or services depending on the Discovery type Args: Nothing Returns: Nothing .. py:data:: COAP_STR :annotation: = coap .. py:data:: COAP_PORT :annotation: = 5683 .. py:data:: ROOTPATH :annotation: = / .. py:data:: WKRPATH :annotation: = /.well-known/core .. py:class:: WKResource(link) A resource on the CoAP server as advertised on "/.well-known/core" in CoRE Link Format (RFC 6690). For more details on CoRE Link format, https://tools.ietf.org/html/rfc6690 .. py:method:: parse(link) Parses the link provided and extracts the attributes from it. An example of the link format: ';title="Foo Bar";if="Foo";rt="bar";sz=100' More details about the syntax can be found here - https://tools.ietf.org/html/rfc6690#page-6 Args: link (bytes or str): The link format containing a single link resource from the response. Returns: Nothing .. py:method:: attributes() Returns a dict containing all attributes of a sinle link. The resource path is stored in "path" key for ease. Returns: dict: The dict containing all the attributes found in the parsed link. .. py:method:: path() Returns the path of the well-known resource .. py:class:: CoapClient(host, port=COAP_PORT, secure=False) A CoAP Client Object .. py:method:: response_dict(response) :staticmethod: Creates and returns a dict containing response code, string and payload from the Response Object. Args: response (aiocoap.message.Message): Response message received from the CoAP server. Returns: dict: Dict object containing response code, string and payload .. py:method:: makeuri(path=None, secure=False) Make a CoAP URI from the details provided Args: path (str): The resource path of the request secure (bool): Add s for secure or not Returns: str: The URI created using the parameters .. py:method:: request(method=GET, path=None, payload=b'', secure=True) Wrapper on async_request() to make a sync request. Args: Check async_request() Returns: Check async_request() .. py:method:: async_request(method=GET, path=None, payload=b'', secure=False) :async: Send a request to a CoAP server. Args: method (aiocoap.numbers.codes.Code): The request method e.g. GET path (str): The resource path of the request payload (bytes): The payload to send if any secure (bool): plain text (coap) or secure (coaps) request Returns: aiocoap.message.Message: Response message .. py:method:: get(path=None, secure=False) Wrapper on request() to make a GET request. Args: Check async_request() Returns: Check async_request() .. py:method:: post(path=None, payload=b'', secure=False) Wrapper on request() to make a POST request. Args: Check async_request() Returns: Check async_request() .. py:method:: put(path=None, payload=b'', secure=False) Wrapper on request() to make a PUT request. Args: Check async_request() Returns: Check async_request() .. py:method:: delete(path=None, secure=False) Wrapper on request() to make a DELETE request. Args: Check async_request() Returns: Check async_request() .. py:class:: CoapDiscovery(host, port=COAP_PORT) Bases: :py:obj:`expliot.core.discovery.Discovery` Discovery for Resources on a CoAP server. .. py:method:: scan() Scan for resources advertised by the CoAP server on "/.well-known/core" in CoRE Link Format (RFC 6690). For more details on CoRE Link Format check - https://tools.ietf.org/html/rfc6690 Args: Nothing Returns: Nothing .. py:method:: services() Returns the found resources on the CoAP server. Args: Nothing Returns: list: List of resources found