Code Monkey home page Code Monkey logo

coapnet's Introduction



NuGet Badge Size Join the chat at https://gitter.im/CoAPnet/community License: MIT

CoAPnet

CoAPnet is a high performance .NET library for CoAPnet based communication. The library runs on macOS, Linux and Windows. It also supports UDP, DTLS, TCP and TLS connections.

Features

Protocol

  • Core protocol (RFC 7252)
  • Block transfer (RFC 7959)
  • Observe (RFC 7641)

General

  • Async support
  • DTLS (up to 1.2) support
  • TLS 1.2 support
  • Extensible communication channels (e.g. In-Memory, TCP, TCP+TLS, UDP, UDP+TLS)
  • Lightweight (only the low level implementation of CoAPnet, no overhead)
  • Performance optimized
  • Interfaces included for mocking and testing
  • Access to internal trace messages
  • Unit tested
  • No external dependencies

Client

  • Communication via TCP (+TLS) or UDP (+DTLS) supported
  • Included core LowLevelCoAPClient with low level functionality
  • Block transfer is supported

Supported frameworks

  • .NET Standard 1.3+
  • .NET Core 1.1+
  • .NET Core App 1.1+
  • .NET Framework 4.5.2+ (x86, x64, AnyCPU)
  • Mono 5.2+
  • Universal Windows Platform (UWP) 10.0.10240+ (x86, x64, ARM, AnyCPU, Windows 10 IoT Core)
  • Xamarin.Android 7.5+
  • Xamarin.iOS 10.14+

Nuget

This library is available as a nuget package: https://www.nuget.org/packages/CoAPnet/

Examples

Please find examples and the documentation at the Wiki of this repository (https://github.com/chkr1011/CoAPnet/wiki).

Contributions

If you want to contribute to this project just create a pull request. But only pull requests which are matching the code style of this library will be accepted. Before creating a pull request please have a look at the library to get an overview of the required style. Also additions and updates in the Wiki are welcome.

References

This library is used in the following projects:

If you use this library and want to see your project here please create a pull request.

License

MIT License

CoAPnet Copyright (c) 2016-2022 Christian Kratky

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

coapnet's People

Contributors

chkr1011 avatar ms-sk avatar vankooch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

coapnet's Issues

CoapClient.Dispose blocking for some reason

For some reason, that I wasn't able to find yet, the Dispose function of the client is somehow blocked / won't exit.
It doesn't matter If I run the code in a unit test or a console application.
I'm using a using statement, just like in the sample code. The code runs fine. I implemented a couple of functions to work with the Ikea Gateway.

But as soon as my code hits the end of the using statement, it will just run forever.
I also tried the example code from the wiki and I have the same behavior. So that could serve as my example code for the issue. But if I could provide any more details that can help you fix that, please let me know.

I'm using a MacBook Pro with Big Sur 11.2.3 and .NET 5 (5.0.102).

Identity Example

Following this note: "Please note that the identity and key must be generated first using the security token on the back of the device."

Doing so with a python lib is easy, but is there a way to do this with CoAPnet?

If so, could you point me in the right direction to do so?

Thank you!

Example Client has an error?

Hello,

In the example, it says to create a connection the builder is setup as:

var connectOptions = new CoapClientConnectOptionsBuilder()
.WithHost("GW-B8D7AF2B3EA3.fritz.box")
.WithPort(5684)
.WithDtlsTransportLayer(new DtlsCoapTransportLayerOptionsBuilder()
.WithPreSharedKey("IDENTITY", "lqxbBH6o2eAKSo5A")
.Build())
.Build();

However, when the package is downloaded from the nuget link, yhis line doesnt seem to be accepted:

.WithDtlsTransportLayer(new DtlsCoapTransportLayerOptionsBuilder()

And Visual studio only seems to find:

.WithTransportLayer

How will the example be setup in this case?

Thank you!

New version of libraries not connecting to Tradfri

So, I got this code to connect to an IKEA Tradri:

`public static async Task ConnectTradfri(ICoapClient theClient, string IP, string ID, string secretKey) {
Console.WriteLine("< CONNECTING...");

        var connectOptions = new CoapClientConnectOptionsBuilder()
            .WithHost(IP)
            .WithPort(5684)
            .WithDtlsTransportLayer(o => o.WithPreSharedKey(ID, secretKey))
            .Build();

        using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(taskTimout))) {
            await theClient.ConnectAsync(connectOptions, cancellationTokenSource.Token);
        }
        
    }`

That works perfectly well when using the libs from version [1.0.9], but now that I upgraded to version [1.1.0] the same code is unable to connect. It now needs .ConfigureAwait(false); at the end.

Has something changed that I am missing? Or why could this be happening?

Found & fixed bug in Block2

According to the standard, in a Block2 transfer the client should set the "more" bit in Block2 option as 0. Although this shouldn't pose an issue, it's still technically a requirement.
I added "receivedBlock2OptionValue.HasFollowingBlocks = false;" in the loop CoapClientBlockTransferReceiver.ReceiveFullPayload method

ZigBee Clusters and Ikea Symfonisk Volume Control

Hi,

I have been trying to get the Ikea Tradfri Symfonisk device to report its events via Observe in this library. The device is connected sucessfully and I can ask the gateway for its details and it even send random updates using Observe, however it will not report click and rotation events.

A clue as to why may be in the following comment within the deconz project. The developer says:

"bind the client OnOff cluster to a group. And then the client Level Control cluster. After that, it now behaves normally, waking up to send commands on click and turn. " (dresden-elektronik/deconz-rest-plugin#1898 (comment))

Is there the ability to do this in CoAPnet? I would really love to get this device working. So many uses for it.

Cheers!

Data race in response payload for parallel requests

Hi, I was playing around with Tradfri (thanks a lot for this library BTW). And when I started making parallel requests I started noticing that there are weird situations where the message is trimmed (but maybe I'm even getting response to another request, it is difficult to tell in async context and given that all the responses are the same - device info to be exact).

I was able to fix this by augmenting CoapMessage with byte[] PayloadBytes and using that in CoapMessageToResponseConverter. I assign PayloadBytes here by just doing message.PayloadBytes = message.Payload.ToArray(); and voila the problem is gone (quick and dirty, but it did the job).

I didn't do more digging, but it makes me wonder whether the array segments aren't reused somewhere and reassigned before the converter has chance to pick up the data for the response.

This problem also occurs the most during jitting in steady state it is much less likely to occur.

I'll be happy to provide you with more feedback or a sample provided tou have a gateway to test it on ๐Ÿ˜‰.

CoAPServer?

I cannot find any code for the server - is this another repo?

Block1 blockwise transfer?

Does this library have support for Block1 blockwise transfer (request payload)? If so, do you have any sample of this working?

We are trying to do a Coap Push with a large file payload but we can't see how to use blockwise transfer to send it.

Tradfri Pre Shared Key Generation

Hi,

Great library! You have done an amazing amount of work.

One question, in the example for using IKEA Tradfri (https://github.com/chkr1011/CoAPnet/wiki/CoAP-Client-Examples), you mention the following link to create the pre shared key (home-assistant/core#10252). I have tried to do this using the functions available in your library, trying various permutations of parameters etc, however I cannot get it to come back with a result due to timeouts. Is the basic functionality there in the DTLS libs to be able to string something together, or does there need to be additional work done in the WithDtlsTransportLayer function?

Kind Regards.

Wiki gone?

I can't find the wiki with examples any more. Is it gone ?

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.