Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: rework top-level API #76

Merged
merged 21 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 7 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,92 +17,24 @@ 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. CoAP
over DTLS(secure CoAP) is not supported.
Many examples of usage are provided in the examples directory both using a .NET based CoAP server for local testing
and testing using the [coap.me](https://coap.me/) test server. Also a fully populated default configuration
file is present in the examples directory.
Many examples of usage are provided in the examples directory using the [coap.me](https://coap.me/) and [californium](https://www.eclipse.org/californium/) test servers.

# Setup
* Add this as dependency in your `pubspec.yaml`:
````yaml
```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:
````yaml
# An example COAP config file
# Syntax is YAML
# Protocol section
version: "RFC7252" # (this field is required)
defaultPort: 5684
defaultSecurePort: 5684
httpPort: 8080
ackTimeout: 3000 # ms
ackRandomFactor: 1.5
ackTimeoutScale: 2.0
maxRetransmit: 8
maxMessageSize: 1024
defaultBlockSize: 512
blockwiseStatusLifetime: 60000 # ms
useRandomIDStart: true
poolUdpConnectionsByClient: false
notificationMaxAge: 128000 # ms
notificationCheckIntervalTime: 86400000 # ms
notificationCheckIntervalCount: 100 # ms
notificationReregistrationBackoff: 2000 # ms
cropRotationPeriod: 2000 # ms
exchangeLifetime: 1247000 # ms
markAndSweepInterval: 10000 # ms
channelReceivePacketSize: 2048
deduplicator: "MarkAndSweep" # CropRotayion or Noop
# Logging section
# Target is none or console
logTarget: "console"
# Log levels
logError: "true"
logDebug: "true"
logWarn: "true"
logInfo: "true"
````
This is a valid configuration file with all possible properties: [examples/config/coap_config.yaml](./examples/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.
# Example
This is a Dart Native program example that uses the [coap.me](https://coap.me/) server to fetch the word "world". Note that to run it you will need to generate your own configuration file.
````dart
import 'dart:async';
import 'dart:io';
import 'package:coap/coap.dart';
import '../config/coap_config_debug.dart';
FutureOr<void> main(List<String> args) async {
// Create a configuration class. Logging levels can be specified in
// the configuration file
final conf = CoapConfigDebug();
// Build the request uri, note that the request paths/query parameters can be changed
// on the request anytime after this initial setup.
const host = 'coap.me';
final uri = Uri(scheme: 'coap', host: host, port: conf.defaultPort);
// Create the client.
// The method we are using creates its own request so we do not
// need to supply one.
// The current request is always available from the client.
final client = CoapClient(uri, conf);
// Adjust the response timeout if needed, defaults to 32767 milliseconds
//client.timeout = 10000;
// Create the request for the get request
final request = CoapRequest.newGet();
request.addUriPath('hello');
client.request = request;
print('EXAMPLE - Sending get request to $host, waiting for response....');
final response = await client.get();
print('EXAMPLE - response received');
print(response.payloadString);
// Clean up
client.close();
}
````

See the [examples](./examples/) for example usage.
4 changes: 0 additions & 4 deletions example/README.md

This file was deleted.

47 changes: 0 additions & 47 deletions example/blockwise_xfer.dart

This file was deleted.

23 changes: 0 additions & 23 deletions example/coap_example.dart

This file was deleted.

97 changes: 0 additions & 97 deletions example/config/coap_config.dart

This file was deleted.

36 changes: 0 additions & 36 deletions example/config/coap_config.yaml

This file was deleted.

44 changes: 0 additions & 44 deletions example/discover_resources.dart

This file was deleted.

37 changes: 0 additions & 37 deletions example/flutter_example/.gitignore

This file was deleted.

Loading