GithubHelp home page GithubHelp logo

isabella232 / qtcoap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qt/qtcoap

0.0 0.0 0.0 863 KB

Qt CoAP client module

License: Other

Shell 0.13% C++ 96.46% Python 0.40% C 0.14% CSS 0.70% CMake 2.17%

qtcoap's Introduction

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

  • 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.

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

For multicast discovery use one of the groups from the QtCoap::MulticastGroup enum, instead of specifying the discovery path:

QCoapResourceDiscoveryReply *reply = client->discover(QtCoap::AllCoapNodesIPv6LinkLocal);

If no group is specified, QtCoap::AllCoapNodesIPv4 will be used by default.

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

Using security

The following example code can be used to secure CoAP communication:

QCoapClient* client = new QCoapClient(this, QtCoap::PreSharedKey);
QCoapSecurityConfiguration config;
config.setPreSharedKey("secretPSK");
config.setIdentity("Client_identity");
client->setSecurityConfiguration(config);

To use X.509 certificate-based security use QtCoap::Certificate for the security mode. QtCoap::RawPublicKey mode is not supported yet.

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"

qtcoap's People

Contributors

alcroito avatar dansoqt avatar diseraluca-qt avatar ediosyncratic avatar friedemannkleint avatar gladhorn avatar iieklund avatar issam-b avatar jaheikk avatar jobor avatar kaheimri avatar kkoehne avatar konstantinritt avatar leena-miettinen avatar lugerard avatar marc-kdab avatar marcmutz avatar migronof avatar ossilator avatar paulwicking avatar pixep avatar semlanik avatar thiagomacieira avatar torarnv avatar toreinio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.