Library coap
An implementation of CoAP https://tools.ietf.org/html/rfc7252
This library does not currently implement the entire CoAP protocol, only those behaviours which are necessary for existing scripts are included. Extending to accommodate additional control packets should not be difficult.
Author:
Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html
Source: https://svn.nmap.org/nmap/nselib/coap.lua
Functions
- COAP.build (options, payload)
Builds a CoAP message.
- COAP.header.build See section "3. Message Format" of the standard. (options)
Builds a CoAP message header.
- COAP.header.codes.build (name)
Builds a CoAP message request or response code.
- COAP.header.codes.parse (buf, pos)
Parses a CoAP request or response code.
- COAP.header.find_option (hdr, name)
Finds the first instance of an option type in a header.
- COAP.header.find_options (hdr, name, max)
Finds all instances of an option type in a header.
- COAP.header.options.accept.build 5.10.4. Accept (val)
Builds a CoAP message header Accept option.
- COAP.header.options.accept.parse 5.10.4. Accept (buf)
Parses a CoAP message header Accept option.
- COAP.header.options.block.build For large payloads that would be too large for the underlying transport, block transfers exist. This allows endpoints to transfer payloads in small chunks. This is very common, and is frequently used when transferring the <code>/.well-known/core</code> resource due to its size. As of the writing of this function, the block transfer definition is a draft undergoing active revision. https://tools.ietf.org/html/draft-ietf-core-block-19 (val)
Builds a CoAP message header Block option.
- COAP.header.options.block.parse https://tools.ietf.org/html/draft-ietf-core-block-19 (buf)
Parses a CoAP message header Block option.
- COAP.header.options.block1.build https://tools.ietf.org/html/draft-ietf-core-block-19 (val)
Builds a CoAP message header Block1 option.
- COAP.header.options.block1.parse https://tools.ietf.org/html/draft-ietf-core-block-19 (buf)
Parses a CoAP message header Block1 option.
- COAP.header.options.block2.build https://tools.ietf.org/html/draft-ietf-core-block-19 (val)
Builds a CoAP message header Block2 option.
- COAP.header.options.block2.parse https://tools.ietf.org/html/draft-ietf-core-block-19 (buf)
Parses a CoAP message header Block2 option.
- COAP.header.options.build See section "3.1. Option Format" of the standard. Due to the ordering of options and using delta representation of their identifiers, we process all options at once. The sorting method used is in this function is terrible, but using Lua's sort with a function gave seemingly inconsistent results. We have rolled-our-own stable sort which functions properly. Replacing it is welcome. (options)
Build CoAP message header options.
- COAP.header.options.content_format.build 5.10.3. Content-Format (val)
Builds a CoAP message header Content-Format option.
- COAP.header.options.content_format.parse 5.10.3. Content-Format (buf)
Parses a CoAP message header Content-Format option.
- COAP.header.options.delta_length.build Due to the interleaving of these two fields they are handled together, since they can appear in nine forms, with the first byte holding a nibble for each: 1) D|L 2) D|L D 3) D|L L 4) D|L D D 5) D|L D L 6) D|L L L 7) D|L D D L 8) D|L D L L 9) D|L D D L L The 4 bits reserved in the header for the delta and length are not enough to represent the large numbers required by the options. For this reason there is a 1 or 2-byte field conditionally added to the option's header to extend the range the deltas and lengths can represent. The delta field can represent: Low : 0 as 0000 High: 12 as 1100 With one extra delta byte, it can represent: Low : 13 as 1101 00000000 (13 + 0) High: 268 as 1101 11111111 (13 + 255) With two extra delta bytes, it can represent: Low : 269 as 1110 00000000 00000000 (269 + 0) High: 65804 as 1110 11111111 11111111 (269 + 65535) 3.1. Option Format (delta, length)
Build the variable-length option delta and length field.
- COAP.header.options.delta_length.parse Due to the interleaving of these two fields they are handled together. See <ref>COAP.header.options.delta_length_build</ref> for details. 3.1. Option Format (buf, pos)
Parse the variable-length option delta and length field.
- COAP.header.options.etag.build 5.10.6. ETag 5.10.6.1. ETag as a Response Option 5.10.6.2. ETag as a Request Option (val)
Builds a CoAP message header ETag option.
- COAP.header.options.etag.parse 5.10.6. ETag 5.10.6.1. ETag as a Response Option 5.10.6.2. ETag as a Request Option (buf)
Parses a CoAP message header ETag option.
- COAP.header.options.if_match.build 5.10.8. Conditional Request Options 5.10.8.1. If-Match (val)
Builds a CoAP message header If-Match option.
- COAP.header.options.if_match.parse 5.10.8. Conditional Request Options 5.10.8.1. If-Match (buf)
Parses a CoAP message header If-Match option.
- COAP.header.options.if_none_match.build 5.10.8. Conditional Request Options 5.10.8.2. If-None-Match (val)
Builds a CoAP message header If-None-Match option.
- COAP.header.options.if_none_match.parse 5.10.8. Conditional Request Options 5.10.8.2. If-None-Match (buf)
Parses a CoAP message header If-None-Match option.
- COAP.header.options.location_path.build 5.10.7. Location-Path and Location-Query (val)
Builds a CoAP message header Location-Path option.
- COAP.header.options.location_path.parse 5.10.7. Location-Path and Location-Query (buf)
Parses a CoAP message header Location-Path option.
- COAP.header.options.location_query.build 5.10.7. Location-Path and Location-Query (val)
Builds a CoAP message header Location-Query option.
- COAP.header.options.location_query.parse 5.10.7. Location-Path and Location-Query (buf)
Parses a CoAP message header Location-Query option.
- COAP.header.options.max_age.build 5.10.5. Max-Age (val)
Builds a CoAP message header Max-Age option.
- COAP.header.options.max_age.parse 5.10.5. Max-Age (buf)
Parses a CoAP message header Max-Age option.
- COAP.header.options.parse See section "3.1. Option Format" of the standard. (buf, pos)
Parses a CoAP message's header options.
- COAP.header.options.proxy_scheme.build 5.10.2. Proxy-Uri and Proxy-Scheme (val)
Builds a CoAP message header Proxy-Scheme option.
- COAP.header.options.proxy_scheme.parse (buf)
Parses a CoAP message header Proxy-Scheme option.
- COAP.header.options.proxy_uri.build 5.10.2. Proxy-Uri and Proxy-Scheme (val)
Builds a CoAP message header Proxy-Uri option.
- COAP.header.options.proxy_uri.parse 5.10.2. Proxy-Uri and Proxy-Scheme (buf)
Parses a CoAP message header Proxy-Uri option.
- COAP.header.options.Size1.build 5.10.9. Size1 Option (val)
Builds a CoAP message header Size1 option.
- COAP.header.options.size1.parse 5.10.9. Size1 Option (buf)
Parses a CoAP message header Size1 option.
- COAP.header.options.uri_host.build 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (val)
Builds a CoAP message header Uri-Host option.
- COAP.header.options.uri_host.parse 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (buf)
Parses a CoAP message header Uri-Host option.
- COAP.header.options.uri_path.build 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (val)
Builds a CoAP message header Uri-Path option.
- COAP.header.options.uri_path.parse 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (buf)
Parses a CoAP message header Uri-Path option.
- COAP.header.options.uri_port.build 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (val)
Builds a CoAP message header Uri-Port option.
- COAP.header.options.uri_port.parse 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (buf)
Parses a CoAP message header Uri-Port option.
- COAP.header.options.uri_query.build 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (val)
Builds a CoAP message header Uri-Query option.
- COAP.header.options.uri_query.parse 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (buf)
Parses a CoAP message header Uri-Query option.
- COAP.header.options.value.empty.parse 3.2. Option Value Formats (buf)
Parses a CoAP message Empty header option value.
- COAP.header.options.value.empty.parse 3.2. Option Value Formats (buf)
Parses a CoAP message Empty header option value.
- COAP.header.options.value.opaque.build 3.2. Option Value Formats (str)
Builds a CoAP message Opaque header option value.
- COAP.header.options.value.opaque.parse 3.2. Option Value Formats (buf)
Parses a CoAP message Opaque header option value.
- COAP.header.options.value.string.build 3.2. Option Value Formats (str)
Builds a CoAP message String header option value.
- COAP.header.options.value.string.parse 3.2. Option Value Formats (buf)
Parses a CoAP message String header option value.
- COAP.header.options.value.uint.build 3.2. Option Value Formats (val)
Builds a CoAP message Uint header option value.
- COAP.header.options.value.uint.parse 3.2. Option Value Formats (buf)
Parses a CoAP message Uint header option value.
- COAP.header.parse See section "3. Message Format" of the standard. (buf, pos)
Parses a CoAP message header.
- COAP.parse (buf, pos)
Parses a CoAP message.
- COAP.payload.application_octet_stream.parse https://tools.ietf.org/html/rfc2045 https://tools.ietf.org/html/rfc2046 This function will return its input, since it is assumed to have no additional structure. (hdr, buf)
Parse the Octet Stream payload of a CoAP message.
- COAP.payload.application_xml.parse https://tools.ietf.org/html/rfc3023 This function is unimplemented. (hdr, buf)
Parse the XML payload of a CoAP message.
- COAP.payload.exi.parse https://www.w3.org/TR/2014/REC-exi-20140211/ This function is unimplemented. (hdr, buf)
Parse the EXI payload of a CoAP message.
- COAP.payload.json.parse https://tools.ietf.org/html/rfc7159 (hdr, buf)
Parse the JSON payload of a CoAP message.
- COAP.payload.link_format.parse https://tools.ietf.org/html/rfc6690 This format is complicated enough that parsing it accurately is unlikely to be worth the effort. As a result, we have chosen the following simplifications. 1) URIs can contain any character except '>'. 2) Parameters can have two forms: a) ;name=value-with-semicolons-and-commas-forbidden b) ;name="value-with-semicolons-and-commas-permitted" If there is a need for full parsing, it can be addressed later. (hdr, buf)
Parse the Link Format payload of a CoAP message.
- COAP.payload.parse 5.5. Payloads and Representations Never use this function directly on a payload that has a Block option, as there will only be a partial payload in such a message. The top-level <ref>COAP.parse</ref> is smart enough not to auto-parse messages with partial payloads. (hdr, buf)
Parse the payload of a CoAP message.
- COAP.payload.text_plain.parse https://tools.ietf.org/html/rfc2046 https://tools.ietf.org/html/rfc3676 This function will return its input, since plain text is assumed to have no additional structure. (hdr, buf)
Parse the Plain Text payload of a CoAP message.
- Comm.build (self, options, payload)
Builds a CoAP message.
- Comm.close (self)
Disconnects from the CoAP endpoint.
- Comm.connect (self, options)
Connects to the CoAP endpoint.
- Comm.new (self, host, port, options)
Creates a new Client instance.
- Comm.parse (self, buf, pos)
Parses a CoAP message.
- Comm.receive (self)
Receives an MQTT control packet.
- Comm.send (self, pkt)
Sends a CoAP message.
- Helper.connect (self, options)
Connects to the CoAP endpoint.
- Helper.create (self, host, port, opt, options)
Creates a new Helper instance.
- Helper.receive (self, ids, timeout)
Listens for a response matching a list of types.
- Helper.request (self, options, payload)
Sends a request to the CoAP, and receive a response.
- Helper.send (self, options, payload)
Sends a request to the CoAP endpoint.
Functions
- COAP.build (options, payload)
-
Builds a CoAP message.
Parameters
- options
- Table of options accepted by the desired message build function.
- payload
- String representing the message payload.
Return values:
- status true on success, false on failure.
- response String representing a raw message on success, or containing the error message on failure.
- COAP.header.build See section "3. Message Format" of the standard. (options)
-
Builds a CoAP message header.
Parameters
- options
- Table of options accepted by the desired message build function.
Return values:
- status true on success, false on failure.
- response String representing a raw message header on success, or containing the error message on failure.
- COAP.header.codes.build (name)
-
Builds a CoAP message request or response code.
Parameters
- name
- String naming the desired code.
Return values:
- status true on success, false on failure.
- response String representing a code on success, or containing the error message on failure.
- COAP.header.codes.parse (buf, pos)
-
Parses a CoAP request or response code.
Parameters
- buf
- String from which to parse the code.
- pos
- Position from which to start parsing.
Return values:
- pos String index on success, false on failure.
- response Table representing the code on success, string containing the error message on failure.
- COAP.header.find_option (hdr, name)
-
Finds the first instance of an option type in a header.
Parameters
- hdr
- Table representing a message header.
- name
- String naming an option type.
Return value:
opt Table representing option on success, or nil if one was not found.See also:
- COAP.header.find_options (hdr, name, max)
-
Finds all instances of an option type in a header.
Parameters
- hdr
- Table representing a message header.
- name
- String naming an option type.
- max
- Maximum number of options to return.
Return value:
opts Table containing option all options found, may be empty. - COAP.header.options.accept.build 5.10.4. Accept (val)
-
Builds a CoAP message header Accept option.
Parameters
- val
- Number representing an acceptable content type.
Return value:
str String representing the option's value. - COAP.header.options.accept.parse 5.10.4. Accept (buf)
-
Parses a CoAP message header Accept option.
Parameters
- buf
- String from which to parse the option.
Return value:
val Number representing the option's value. - COAP.header.options.block.build For large payloads that would be too large for the underlying transport, block transfers exist. This allows endpoints to transfer payloads in small chunks. This is very common, and is frequently used when transferring the <code>/.well-known/core</code> resource due to its size. As of the writing of this function, the block transfer definition is a draft undergoing active revision. https://tools.ietf.org/html/draft-ietf-core-block-19 (val)
-
Builds a CoAP message header Block option.
Parameters
- val
- Table representing the block's parameters.
Return value:
str String representing the option's value.See also:
- COAP.header.options.block.parse https://tools.ietf.org/html/draft-ietf-core-block-19 (buf)
-
Parses a CoAP message header Block option.
Parameters
- buf
- String from which to parse the option.
Return value:
val Table representing the option.See also:
- COAP.header.options.block1.build https://tools.ietf.org/html/draft-ietf-core-block-19 (val)
-
Builds a CoAP message header Block1 option.
Parameters
- val
- Table representing the option's parameters.
Return value:
str String representing the option's value.See also:
- COAP.header.options.block1.parse https://tools.ietf.org/html/draft-ietf-core-block-19 (buf)
-
Parses a CoAP message header Block1 option.
Parameters
- buf
- String from which to parse the option.
Return value:
response Table representing the option's value.See also:
- COAP.header.options.block2.build https://tools.ietf.org/html/draft-ietf-core-block-19 (val)
-
Builds a CoAP message header Block2 option.
Parameters
- val
- Table representing the option's parameters.
Return value:
str String representing the option.See also:
- COAP.header.options.block2.parse https://tools.ietf.org/html/draft-ietf-core-block-19 (buf)
-
Parses a CoAP message header Block2 option.
Parameters
- buf
- String from which to parse the option.
Return value:
response Table representing the option's value.See also:
- COAP.header.options.build See section "3.1. Option Format" of the standard. Due to the ordering of options and using delta representation of their identifiers, we process all options at once. The sorting method used is in this function is terrible, but using Lua's sort with a function gave seemingly inconsistent results. We have rolled-our-own stable sort which functions properly. Replacing it is welcome. (options)
-
Build CoAP message header options.
Parameters
- options
- Table of options and their values.
Return value:
response String representing a raw set of options, properly sorted. - COAP.header.options.content_format.build 5.10.3. Content-Format (val)
-
Builds a CoAP message header Content-Format option.
Parameters
- val
- Number representing the payload content format.
Return value:
str String representing the option's value. - COAP.header.options.content_format.parse 5.10.3. Content-Format (buf)
-
Parses a CoAP message header Content-Format option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.delta_length.build Due to the interleaving of these two fields they are handled together, since they can appear in nine forms, with the first byte holding a nibble for each: 1) D|L 2) D|L D 3) D|L L 4) D|L D D 5) D|L D L 6) D|L L L 7) D|L D D L 8) D|L D L L 9) D|L D D L L The 4 bits reserved in the header for the delta and length are not enough to represent the large numbers required by the options. For this reason there is a 1 or 2-byte field conditionally added to the option's header to extend the range the deltas and lengths can represent. The delta field can represent: Low : 0 as 0000 High: 12 as 1100 With one extra delta byte, it can represent: Low : 13 as 1101 00000000 (13 + 0) High: 268 as 1101 11111111 (13 + 255) With two extra delta bytes, it can represent: Low : 269 as 1110 00000000 00000000 (269 + 0) High: 65804 as 1110 11111111 11111111 (269 + 65535) 3.1. Option Format (delta, length)
-
Build the variable-length option delta and length field.
Parameters
- delta
- Number representing the option ID's delta.
- length
- Number representing the length of the option's value.
Return value:
str String representing the delta and length fields. - COAP.header.options.delta_length.parse Due to the interleaving of these two fields they are handled together. See <ref>COAP.header.options.delta_length_build</ref> for details. 3.1. Option Format (buf, pos)
-
Parse the variable-length option delta and length field.
Parameters
- buf
- String from which to parse the fields.
- pos
- Position from which to start parsing.
Return values:
- pos Position at which parsing stopped on success, or false on failure.
- delta Delta value of the option's ID on success, or nil on failure.
- length Length of the option's value on success, or nil on failure.
- err nil on success, or an error message on failure.
- COAP.header.options.etag.build 5.10.6. ETag 5.10.6.1. ETag as a Response Option 5.10.6.2. ETag as a Request Option (val)
-
Builds a CoAP message header ETag option.
Parameters
- val
- String representing the ETag's value.
Return value:
str String representing the option's value. - COAP.header.options.etag.parse 5.10.6. ETag 5.10.6.1. ETag as a Response Option 5.10.6.2. ETag as a Request Option (buf)
-
Parses a CoAP message header ETag option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.if_match.build 5.10.8. Conditional Request Options 5.10.8.1. If-Match (val)
-
Builds a CoAP message header If-Match option.
Parameters
- val
- String representing the condition.
Return value:
str String representing the option's value. - COAP.header.options.if_match.parse 5.10.8. Conditional Request Options 5.10.8.1. If-Match (buf)
-
Parses a CoAP message header If-Match option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.if_none_match.build 5.10.8. Conditional Request Options 5.10.8.2. If-None-Match (val)
-
Builds a CoAP message header If-None-Match option.
Parameters
- val
- Parameter is ignored, existing only to keep API consistent.
Return value:
str Empty string to keep API consistent. - COAP.header.options.if_none_match.parse 5.10.8. Conditional Request Options 5.10.8.2. If-None-Match (buf)
-
Parses a CoAP message header If-None-Match option.
Parameters
- buf
- Parameter is ignored, existing only to keep API consistent.
Return value:
val Nil due to the option being empty. - COAP.header.options.location_path.build 5.10.7. Location-Path and Location-Query (val)
-
Builds a CoAP message header Location-Path option.
Parameters
- val
- String representing a path.
Return value:
str String representing the option's value. - COAP.header.options.location_path.parse 5.10.7. Location-Path and Location-Query (buf)
-
Parses a CoAP message header Location-Path option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.location_query.build 5.10.7. Location-Path and Location-Query (val)
-
Builds a CoAP message header Location-Query option.
Parameters
- val
- String representing the query.
Return value:
str String representing the option's value. - COAP.header.options.location_query.parse 5.10.7. Location-Path and Location-Query (buf)
-
Parses a CoAP message header Location-Query option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.max_age.build 5.10.5. Max-Age (val)
-
Builds a CoAP message header Max-Age option.
Parameters
- val
- Number representing the maximum age.
Return value:
str String representing the option's value - COAP.header.options.max_age.parse 5.10.5. Max-Age (buf)
-
Parses a CoAP message header Max-Age option.
Parameters
- buf
- String from which to parse the option.
Return value:
val Number representing the option's value. - COAP.header.options.parse See section "3.1. Option Format" of the standard. (buf, pos)
-
Parses a CoAP message's header options.
Parameters
- buf
- String from which to parse the options.
- pos
- Position from which to start parsing.
Return values:
- pos String index on success, false on failure.
- response Table representing options on success, string containing the error message on failure.
- COAP.header.options.proxy_scheme.build 5.10.2. Proxy-Uri and Proxy-Scheme (val)
-
Builds a CoAP message header Proxy-Scheme option.
Parameters
- val
- String representing the proxy scheme.
Return value:
str String representing the option's value. - COAP.header.options.proxy_scheme.parse (buf)
-
Parses a CoAP message header Proxy-Scheme option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.proxy_uri.build 5.10.2. Proxy-Uri and Proxy-Scheme (val)
-
Builds a CoAP message header Proxy-Uri option.
Parameters
- val
- String representing the proxy URI.
Return value:
str String representing the option's value. - COAP.header.options.proxy_uri.parse 5.10.2. Proxy-Uri and Proxy-Scheme (buf)
-
Parses a CoAP message header Proxy-Uri option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.Size1.build 5.10.9. Size1 Option (val)
-
Builds a CoAP message header Size1 option.
Parameters
- val
- Number representing a size.
Return value:
str String representing the option's value. - COAP.header.options.size1.parse 5.10.9. Size1 Option (buf)
-
Parses a CoAP message header Size1 option.
Parameters
- buf
- String from which to parse the option.
Return value:
val Number representing the option's value. - COAP.header.options.uri_host.build 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (val)
-
Builds a CoAP message header Uri-Host option.
Parameters
- val
- String representing the host of the URI.
Return value:
str String representing the option's value. - COAP.header.options.uri_host.parse 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (buf)
-
Parses a CoAP message header Uri-Host option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.uri_path.build 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (val)
-
Builds a CoAP message header Uri-Path option.
Parameters
- val
- String representing a path in the URI.
Return value:
str String representing the option's value. - COAP.header.options.uri_path.parse 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (buf)
-
Parses a CoAP message header Uri-Path option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.uri_port.build 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (val)
-
Builds a CoAP message header Uri-Port option.
Parameters
- val
- Number representing an endpoint's port number.
Return value:
str String representing the option's value. - COAP.header.options.uri_port.parse 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (buf)
-
Parses a CoAP message header Uri-Port option.
Parameters
- buf
- String from which to parse the option.
Return value:
val Number representing the option's value. - COAP.header.options.uri_query.build 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (val)
-
Builds a CoAP message header Uri-Query option.
Parameters
- val
- String representing a query string in the URI.
Return value:
str String representing the option's value. - COAP.header.options.uri_query.parse 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query (buf)
-
Parses a CoAP message header Uri-Query option.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.value.empty.parse 3.2. Option Value Formats (buf)
-
Parses a CoAP message Empty header option value.
Parameters
- buf
- Parameter is ignored, existing only to keep API consistent.
Return value:
val Nil due to the option being empty. - COAP.header.options.value.empty.parse 3.2. Option Value Formats (buf)
-
Parses a CoAP message Empty header option value.
Parameters
- buf
- Parameter is ignored, existing only to keep API consistent.
Return value:
val Nil due to the option being empty. - COAP.header.options.value.opaque.build 3.2. Option Value Formats (str)
-
Builds a CoAP message Opaque header option value.
Parameters
- str
- String representing an opaque option value.
Return value:
str String representing the option's value. - COAP.header.options.value.opaque.parse 3.2. Option Value Formats (buf)
-
Parses a CoAP message Opaque header option value.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.value.string.build 3.2. Option Value Formats (str)
-
Builds a CoAP message String header option value.
Parameters
- str
- String representing a string option value.
Return value:
str String representing the option's value. - COAP.header.options.value.string.parse 3.2. Option Value Formats (buf)
-
Parses a CoAP message String header option value.
Parameters
- buf
- String from which to parse the option.
Return value:
val String representing the option's value. - COAP.header.options.value.uint.build 3.2. Option Value Formats (val)
-
Builds a CoAP message Uint header option value.
Parameters
- val
- Number representing a Uint option value.
Return value:
str String representing the option's value. - COAP.header.options.value.uint.parse 3.2. Option Value Formats (buf)
-
Parses a CoAP message Uint header option value.
Parameters
- buf
- String from which to parse the option.
Return value:
val Number representing the option's value. - COAP.header.parse See section "3. Message Format" of the standard. (buf, pos)
-
Parses a CoAP message header.
Parameters
- buf
- String from which to parse the header.
- pos
- Position from which to start parsing.
Return values:
- pos String index on success, false on failure.
- response Table representing a message header on success, string containing the error message on failure.
- COAP.parse (buf, pos)
-
Parses a CoAP message.
Parameters
- buf
- String from which to parse the message.
- pos
- Position from which to start parsing.
Return values:
- pos String index on success, false on failure.
- response Table representing a message on success, string containing the error message on failure.
- COAP.payload.application_octet_stream.parse https://tools.ietf.org/html/rfc2045 https://tools.ietf.org/html/rfc2046 This function will return its input, since it is assumed to have no additional structure. (hdr, buf)
-
Parse the Octet Stream payload of a CoAP message.
Parameters
- hdr
- Table representing a message header.
- buf
- String from which to parse the payload.
Return values:
- status True on success, false on failure.
- val String containing parsed payload on success, string containing the error message on failure.
- COAP.payload.application_xml.parse https://tools.ietf.org/html/rfc3023 This function is unimplemented. (hdr, buf)
-
Parse the XML payload of a CoAP message.
Parameters
- hdr
- Table representing a message header.
- buf
- String from which to parse the payload.
Return values:
- status True on success, false on failure.
- response Object containing parsed payload on success, string containing the error message on failure.
- COAP.payload.exi.parse https://www.w3.org/TR/2014/REC-exi-20140211/ This function is unimplemented. (hdr, buf)
-
Parse the EXI payload of a CoAP message.
Parameters
- hdr
- Table representing a message header.
- buf
- String from which to parse the payload.
Return values:
- status True on success, false on failure.
- response Object containing parsed payload on success, string containing the error message on failure.
- COAP.payload.json.parse https://tools.ietf.org/html/rfc7159 (hdr, buf)
-
Parse the JSON payload of a CoAP message.
Parameters
- hdr
- Table representing a message header.
- buf
- String from which to parse the payload.
Return values:
- status True on success, false on failure.
- response Object containing parsed payload on success, string containing the error message on failure.
- COAP.payload.link_format.parse https://tools.ietf.org/html/rfc6690 This format is complicated enough that parsing it accurately is unlikely to be worth the effort. As a result, we have chosen the following simplifications. 1) URIs can contain any character except '>'. 2) Parameters can have two forms: a) ;name=value-with-semicolons-and-commas-forbidden b) ;name="value-with-semicolons-and-commas-permitted" If there is a need for full parsing, it can be addressed later. (hdr, buf)
-
Parse the Link Format payload of a CoAP message.
Parameters
- hdr
- Table representing a message header.
- buf
- String from which to parse the payload.
Return values:
- status True on success, false on failure.
- val Table containing parsed payload on success, string containing the error message on failure.
- COAP.payload.parse 5.5. Payloads and Representations Never use this function directly on a payload that has a Block option, as there will only be a partial payload in such a message. The top-level <ref>COAP.parse</ref> is smart enough not to auto-parse messages with partial payloads. (hdr, buf)
-
Parse the payload of a CoAP message.
Parameters
- hdr
- Table representing a message header.
- buf
- String from which to parse the payload.
Return values:
- status True on success, false on failure.
- val Object containing parsed payload on success, string containing the error message on failure.
- COAP.payload.text_plain.parse https://tools.ietf.org/html/rfc2046 https://tools.ietf.org/html/rfc3676 This function will return its input, since plain text is assumed to have no additional structure. (hdr, buf)
-
Parse the Plain Text payload of a CoAP message.
Parameters
- hdr
- Table representing a message header.
- buf
- String from which to parse the payload.
Return values:
- status True on success, false on failure.
- val String containing parsed payload on success, string containing the error message on failure.
- Comm.build (self, options, payload)
-
Builds a CoAP message.
Parameters
- self
- options
- Table of options accepted by the requested type of message.
- payload
Return values:
- status true on success, false on failure.
- response String representing a raw message on success, or containing the error message on failure.
- Comm.close (self)
-
Disconnects from the CoAP endpoint.
Parameters
- self
- Comm.connect (self, options)
-
Connects to the CoAP endpoint.
Parameters
- self
- options
Return values:
- status true on success, false on failure.
- err string containing the error message on failure.
- Comm.new (self, host, port, options)
-
Creates a new Client instance.
Parameters
- self
- host
- String as received by the action method.
- port
- Number as received by the action method.
- options
- Table as received by the action method.
Return value:
o Instance of Client. - Comm.parse (self, buf, pos)
-
Parses a CoAP message.
Parameters
- self
- buf
- String from which to parse the message.
- pos
- Position from which to start parsing.
Return values:
- pos String index on success, false on failure.
- response Table representing a CoAP message on success, string containing the error message on failure.
- Comm.receive (self)
-
Receives an MQTT control packet.
Parameters
- self
Return values:
- status True on success, false on failure.
- response String representing a raw message on success, string containing the error message on failure.
- Comm.send (self, pkt)
-
Sends a CoAP message.
Parameters
- self
- pkt
- String representing a raw message.
Return values:
- status true on success, false on failure.
- err string containing the error message on failure.
- Helper.connect (self, options)
-
Connects to the CoAP endpoint.
Parameters
- self
- options
- Table of options for the initial message.
Return values:
- status True on success, false on failure.
- response Table representing the response on success, string containing the error message on failure.
- Helper.create (self, host, port, opt, options)
-
Creates a new Helper instance.
Parameters
- self
- host
- String as received by the action method.
- port
- Number as received by the action method.
- opt
- options
- Table as received by the action method.
Return value:
o instance of Client - Helper.receive (self, ids, timeout)
-
Listens for a response matching a list of types.
Parameters
- self
- ids
- Table of message IDs to wait for.
- timeout
- Number of seconds to listen for matching response, defaults to 5s.
Return values:
- status True on success, false on failure.
- response Table representing any message on success, string containing the error message on failure.
- Helper.request (self, options, payload)
-
Sends a request to the CoAP, and receive a response.
Parameters
- self
- options
- Table of options for the message.
- payload
- String containing the message body.
Return values:
- status True on success, false on failure.
- response Table representing a message with the corresponding message ID on success, string containing the error message on failure.
- Helper.send (self, options, payload)
-
Sends a request to the CoAP endpoint.
Parameters
- self
- options
- Table of options for the message.
- payload
- Payload of message.
Return values:
- status True on success, false on failure.
- err String containing the error message on failure.