GitHub - shamblett/coap: A Coap package for dart (original) (raw)

pub package Build Status codecov

coap

The Constrained Application Protocol is a RESTful web transfer protocol for resource-constrained networks and nodes. The CoAP library is an implementation in Dart providing a CoAP client, the code was initially a port from the C# .NET project CoAP.NET.

Features

Roadmap

Example

FutureOr main() async { final conf = CoapConfig(); final baseUri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort); final client = CoapClient(baseUri, conf);

try { final response = await client.get('multi-format', accept: CoapMediaType.textPlain); print('/multi-format response payload: ${response.payloadString}'); } on Exception catch (e) { print('CoAP encountered an exception: $e'); }

client.close(); }

For more detailed examples, see examples.

Setup

dependencies: coap: ^4.2.1

devDependencies: build_runner: ^2.1.11

Considerations

Binaries for DTLS

If you are planning to use DTLS with OpenSSL, note that not all platforms support OpenSSL natively (iOS and Windows for example), in which case you need to ship the required binaries with your app. Also see the dtls2 package's README for more information.

Connectivity

If connectivity is lost, the CoAP client will continuously try to re-initalize the socket. The library relies heavily on futures however, which might not survive in Flutter when the app runs in the background or when the display of the device is turned off. In this case, you might need to extend the WidgetsBindingObserver class and re-initialize the CoapClient in didChangeAppLifecycleState on AppLifecycleState.resumed.