libcoap - coap Data processing#

Adaptation status unknown

Note

This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!

Tip

This library has its own demo,click this link to view libcoap demo examples

libcoap.new(code, uri, headers, payload)#

create a coap packet

Parameters

Incoming Value Type

Explanation

int

coap code, for example libcoap.GET/libcoap.POST/libcoap.PUT/libcoap.DELETE

string

Target URI, required, no need to start/

table

Request header, similar to http headers, optional

string

The request body, similar to the body of http, optional

Return Value

return value type

explanation

userdata

coap Packet

Examples

-- Create a data packet requesting server time
local coapdata = libcoap.new(libcoap.GET, "time")
local data = coapdata:rawdata()

libcoap.parse(str)#

Parsing coap packets

Parameters

Incoming Value Type

Explanation

string

coap Packet

Return Value

return value type

explanation

userdata

coap packet, which is returned if the parsing fails nil

Examples

-- Parsing Server Incoming Packets
local coapdata = libcoap.parse(indata)
log.info("coapdata", coapdata:hcode(), coapdata:data())

coapdata:msgid()#

of a coap packet msgid

Parameters

None

Return Value

return value type

explanation

int

coap of the packet msgid

Examples

-- Parsing Server Incoming Packets
local coapdata = libcoap.parse(indata)
log.info("coapdata", coapdata:msgid())

coapdata:token()#

of a coap packet token

Parameters

None

Return Value

return value type

explanation

string

coap of the packet token

Examples

-- Parsing Server Incoming Packets
local coapdata = libcoap.parse(indata)
log.info("coapdata", coapdata:token())

coapdata:rawdata()#

Get the binary data of the coap packet for sending to the server

Parameters

None

Return Value

return value type

explanation

string

coap Binary data of the packet

Examples

-- Parsing Server Incoming Packets
local coapdata = libcoap.new(libcoap.GET, "time")
netc:send(coapdata:rawdata())

coapdata:code()#

of a coap packet code

Parameters

None

Return Value

return value type

explanation

int

coap of the packet code

Examples

-- Parsing Server Incoming Packets
local coapdata = libcoap.parse(indata)
log.info("coapdata", coapdata:code())

coapdata:hcode()#

Get the HTTP code of the coap packet, which is more friendly than the original code of coap.

Parameters

None

Return Value

return value type

explanation

int

coap The http code of the packet, for example 200,205,404

Examples

-- Parsing Server Incoming Packets
local coapdata = libcoap.parse(indata)
log.info("coapdata", coapdata:hcode())

coapdata:type(t)#

Get the type of the coap packet, for example libcoap.CON/NON/ACK/RST

Parameters

Incoming Value Type

Explanation

int

New type value, optional

Return Value

return value type

explanation

int

coap of the packet type

Examples

-- Parsing Server Incoming Packets
local coapdata = libcoap.parse(indata)
log.info("coapdata", coapdata:type())

coapdata:data()#

of a coap packet data

Parameters

None

Return Value

return value type

explanation

string

coap of the packet data

Examples

-- Parsing Server Incoming Packets
local coapdata = libcoap.parse(indata)
log.info("coapdata", coapdata:data())