expliot.core.protocols.internet.coap
¶
Wrapper for the CoAP communication.
Package Contents¶
Classes¶
Representation of a discovery entity. |
|
A resource on the CoAP server as advertised on "/.well-known/core" |
|
A CoAP Client Object |
|
Discovery for Resources on a CoAP server. |
Functions¶
|
Converts a bytes or a bytearray object to a str (string) preserving the |
Attributes¶
- expliot.core.protocols.internet.coap.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.
- class expliot.core.protocols.internet.coap.Discovery¶
Representation of a discovery entity.
- abstract devices()¶
Return the found devices. This should be called after scan()
- Args:
Nothing
- Returns:
list: List of all devices discovered in scan()
- abstract services()¶
Return the found services. This should be called after scan()
- Args:
Nothing
- Returns:
list: List of all devices discovered in scan()
- abstract scan()¶
Scan for devices or services depending on the Discovery type
- Args:
Nothing
- Returns:
Nothing
- expliot.core.protocols.internet.coap.COAP_STR = coap¶
- expliot.core.protocols.internet.coap.COAP_PORT = 5683¶
- expliot.core.protocols.internet.coap.ROOTPATH = /¶
- expliot.core.protocols.internet.coap.WKRPATH = /.well-known/core¶
- class expliot.core.protocols.internet.coap.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
- parse(link)¶
Parses the link provided and extracts the attributes from it. An example of the link format: ‘</resurce/path>;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
- 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.
- path()¶
Returns the path of the well-known resource
- class expliot.core.protocols.internet.coap.CoapClient(host, port=COAP_PORT, secure=False)¶
A CoAP Client Object
- static response_dict(response)¶
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
- 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
- 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()
- async async_request(method=GET, path=None, payload=b'', secure=False)¶
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
- get(path=None, secure=False)¶
Wrapper on request() to make a GET request.
- Args:
Check async_request()
- Returns:
Check async_request()
- post(path=None, payload=b'', secure=False)¶
Wrapper on request() to make a POST request.
- Args:
Check async_request()
- Returns:
Check async_request()
- put(path=None, payload=b'', secure=False)¶
Wrapper on request() to make a PUT request.
- Args:
Check async_request()
- Returns:
Check async_request()
- delete(path=None, secure=False)¶
Wrapper on request() to make a DELETE request.
- Args:
Check async_request()
- Returns:
Check async_request()
- class expliot.core.protocols.internet.coap.CoapDiscovery(host, port=COAP_PORT)¶
Bases:
expliot.core.discovery.Discovery
Discovery for Resources on a CoAP server.
- 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
- services()¶
Returns the found resources on the CoAP server.
- Args:
Nothing
- Returns:
list: List of resources found