Build Status

coap

A CoAP client library for Dart developers. The Constrained Application Protocol (CoAP) is a RESTful web transfer protocol for resource-constrained networks and nodes. COAP is an implementation in Dart providing CoAP-based services to Dart applications. The code is a port from the C# .NET project CoAP.NET. The dart implementation is that of a CoAP client only, not a server although the CoAP.NET project does supply a server. The COAP client provides many high level functions to control the request/response nature of the CoAP protocol, fine grained control however can be obtained by users directly constructing their own request messages. Configuration is achieved by editing a yaml based config file containing many of CoAP protocol configurations. This is a full implementation of the CoAP protocol including block wise transfer, deduplication, transmission retries using request/response token/id matching, piggy-backed and separate response handling is also supported. Proxying options can be set in request messages however full proxying support is not guaranteed. All CoAP options(if-match, if-none match, uri path/query, location path/query, content format, max age, etags et al.) are supported

Observation of resources is supported with the client 'listening' for observed resource updates when configured for this. The client supports both IPV4 and IPV6 communications and multicast operation.

Experimental CoAPS support (secure CoAP over DTLS) is provided with via an OpenSSL binding using the dtls library for certificate support and an Eclipse tinydtls binding for Pre-Shared Keys and Raw Public Keys. In order to use CoAPS, OpenSSL and/or tinydtls binaries need to be available on your/the target system, and you need to enable at least one of the two backends in the config you are using.

For Flutter apps, you can provide tinydtls binaries for Linux, Android, and Windows via the Plugin dart_tinydtls_libs. Alternatively, you can also download the binaries directly from the Plugin's GitHub Repository.

Many examples of usage are provided in the examples directory using the coap.me and californium test servers.

Setup

  • Add this as dependency in your pubspec.yaml:
dependencies:
  coap:
  • Create a .yaml file containing your CoAP's configurations.
    • The file name must be separated by _. Example: coap_config
    • The file name must start with coap_config
      • Example: coap_config_all. This will generate a file called CoapConfigAll that you will use in your code.
      • Example: coap_config_debug. This will generate a file called CoapConfigDebug that you will use in your code.
      • This file must contains at least the protocol version. See the example bellow. This is a valid configuration file with all possible properties: example/config/coap_config.yaml.
  • Run the command that will generate the configuration class.
    • Run pub run build_runner build in a Dart project;
    • Run flutter pub run build_runner build in a Flutter project; After running the command above the configuration class will be generated next to the .yaml configuration file.

See the examples for example usage.

Libraries

builder
coap
coap_config_all
coap_config_default
coap_config_openssl
coap_config_tinydtls