Git Product home page Git Product logo

coapblaster's Introduction

CoapBlaster

CoapBlaster is an experimental open-source CoAP client/server library written in Java.

Design Goals

The initial design goals for CoapBlaster were best approximated as the following:

  • Full RFC7252 support
  • Flexible, easy-to-use API that supports both synchronous and asynchronous design patterns
  • Robust, easy-to-use resource observation
  • Easily swappable back-end to support various transports
  • Full support for DTLS, COSE, and possibly OSCORE

Most of these goals have already been met, while a few are still in progress.

Note that because CoapBlaster is still at the experimental/preview stage, it should not be considered production ready.

Current Features

Currently, CoapBlaster supports the following:

  • Full RFC7252 support for the Constrained Application Protocol
    • Retransmission/deduplication support
    • Tunable transmission parameters
  • API allows for both asynchronous and synchronous usage
  • Supports sending and receiving asynchronous CoAP responses
  • Effortless RFC7641 observation support
  • Support for block2 transfers on both client and server interfaces
  • Support for parsing and composing RFC6690-style link formats
  • Support for diverting client requests through a CoAP proxy

Planned Features

Documentation

Usage Examples

Fetching a simple resource

Program:

import com.google.iot.m2m.LocalEndpointManager;
import com.google.iot.m2m.Client;
import com.google.iot.m2m.Transaction;
import com.google.iot.m2m.Message;

LocalEndpointManager manager = new LocalEndpointManager();

Client client = new Client(manager, "coap://coap.me/test");

Transaction transaction = client.newRequestBuilder().send();

try {
    Message response = transaction.getResponse();
    System.out.println("Got response: " + response);

} catch(Exception exception) {
    System.out.println("Exception: " + exception);
}

Which will print out a long line which looks something like this:

<CONTENT IN ACK MID:44712 TOK:"f43c" 2.05 RADDR:"/134.102.218.18:5683" OPTS:[ETag:thZhiYJXp/I=, Content-Format:0] TEXT:"welcome to the ETSI plugtest! last change: 2018-1...">

Additional Examples

Building and Installing

This project uses Maven for building. Once Maven is installed, you should be able to build and install the project by doing the following:

mvn verify
mvn install

Note that the master branch of this project depends on CborTree, so you may need to download, build, and install that project first.

Adding to Projects

Gradle:

dependencies {
  compile 'com.google.iot.coap:coap:0.02.01'
}

Maven:

<dependency>
  <groupId>com.google.iot.coap</groupId>
  <artifactId>coap</artifactId>
  <version>0.02.01</version>
</dependency>

Building and Installing

This project uses Maven for building. Once Maven is installed, you should be able to build and install the project by doing the following:

mvn verify
mvn install

Note that the master branch of this project depends on CborTree, so you may need to download, build, and install those projects first.

See Also

License

CoapBlaster is released under the Apache 2.0 license.

Copyright 2018 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Disclaimer

This is not an officially supported Google product.

coapblaster's People

Contributors

darconeous avatar dependabot[bot] 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

coapblaster's Issues

Stop using coap.me in unit tests

Currently there are a few unit tests which actually use coap://coap.me, which isn't really a great idea long-term. This issue is tracking the replacement of those unit tests with more robust tests that don't rely on internet access nor burden third-party services.

How test the soapBluster library?

I managed to build a soapBluster project, but I don’t know how to test and use it. I created a java gradle project in IntelliJ IDEA, and added dependences according to the your recommendation to the build.gradle file. Also some changes were added to function main of Main.java class:

import com.google.iot.m2m.LocalEndpointManager;
import com.google.iot.m2m.Client;
import com.google.iot.m2m.Transaction;
import com.google.iot.m2m.Message;

public class Main {

    public static void main(String[] args)
    {
        System.out.println("Hello coap!");

        LocalEndpointManager manager = new LocalEndpointManager();

        Client client = new Client(manager, "coap://coap.me/test");

        Transaction transaction = client.newRequestBuilder().send();

        Message response = transaction.getResponse();

        System.out.println("Got response: " + response);
    }

}

However, apart from compilation errors, I received nothing:

Information:java: Errors occurred while compiling module 'testCoapBluster.testCoap.main'
Information:javac 1.8.0_201 was used to compile java sources
Information:2/28/19 9:42 AM - Compilation completed with 10 errors and 0 warnings in 1 s 635 ms
/home/michael_k/IdeaProjects/testCoap/src/main/java/Main.java
Error:(1, 26) java: package com.google.iot.m2m does not exist
Error:(2, 26) java: package com.google.iot.m2m does not exist
Error:(3, 26) java: package com.google.iot.m2m does not exist
Error:(4, 26) java: package com.google.iot.m2m does not exist
Error:(12, 9) java: cannot find symbol
  symbol:   class LocalEndpointManager
  location: class Main
Error:(12, 44) java: cannot find symbol
  symbol:   class LocalEndpointManager
  location: class Main
Error:(14, 9) java: cannot find symbol
  symbol:   class Client
  location: class Main
Error:(14, 29) java: cannot find symbol
  symbol:   class Client
  location: class Main
Error:(16, 9) java: cannot find symbol
  symbol:   class Transaction
  location: class Main
Error:(18, 9) java: cannot find symbol
  symbol:   class Message
  location: class Main

What is the matter and how to fix errors?

File build.gradle:

plugins {
    id 'java'
}

group 'testCoapBluster'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'com.google.iot.coap:coap:0.01.00'
}


Client-Server app doesn't work on Android.

I tried to test CoapBlaster on my phone. I wrote a simple application with two buttons: the first creates and starts the server, the second creates a client and tries to get a response:

public class MainActivity extends AppCompatActivity {
    final String TAG = "coap";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Button server = findViewById(R.id.server);
        server.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startServer();
            }
        });

        final Button client = findViewById(R.id.client);
        client.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startClient();
            }
        });
    }

    private void startClient() {
        try {
            LocalEndpointManager manager = new LocalEndpointManager();
            Client client = new Client(manager, "coap://127.0.0.1/test/hello");
            Transaction transaction = client.newRequestBuilder().send();
            Message response = transaction.getResponse(5000);
            Log.e(TAG, "Got response: " + response.getPayloadAsString());
        }
        catch (Exception exception) {
            Log.e(TAG, "Client.Exception->" + exception.toString());
        }
    }

    private void startServer() {
        try {
            LocalEndpointManager manager = new LocalEndpointManager();
            Server server = new Server(manager);
            LocalEndpoint udpEndpoint = manager.getLocalEndpointForScheme(Coap.SCHEME_UDP);
            server.addLocalEndpoint(udpEndpoint);
            Resource<InboundRequestHandler> rootResource = new Resource<>();
            Resource<InboundRequestHandler> testFolder = new Resource<>();
            InboundRequestHandler helloHandler = new InboundRequestHandler() {
                public void onInboundRequest(InboundRequest inboundRequest) {
                    inboundRequest.sendSimpleResponse(Code.RESPONSE_CONTENT, "Hello, World!");
                }
            };
            testFolder.addChild("hello", helloHandler);
            rootResource.addChild("test", testFolder);
            server.setRequestHandler(rootResource);
            server.start();
            Log.e(TAG, "Server started");
        }
        catch (Exception exception) {
            Log.e(TAG, "Server.Exception->" + exception.toString());
        }
    }
}


Result:
2020-10-21 13:24:04.466 17315-17315/com.mk.testcoap2 E/coap: Server started
2020-10-21 13:24:12.968 17315-17315/com.mk.testcoap2 E/coap: Client.Exception->java.util.concurrent.TimeoutException
What's wrong?

Stop using Doclava

Doclava is currently used for Javadoc generation because it supports @hide, which is currently in use to hide experimental methods and classes from the Javadocs. Ultimately the real solution is to not use @hide, but this will require some refactoring of code.

Client Server Sample Program

Hello Team

I've tried client server sample program given in examples.

When I start server, not sure on which URI it is coming up and may be because of that client program is not able to make a connection to server URI.

My observation is ' client is not identifying where server is running' and I could not find an option where to fix host & port for server & client program.

@darconeous : Please advise. I've attached sample server & client program.

Thanks
coap.zip

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.