CoAP Binding? yes or no

Hello all,

I had build the OH2 binding vitotronic.
Since one year it runs stable and without problems, thanks smarthome and OH2 Team.
Now I like to upgrade the binding but the changing of the things/channels are heavy :unamused: (complex changes on client an server site).
Now my Idea:
I rebuild my binding vitotronic and the server site with a generic thing model (discovery) and I like to use CoAP as communication.
Or I leave the dedicated solution and replace it a with generic CoAP binding.

My Question: Make it sense to build a generic CoAP binding?

pros:

  • already implementation in eclipse include maven :slight_smile:
  • lightweight and easy to use
  • standard implementation for IoT (Web Things) communication
  • meta model in place
  • security available (DTLS: TLS/SSL for Datagrams), if requested
  • free adding of attributes in the meta model
  • observer function for events available
  • based on REST model (GET, PUT, POST, DELETE)

contra:

  • no data model for things what maped to OH2 (meta data can extended)
  • unclear if it becomes marked standard

Thanks for comments

Regards
Stefan

1 Like

Hey Stefan,

in our student project we coincidentally had the same idea and utilized CoAP resource discovery to dynamically add channels to a generic thing. Maybe our code can help or inspire you a bit. Here is our post in the ESH-forums https://www.eclipse.org/forums/index.php/t/1085170/

Regards,
another Stefan

1 Like

Hi Stefan, I could compile your CoAP binding from the generic_coap branch, run it in OH2 and manually add my Sonoff switch running a CoAP server. The server has two POST resources (on / off) and one GET (status). How to bind these resources now to OH2 items? Thanks, Christian

Hi Christian,

in order to let your CoAP endpoints be automatically discovered by the binding, your CoAP Server implementation needs to return a fitting resourcetype (“rt= …”) for every endpoint when recieving a GET on /.well-known/core endpoint.
The currently supported resourcetypes can be found in the file binding/gencoap/CoapResourceType.java.
For your case the response to /.well-known/core should be something like

</myPostEndpoint1>;rt="oic.r.switch.binary">, </myPostEndpoint2>;rt="oic.r.switch.binary">, </myGetEndpoint>;rt="oic.r.sensor">

Your manually added generic coap thing will then dynamically get matching channels to link your items with.
Please also note that the binary switch will recieve very simple POST requests with only “0” and “1” as payload if you for example send a command via PaperUI. The sensor endpoint will be queried every 15 seconds.

Hope this helps,
Stefan

1 Like

Hi Stefan, thanks for the quick reply! That helps me! The only problem now: How to set RT in the NodeMCU CoAP implementation :wink: Will try to figure that out. Thanks, Christian

Got the RT now and only have one resource where I can POST “0” or “1” (off or on) or carry out a GET to see the status. The Paper UI shows “online” for the thing but no channels are displayed. Any chance to define an item manually like “gencoap:node:8ba41514:switch”?

Any ideas? Could you give me an item example?

Hi Stefan, I also tried with your “coap-test-thing” - same: it is detected as online but no channels / items are listed. Any ideas how to proceed? Thanks, Christian

Hey Christian,
sorry for the late answer. I tried it again with the test thing on my ubuntu machine and it worked. I also noticed that your node in the screenshot is added by its IPv4 address of the thing. Sorry for not pointing it out, but the binding currently only uses IPv6 addresses. Maybe this already fixes your problem.

The binding is more or less in a proof-of-concept state at the moment and the coding in our project is currently paused, but nevertheless external contributions are always welcome :wink:

Here is my screenshot when using the test thing:

Thanks for the info Stefan! Unfortunately NodeMCU on ESP8266 does not support IPv6, so I decided to go for a small HTTP server instead.

Hi,

i have changed following in GenCoAPHandler.java:

from …

        } else {
            // TODO check if ipv6 or ipv4
            BASE_URI = "coap://[" + coap_server_ip_adr + "]:" + coap_server_port;
        }

to …

        } else {
            // TODO check if ipv6 or ipv4
            BASE_URI = "coap://" + coap_server_ip_adr + ":" + coap_server_port;
        }

Now i can add a Generic Coap Thing in openHAB2 with the modified ESP-CoAP simple library from https://github.com/automote/ESP-CoAP (added the resource type string “oic.r.switch.binary”, “oic.r.sensor” at resourceDiscovery in coap_server.cpp) on a
ESP8266 NodeMCU. So the switch and sensor type are working without problems.

image

My questions are now:

What is the current status of the Generic CoAP binding?

Will there be a “oic.r.colour.rgb” Channel as well?

Hy,

what is the current status of your the project?

I think a generic CoAP Binding would be really nice, because the possibilities for the application would be near endless.