ercoap - New Coap Protocol Parsing Library#

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 the demo example of ercoap

ercoap.parse(data)#

Parsing coap packets

Parameters

Incoming Value Type

Explanation

string

coap Packet

Return Value

return value type

explanation

table

Returns table on success, otherwise nil

Examples

-- This function is to parse coap packets
local rcoap = ercoap.parse(data)
if rcoap then
    log.info("coap", rcoap.type, rcoap.code, rcoap.payload)
    -- rcoap Properties
    -- type Message type, 0 - CON needs reply, 1 - NON does not need reply, 2-ACK has been received, 3-RST error
    -- msgid Message id
    -- payload Data carried
    -- code Similar to http's statue code, 2xx is normal and 4xx is wrong.
else
    log.info("ercoap", "Packet parsing failed")
end

ercoap.print(data)#

print coap packets

Parameters

Incoming Value Type

Explanation

string

coap Packet

Return Value

return value type

explanation

boolean

Parse successfully returned true

Examples

-- This function simply prints the coap packet

ercoap.onenet(tp, product_id, device_name, token, payload)#

Quickly generate onenet packets

Parameters

Incoming Value Type

Explanation

string

The request type, which is optional when it is a reply, and is required in other situations.

string

the project id must be filled in.

string

Device name, must be filled in

string

token,Must be filled in

string

object model json string, optional

Return Value

return value type

explanation

string

The synthesized data packet can be uplink through UDP

Examples

-- Reference Document: coap access https://open.iot.10086.cn/doc/v5/fuse/detail/924
-- Reference documentation: The things model https://open.iot.10086.cn/doc/v5/fuse/detail/902

-- Type tp value token source payload
-- login iotauth.onenet function generates none
-- Heartbeat keep_live iotauth.onenet function generates none
-- logout iotauth.onenet function generates none
-- When the attribute is reported to thing/property/post login,
-- The property must be obtained when replying to thing/property/reply login.
-- When an event is reported to thing/event/post login,
-- The remote call reply must be obtained when there is no login.