Skip to content

rosds/luacoap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

luacoap

This project is a simple lua binding to the SMCP CoAP stack. The current version only implements some client calls.

Building

To build this project, you require to install cmake and lua

git clone https://github.com/alfonsoros88/luacoap
mkdir -p luacoap/build
cd luacoap/build
cmake ..
make

the output its a coap.so shared library that can be loaded into lua.

You can optionally install this module with:

sudo make install

and you can use it independently of your location.

Optionally, you can download and install the debian package.

or luarocks

luarocks install luacoap

Usage

Currently it is only possible to send GET, PUT and POST request using the CoAP client.

Example

coap = require("coap")
client = coap.Client()

function callback(playload)
  print(playload)
end

client:get(coap.CON, "coap://coap.me/test", callback)

The current available functions are

client:get([ ConnectionType ,] url [, ContentType, Payload ], [ callback ])
client:put([ ConnectionType ,] url [, ContentType, Payload ], [ callback ])
client:post([ ConnectionType ,] url [, ContentType, Payload ], [ callback ])
client:observe([ ConnectionType ,] url [, ContentType, Payload ], [ callback ])

where:

  • ConnectionType is either coap.CON or coap.NON for confirmable or non-confirmable,
  • url is the address to the resource
  • ContentType is any of the CoAP supported content types
  • Payload is the data you want to send
  • callback is a function that will be executed when the response arrives
Observe Request

The observe request is different from the others since it returns a listener object. This object can be used to control the subscription to the target resource. The listener object implements the following methods.

listener:callback()   -- Executes the callback function provided to the client
listener:listen()     -- Starts observing the resource
listener:stop()       -- Stops the observation
listener:pause()      -- Suspends the observation
listener:continue()   -- Resumes the observation

About

lua binding for smcp coap library

Resources

Stars

Watchers

Forks

Packages

No packages published