{"id":20390611,"url":"https://github.com/gotthardp/gen_coap","last_synced_at":"2025-04-12T11:22:15.989Z","repository":{"id":35884349,"uuid":"40170146","full_name":"gotthardp/gen_coap","owner":"gotthardp","description":"Generic Erlang CoAP Client/Server","archived":false,"fork":false,"pushed_at":"2020-04-14T07:45:01.000Z","size":216,"stargazers_count":105,"open_issues_count":6,"forks_count":47,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-26T06:11:19.867Z","etag":null,"topics":["coap","coap-client","coap-resources","coap-server","erlang"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gotthardp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-04T07:34:49.000Z","updated_at":"2025-01-12T12:33:06.000Z","dependencies_parsed_at":"2022-08-30T13:11:02.085Z","dependency_job_id":null,"html_url":"https://github.com/gotthardp/gen_coap","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotthardp%2Fgen_coap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotthardp%2Fgen_coap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotthardp%2Fgen_coap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotthardp%2Fgen_coap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gotthardp","download_url":"https://codeload.github.com/gotthardp/gen_coap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248558254,"owners_count":21124240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coap","coap-client","coap-resources","coap-server","erlang"],"created_at":"2024-11-15T03:25:57.278Z","updated_at":"2025-04-12T11:22:15.969Z","avatar_url":"https://github.com/gotthardp.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Generic Erlang CoAP Client/Server\n\nPure Erlang implementation of the Constrained Application Protocol (CoAP),\nwhich aims to be conformant with:\n - CoAP core protocol [RFC 7252](https://tools.ietf.org/rfc/rfc7252.txt),\n   including (since Erlang/OTP 19.2) the DTLS-Secured CoAP\n - CoAP Observe option [RFC 7641](https://tools.ietf.org/rfc/rfc7641.txt)\n - Block-wise transfers in CoAP [draft-ietf-core-block-18](https://tools.ietf.org/id/draft-ietf-core-block-18.txt)\n - CoRE link format [RFC 6690](https://tools.ietf.org/rfc/rfc6690.txt)\n\nThe following features are not (yet) implemented:\n - Proxying and virtual servers (Uri-Host, Uri-Port, Proxy-Uri and Proxy-Scheme options)\n\nIt was tested with the following CoAP implementations:\n - C [libcoap](https://www.libcoap.net/) (develop branch)\n - [coap.me](http://coap.me/)\n\nUsed in the following applications:\n - [CoAP Publish-Subscribe interface to RabbitMQ](https://github.com/gotthardp/rabbitmq-coap-pubsub)\n\nLet me know if you (intend to) use *gen_coap*. The API may change and some\nfunctions may not be implemented. Please\n[add an Issue](https://github.com/gotthardp/gen_coap/issues/new)\nif you find a bug or miss a feature.\n\n\n## Usage\n*gen_coap* enables you to integrate a CoAP server and/or CoAP client with\nyour application. For demonstration purposes it also includes a simple CoAP\nclient and server.\n\n[![Build Status](https://travis-ci.org/gotthardp/gen_coap.svg?branch=master)](https://travis-ci.org/gotthardp/gen_coap)\n\n### Client\nHave a look at [sample_client.erl](examples/src/sample_client.erl). It implements a simple\ncommand line utility for manipulation and observation of CoAP resources. It\nshall demonstrate the use of the `coap_client` and `coap_observer` modules.\nThe tool accepts the following arguments:\n\n Argument      | Description\n---------------|---------------\n -m *Method*   | request method (get, put, post or delete), default is 'get'\n -e *Text*     | include text as payload\n -s *Duration* | subscribe for given duration [seconds]\n *Uri*         | coap:// or coaps:// URI identifying the resource\n\nRun the example simply by:\n\n    $ ./coap-client.sh coap://127.0.0.1/.well-known/core\n    $ ./coap-client.sh coaps://127.0.0.1/.well-known/core?rt=core.ps\n    $ ./coap-client.sh coaps://127.0.0.1/resource\n    $ ./coap-client.sh coap://127.0.0.1/resource -s 1000\n    $ ./coap-client.sh -m put coap://127.0.0.1/resource -e data\n    $ ./coap-client.sh -m delete coap://127.0.0.1/resource\n\nIn an erlang program you can get a CoAP resource by:\n```erlang\n{ok, content, Data} = coap_client:request(get, \"coap://coap.me:5683\")\n```\nNo application need to be started to use the client.\n\n### Server\nHave a look at [sample_server.erl](examples/src/sample_server.erl). It implements a simple\nresource storage, which can be accessed using CoAP. It shall demonstrate the\nuse of the `coap_server_registry` and `coap_responder` modules. The server\nrequires no arguments. Run the sample server as follows and then access\nit using any CoAP client (or the *gen_coap* sample client tool):\n\n    $ ./coap-server.sh\n\nYou can manually start the server from the Erlang command line by:\n\n    $ erl -pa _build/default/lib/gen_coap/ebin\n\n    1\u003e application:ensure_all_started(gen_coap).\n    {ok,[crypto,asn1,public_key,ssl,gen_coap]}\n\n    2\u003e coap_server:start_udp(coap_udp_socket).\n    {ok,\u003c0.78.0\u003e}\n\n\nHowever, the server out of a box does not offer any resources. To offer CoAP access\nto some server resources you need to implement the [`coap_resource` behaviour](src/coap_resource.erl),\nwhich defines callbacks that the server invokes upon reception of a CoAP request.\n - `coap_discover` is called when a CoAP client asks for the list of\n   \".well-known/core\" resources.\n - `coap_get`, `coap_post`, `coap_put` or `coap_delete` is called when the server\n   receives a GET, POST, PUT or DELETE request for a resource.\n - `coap_observe` or `coap_unobserve` is called upon a GET request with an\n   Observe=0 or Observe=1 option.\n\nSince Erlang 19.2 the DTLS transport is supported. To configure certificates for\nthe sample coap-server do:\n\n    $ cd gen_coap\n    $ sudo openssl req -new \u003e csr.pem\n    $ sudo openssl rsa -in privkey.pem -out key.pem\n    $ sudo openssl x509 -in csr.pem -out cert.pem -req -signkey key.pem\n\n### Architecture\n\nThe following picture shows the `gen_coap` modules are their relationships:\n![GitHub Logo](https://rawgit.com/gotthardp/gen_coap/master/doc/architecture.svg)\n\n## Build Instructions\n\n### Linux\n\nFirst, you need to have [rebar](https://github.com/rebar/rebar) installed. Please\ninstall the rebar package e.g. by\n\n    $ sudo yum install erlang-rebar\n\nThen, you only need to run\n\n    $ git clone https://github.com/gotthardp/gen_coap.git\n    $ cd gen_coap\n    $ make\n\n### Windows\n\nI recommend you install the [Erlang IDE](http://erlide.org) for [Eclipse](https://www.eclipse.org).\nThen, import the project:\n - Run Eclipse, select File \u003e New \u003e Project..., select Erlang Project and click Next.\n - Enter gen_coap as a Project name and select Location of *gen_coap* on your machine. Click Next.\n - Review the following page and click Next.\n - Set Source folders to `src;examples` and click Finish.\n\nRun the Erlang application and then you should be able to run the client and server in your Console:\n\n    1\u003e sample_server:start().\n    ok\n\n    2\u003e sample_client:start([\"coap://localhost/.well-known/core\"]).\n    get \"coap://localhost/.well-known/core\"\n    {ok,content,{coap_content,\u003c\u003c\"xyz\"\u003e\u003e,60,\u003c\u003c\"application/link-format\"\u003e\u003e,\u003c\u003c\u003e\u003e}}\n    ok\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotthardp%2Fgen_coap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgotthardp%2Fgen_coap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotthardp%2Fgen_coap/lists"}