Fix syntax in coap doc

This commit is contained in:
Marcel Stör 2016-01-16 15:03:22 +01:00
parent 8cbc5d6a05
commit b93f2ee8b1
1 changed files with 38 additions and 40 deletions

View File

@ -2,15 +2,17 @@
The CoAP module provides a simple implementation according to [CoAP](http://tools.ietf.org/html/rfc7252) protocol. The CoAP module provides a simple implementation according to [CoAP](http://tools.ietf.org/html/rfc7252) protocol.
The basic endpoint server part is based on [microcoap](https://github.com/1248/microcoap), and many other code reference [libcoap](https://github.com/obgm/libcoap). The basic endpoint server part is based on [microcoap](https://github.com/1248/microcoap), and many other code reference [libcoap](https://github.com/obgm/libcoap).
This Module implement both Client and Server side. GET/PUT/POST/DELETE is partially supported by Client. Server can regist Lua function and varibles. No Observe or Discover supported right now. This module implements both the client and the server side. GET/PUT/POST/DELETE is partially supported by the client. Server can register Lua functions and varibles. No observe or discover supported yet.
## Caution ## Caution
CoAP Module is only in the very early stage and not complete right now. This module is only in the very early stage and not complete yet.
## Constants ## Constants
`coap.CON`, `coap.NON` is the request type. Constants for various functions.
`coap.TEXT_PLAIN`, `coap.LINKFORMAT`, `coap.XML`, `coap.OCTET_STREAM`, `coap.EXI`, `coap.JSON` is the content type. `coap.CON`, `coap.NON` represent the request types.
`coap.TEXT_PLAIN`, `coap.LINKFORMAT`, `coap.XML`, `coap.OCTET_STREAM`, `coap.EXI`, `coap.JSON` represent content types.
## coap.Client() ## coap.Client()
@ -71,17 +73,16 @@ cs:func("myfun") -- post coap://192.168.18.103:5683/v1/f/myfun will call myfun
# CoAP Client # CoAP Client
## coap.client:get() ## coap.client:get()
Issue a GET request to the server. Issues a GET request to the server.
#### Syntax #### Syntax
`coap.client:get( type, uri, payload )` `coap.client:get(type, uri, [payload])`
#### Parameters #### Parameters
- `type` coap.CON, coap.NON, default to CON. when type is CON, and request failed, the request will retry another 4 times before giving up. - `type` `coap.CON`, `coap.NON`, defaults to CON. If the type is CON and request fails, the library retries four more times before giving up.
- `uri` the uri such as coap://192.168.18.103:5683/v1/v/myvar, only IP is supported. - `uri` the URI such as "coap://192.168.18.103:5683/v1/v/myvar", only IP addresses are supported i.e. no hostname resoltion.
- `payload` optional, the payload will be put in the payload section of the request. - `payload` optional, the payload will be put in the payload section of the request.
#### Returns #### Returns
@ -89,14 +90,14 @@ Issue a GET request to the server.
## coap.client:put() ## coap.client:put()
Issue a PUT request to the server. Issues a PUT request to the server.
#### Syntax #### Syntax
`coap.client:put( type, uri, payload )` `coap.client:put(type, uri, [payload])`
#### Parameters #### Parameters
- `type` coap.CON, coap.NON, default to CON. when type is CON, and request failed, the request will retry another 4 times before giving up. - `type` `coap.CON`, `coap.NON`, defaults to CON. If the type is CON and request fails, the library retries four more times before giving up.
- `uri` the uri such as coap://192.168.18.103:5683/v1/v/myvar, only IP is supported. - `uri` the URI such as "coap://192.168.18.103:5683/v1/v/myvar", only IP addresses are supported i.e. no hostname resoltion.
- `payload` optional, the payload will be put in the payload section of the request. - `payload` optional, the payload will be put in the payload section of the request.
#### Returns #### Returns
@ -104,13 +105,13 @@ Issue a PUT request to the server.
## coap.client:post() ## coap.client:post()
Issue a POST request to the server. Issues a POST request to the server.
#### Syntax #### Syntax
`coap.client:post( type, uri, payload )` `coap.client:post(type, uri, [payload])`
#### Parameters #### Parameters
- `type` coap.CON, coap.NON, default to CON. when type is CON, and request failed, the request will retry another 4 times before giving up. - `type` coap.CON, coap.NON, defaults to CON. when type is CON, and request failed, the request will retry another 4 times before giving up.
- `uri` the uri such as coap://192.168.18.103:5683/v1/v/myvar, only IP is supported. - `uri` the uri such as coap://192.168.18.103:5683/v1/v/myvar, only IP is supported.
- `payload` optional, the payload will be put in the payload section of the request. - `payload` optional, the payload will be put in the payload section of the request.
@ -119,43 +120,41 @@ Issue a POST request to the server.
## coap.client:delete() ## coap.client:delete()
Issue a DELETE request to the server. Issues a DELETE request to the server.
#### Syntax #### Syntax
`coap.client:delete( type, uri, payload )` `coap.client:delete(type, uri, [payload])`
#### Parameters #### Parameters
- `type` coap.CON, coap.NON, default to CON. when type is CON, and request failed, the request will retry another 4 times before giving up. - `type` `coap.CON`, `coap.NON`, defaults to CON. If the type is CON and request fails, the library retries four more times before giving up.
- `uri` the uri such as coap://192.168.18.103:5683/v1/v/myvar, only IP is supported. - `uri` the URI such as "coap://192.168.18.103:5683/v1/v/myvar", only IP addresses are supported i.e. no hostname resoltion.
- `payload` optional, the payload will be put in the payload section of the request. - `payload` optional, the payload will be put in the payload section of the request.
#### Returns #### Returns
`nil` `nil`
# CoAP Server # CoAP Server
## coap.server:listen() ## coap.server:listen()
Start the CoAP server on the given port. Starts the CoAP server on the given port.
#### Syntax #### Syntax
`coap.server:listen( port, ip )` `coap.server:listen(port, [ip])`
#### Parameters #### Parameters
- `port` server port (number). - `port` server port (number)
- `ip` optional. - `ip` optional IP address
#### Returns #### Returns
`nil` `nil`
## coap.server:close() ## coap.server:close()
Close the CoAP server. Closes the CoAP server.
#### Syntax #### Syntax
`coap.server:close( )` `coap.server:close()`
#### Parameters #### Parameters
none none
@ -165,14 +164,14 @@ none
## coap.server:var() ## coap.server:var()
Regist a Lua variable as an endpoint in the server. the varible value then can be GET by a client via GET method, represented as an [URI](http://tools.ietf.org/html/rfc7252#section-6) to client. The endpoint path for varialble is '/v1/v/'. Registers a Lua variable as an endpoint in the server. the variable value then can be retrieved by a client via GET method, represented as an [URI](http://tools.ietf.org/html/rfc7252#section-6) to the client. The endpoint path for varialble is '/v1/v/'.
#### Syntax #### Syntax
`coap.server:var( name, content_type )` `coap.server:var(name, [content_type])`
#### Parameters #### Parameters
- `name` the Lua variable's name. - `name` the Lua variable's name
- `content_type` optional, default to coap.TEXT_PLAIN, see [Content Negotiation](http://tools.ietf.org/html/rfc7252#section-5.5.4) - `content_type` optional, defaults to `coap.TEXT_PLAIN`, see [Content Negotiation](http://tools.ietf.org/html/rfc7252#section-5.5.4)
#### Returns #### Returns
`nil` `nil`
@ -192,19 +191,18 @@ cs:var("all", coap.JSON) -- sets content type to json
## coap.server:func() ## coap.server:func()
Regist a Lua function as an endpoint in the server. the function then can be called by a client via POST method. represented as an [URI](http://tools.ietf.org/html/rfc7252#section-6) to client. The endpoint path for function is '/v1/f/'. Registers a Lua function as an endpoint in the server. The function then can be called by a client via POST method. represented as an [URI](http://tools.ietf.org/html/rfc7252#section-6) to the client. The endpoint path for function is '/v1/f/'.
When the client issues a POST request to this URI, the payload will be passed to the function as parameter. the function's return value will be the payload in the message to the client. When the client issues a POST request to this URI, the payload will be passed to the function as parameter. The function's return value will be the payload in the message to the client.
The function registed SHOULD be accept ONLY ONE string type parameter, and return ONE string value or return nothing. The function registered SHOULD accept ONLY ONE string type parameter, and return ONE string value or return nothing.
When the client issue
#### Syntax #### Syntax
`coap.server:func( name, content_type )` `coap.server:func(name, [content_type])`
#### Parameters #### Parameters
- `name` the Lua function's name. - `name` the Lua function's name
- `content_type` optional, default to coap.TEXT_PLAIN, see [Content Negotiation](http://tools.ietf.org/html/rfc7252#section-5.5.4) - `content_type` optional, defaults to `coap.TEXT_PLAIN`, see [Content Negotiation](http://tools.ietf.org/html/rfc7252#section-5.5.4)
#### Returns #### Returns
`nil` `nil`