Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
/ qtcoap Public archive

Provides a CoAP client module for the Qt framework

Notifications You must be signed in to change notification settings

Witekio/qtcoap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Module merged into Qt, see Qt Coap

This repository contains the original work by Witekio to create a new Qt module adding CoAP protocol support. This work is now hosted and maintained by The Qt Company and community, here.

Introduction

This is the Qt CoAP module repository. CoAP is a protocol for IoT devices, and machine to machine communication. The full specification can be found in RFC 7252.

Supported features

  • CoAP Client
  • Send GET/POST/PUT/DELETE requests
  • Discover resources (single server)
  • Observe resources and cancel the observation
  • Blockwise requests and replies
  • Confirmable and non-confirmable messages
  • Some options can be added to the request
  • Replies can be received in a separate or piggybacked message

Unsupported yet

  • Multicast discovery
  • DTLS
  • CoAP Server

How to use the library

GET/POST/PUT/DELETE requests

QCoapClient* client = new QCoapClient(this);
connect(client, &QCoapClient::finished, this, &MyClass::onFinished);
client->get(QUrl("coap://coap.me/test"));
client->put(QUrl("coap://coap.me/test"), QByteArray("payload"));

or

QCoapReply* reply = client->get(QCoapRequest("coap://coap.me/test"));
connect(reply, &QCoapReply::finished, this, &MyClass::onFinished);

The slot connected to the QCoapReply::finished(QCoapReply *) signal can use the QCoapReply object like a QIODevice object.

OBSERVE requests

Observe requests are used to receive automatic server notifications for a resource. For Observe requests specifically, you can use the QCoapReply::notified(QCoapReply *, QCoapMessage) signal to handle notifications from the CoAP server.

QCoapRequest request = QCoapRequest("coap://coap.me/obs");
QCoapReply* reply = client->observe(request);
connect(reply, &QCoapReply::notified, this, &MyClass::onNotified);

You can then stop the observation with

client->cancelObserve(reply);

The notified signal will provide the QCoapReply and most recent message.

DISCOVERY requests

For machine to machine communication, CoAP Discovery requests is used to query the resources available to an endpoint, or to the complete network.

QCoapDiscoveryReply* reply = client->discover("coap://coap.me/");
connect(reply, &QCoapReply::discovered, this, &MyClass::onDiscovered);

The signal discovered can be triggered multiple times, and will provide the list of resources returns by the server(s).

Automated tests

Automated tests require a Californium plugtest server. Plugtest is a CoAP server used to test the main features of the CoAP protocol. The following command starts a plugtest server using Docker.

docker run --name coap-test-server -d --rm -p 5683:5683/udp aleravat/coap-test-server:latest

Automated tests require COAP_TEST_SERVER_IP environment variable to be set, containing Plugtest server IP address. This address will be used to connect to the Plugtest server on port 5683.

The IP address of the docker container can found identified by:

  1. Retrieve the container id with docker ps
$ docker ps
CONTAINER ID        IMAGE                                           [...]
826073e84e7f        aleravat/coap-test-server:latest                [...]
  1. Get the IP address with docker inspect <container_id> | grep IPAddress
$ docker inspect 826073e84e7f | grep IPAddress
[...]
        "IPAddress": "172.17.0.3",
[...]
  1. Set the environment variable in QtCreator, or in a the terminal used export COAP_TEST_SERVER_IP="172.17.0.3"

About

Provides a CoAP client module for the Qt framework

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages