All Projects → gotthardp → gen_coap

gotthardp / gen_coap

Licence: other
Generic Erlang CoAP Client/Server

Programming Languages

erlang
1774 projects
Makefile
30231 projects

Projects that are alternatives of or similar to gen coap

microCoAPy
A mini client/server implementation of CoAP (Constrained Application Protocol) into MicroPython
Stars: ✭ 41 (-59.8%)
Mutual labels:  coap, coap-server, coap-client
CoAPExplorer
A (soon to be) cross-platform tool for exploring CoAP protocol.
Stars: ✭ 16 (-84.31%)
Mutual labels:  coap, coap-client
emqx-coap
EMQ X CoAP Gateway
Stars: ✭ 50 (-50.98%)
Mutual labels:  coap, coap-server
ESP-CoAP
This repo contains CoAP protocol for ESP-12E
Stars: ✭ 70 (-31.37%)
Mutual labels:  coap-server, coap-client
Emqx
An Open-Source, Cloud-Native, Distributed MQTT Message Broker for IoT.
Stars: ✭ 8,951 (+8675.49%)
Mutual labels:  coap, coap-server
Iot Technical Guide
🐝 IoT Technical Guide --- 从零搭建高性能物联网平台及物联网解决方案和Thingsboard源码分析 ✨ ✨ ✨ (IoT Platform, SaaS, MQTT, CoAP, HTTP, Modbus, OPC, WebSocket, 物模型,Protobuf, PostgreSQL, MongoDB, Spring Security, OAuth2, RuleEngine, Kafka, Docker)
Stars: ✭ 2,334 (+2188.24%)
Mutual labels:  coap
Ikea Tradfri Coap Docs
How can you communicate to your ikea tradfri gateway/hub through coap-client
Stars: ✭ 111 (+8.82%)
Mutual labels:  coap
Qcloud Iot Sdk Embedded C
SDK for connecting to Tencent Cloud IoT from a device using embedded C.
Stars: ✭ 109 (+6.86%)
Mutual labels:  coap
Go Coap
Implementation of CoAP Server & Client in Go
Stars: ✭ 226 (+121.57%)
Mutual labels:  coap
Awalwm2m
Awa LWM2M is an implementation of the OMA Lightweight M2M protocol in C.
Stars: ✭ 93 (-8.82%)
Mutual labels:  coap
Golden Gate
Framework to connect wearables and other IoT devices to mobile phones, tablets and PCs with an IP-based protocol stack over Bluetooth Low Energy
Stars: ✭ 223 (+118.63%)
Mutual labels:  coap
Anjay
C implementation of the client-side OMA LwM2M protocol
Stars: ✭ 115 (+12.75%)
Mutual labels:  coap
zestdb
ZestDB
Stars: ✭ 18 (-82.35%)
Mutual labels:  coap
coap-go
Lobaro CoAP for GoLang - server and client applications
Stars: ✭ 20 (-80.39%)
Mutual labels:  coap
Aiocoap
The Python CoAP library
Stars: ✭ 185 (+81.37%)
Mutual labels:  coap
Mainflux
Industrial IoT Messaging and Device Management Platform
Stars: ✭ 1,341 (+1214.71%)
Mutual labels:  coap
ioBroker.shelly
Shelly ioBroker Adapter
Stars: ✭ 108 (+5.88%)
Mutual labels:  coap
Designiot
教你设计物联网系统。构建自己的Internet of Things 。
Stars: ✭ 1,983 (+1844.12%)
Mutual labels:  coap
peniot
PENIOT: Penetration Testing Tool for IoT
Stars: ✭ 164 (+60.78%)
Mutual labels:  coap
Cloud
Secure and Interoperable Internet of Things
Stars: ✭ 142 (+39.22%)
Mutual labels:  coap

Generic Erlang CoAP Client/Server

Pure Erlang implementation of the Constrained Application Protocol (CoAP), which aims to be conformant with:

The following features are not (yet) implemented:

  • Proxying and virtual servers (Uri-Host, Uri-Port, Proxy-Uri and Proxy-Scheme options)

It was tested with the following CoAP implementations:

Used in the following applications:

Let me know if you (intend to) use gen_coap. The API may change and some functions may not be implemented. Please add an Issue if you find a bug or miss a feature.

Usage

gen_coap enables you to integrate a CoAP server and/or CoAP client with your application. For demonstration purposes it also includes a simple CoAP client and server.

Build Status

Client

Have a look at sample_client.erl. It implements a simple command line utility for manipulation and observation of CoAP resources. It shall demonstrate the use of the coap_client and coap_observer modules. The tool accepts the following arguments:

Argument Description
-m Method request method (get, put, post or delete), default is 'get'
-e Text include text as payload
-s Duration subscribe for given duration [seconds]
Uri coap:// or coaps:// URI identifying the resource

Run the example simply by:

$ ./coap-client.sh coap://127.0.0.1/.well-known/core
$ ./coap-client.sh coaps://127.0.0.1/.well-known/core?rt=core.ps
$ ./coap-client.sh coaps://127.0.0.1/resource
$ ./coap-client.sh coap://127.0.0.1/resource -s 1000
$ ./coap-client.sh -m put coap://127.0.0.1/resource -e data
$ ./coap-client.sh -m delete coap://127.0.0.1/resource

In an erlang program you can get a CoAP resource by:

{ok, content, Data} = coap_client:request(get, "coap://coap.me:5683")

No application need to be started to use the client.

Server

Have a look at sample_server.erl. It implements a simple resource storage, which can be accessed using CoAP. It shall demonstrate the use of the coap_server_registry and coap_responder modules. The server requires no arguments. Run the sample server as follows and then access it using any CoAP client (or the gen_coap sample client tool):

$ ./coap-server.sh

You can manually start the server from the Erlang command line by:

$ erl -pa _build/default/lib/gen_coap/ebin

1> application:ensure_all_started(gen_coap).
{ok,[crypto,asn1,public_key,ssl,gen_coap]}

2> coap_server:start_udp(coap_udp_socket).
{ok,<0.78.0>}

However, the server out of a box does not offer any resources. To offer CoAP access to some server resources you need to implement the coap_resource behaviour, which defines callbacks that the server invokes upon reception of a CoAP request.

  • coap_discover is called when a CoAP client asks for the list of ".well-known/core" resources.
  • coap_get, coap_post, coap_put or coap_delete is called when the server receives a GET, POST, PUT or DELETE request for a resource.
  • coap_observe or coap_unobserve is called upon a GET request with an Observe=0 or Observe=1 option.

Since Erlang 19.2 the DTLS transport is supported. To configure certificates for the sample coap-server do:

$ cd gen_coap
$ sudo openssl req -new > csr.pem
$ sudo openssl rsa -in privkey.pem -out key.pem
$ sudo openssl x509 -in csr.pem -out cert.pem -req -signkey key.pem

Architecture

The following picture shows the gen_coap modules are their relationships: GitHub Logo

Build Instructions

Linux

First, you need to have rebar installed. Please install the rebar package e.g. by

$ sudo yum install erlang-rebar

Then, you only need to run

$ git clone https://github.com/gotthardp/gen_coap.git
$ cd gen_coap
$ make

Windows

I recommend you install the Erlang IDE for Eclipse. Then, import the project:

  • Run Eclipse, select File > New > Project..., select Erlang Project and click Next.
  • Enter gen_coap as a Project name and select Location of gen_coap on your machine. Click Next.
  • Review the following page and click Next.
  • Set Source folders to src;examples and click Finish.

Run the Erlang application and then you should be able to run the client and server in your Console:

1> sample_server:start().
ok

2> sample_client:start(["coap://localhost/.well-known/core"]).
get "coap://localhost/.well-known/core"
{ok,content,{coap_content,<<"xyz">>,60,<<"application/link-format">>,<<>>}}
ok
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].