expliot.core.protocols.internet.coap¶
Wrapper for the CoAP communication.
Attributes¶
Classes¶
Representation of a discovery entity. |
|
A resource on the CoAP server as advertised. |
|
A CoAP Client Object. |
|
Discover the resources on a CoAP server. |
Functions¶
|
Convert bytes or a bytearray object to a string. |
Package Contents¶
- expliot.core.protocols.internet.coap.bstr(byts)¶
Convert bytes or a bytearray object to a 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.
Reading “/.well-known/core” which is in the CoRE Link Format (RFC 6690). For more details on CoRE Link format, https://tools.ietf.org/html/rfc6690
- _attributes¶
- unknown = []¶
- parse(link)¶
Parse 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()¶
Return 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()¶
Return the path of the well-known resource.
- class expliot.core.protocols.internet.coap.CoapClient(host, port=COAP_PORT, secure=False)¶
A CoAP Client Object.
- host¶
- port = 5683¶
- static response_dict(response)¶
Create and return a dict containing response code.
Based on the string and the 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: The resource path of the request secure (bool): Plain text (coap) or secure (coaps) request
- Returns:
str: The URI created using the parameters
- request(method=GET, path=None, payload=b'', secure=True)¶
Make a sync request.
- 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:
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)¶
Make a GET request.
- Args:
path (str): The resource path of the request secure (bool): plain text (coap) or secure (coaps) request
- Returns:
Check async_request()
- post(path=None, payload=b'', secure=False)¶
Make a POST request.
- Args:
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:
Check async_request()
- put(path=None, payload=b'', secure=False)¶
Make a PUT request.
- Args:
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:
Check async_request()
- delete(path=None, secure=False)¶
Make a DELETE request.
- Args:
path (str): The resource path of the request secure (bool): plain text (coap) or secure (coaps) request
- Returns:
Check async_request()
- class expliot.core.protocols.internet.coap.CoapDiscovery(host, port=COAP_PORT)¶
Bases:
expliot.core.discovery.Discovery
Discover the resources on a CoAP server.
- host¶
- port = 5683¶
- resources = []¶
- scan()¶
Scan for resources advertised by the CoAP server.
- Args:
Nothing
- Returns:
Nothing
- services()¶
Return the found resources on the CoAP server.
- Args:
Nothing
- Returns:
list: List of resources found