Overview
Last updated
Was this helpful?
Last updated
Was this helpful?
The highest levels of API in regards to CoAP are all provided by the Serval Stack. It offers functionality such as a server, a client or general utilities when implementing a CoAP based application. This ensures that any message sent and received will be a CoAP message and treated as such.
Client Functionality
Function
Description
CoapServer_initialize()
This function is called to initialize the CoAP client (and server) and related modules. It must be called before any other CoAP-Client related function.
CoapServer_startInstance()
This function is called to start the CoAP client (and server). As input it receives a port, to which the server will listen, and a reference to a callbackfunction, which will be called every time the server receives a message.
CoapClient_initialize()
If it is desired to use different UDP sockets for server and client, this function must be called for the client instead of CoapServer_initialize. This function initializes only the client and relevant modules. Per default, this function is disabled.
CoapClient_startInstance()
This function is called to start the CoAP client after the client has been initialized using CoapClient_initialize. Per default, this function is disabled, if CoapClient_initialize is disabled, as well.
CoapClient_request()
This function is called to send a message as a request. As input, it receives a message, a callback for informing about the status of sending and a callback to handle a response to this message.
CoapClient_initReqMsg()
This function is called to initialize a message. As input, it receives the target’s IP address, its port and the pointer to a message.
Utility
CoapParser_setup()
This function sets up a CoAP-Parser which will be used to receive certain information from a CoAP-Message, such as the code, the payload or the options. As input, it receives a variable of type CoapParser_T and the pointer to a message.
CoapParser_getCode()
This function is called to receive the code of a message. As input, it receives a pointer to a message.
CoapParser_getPayload()
This function is called to receive the payload of a message. As input, it receives a pointer to the previously set up parser, a pointer to a payload array, and the array’s length.
CoapSerializer_setup()
This function sets up a CoAP-Serializer, which will be used to create a message. It handles setting options, the payload, the code, etc, for a given message. As input, it receives variable of type CoapSerializer_T, the pointer to a message, and a code indicating whether a RESPONSE or a REQUEST is created.
CoapSerializer_setCode()
This function is called to set the code of a message. As input, it receives the serializer, a message and the code to be set.
CoapSerializer_serializePayload()
This function is called to set the payload for a message. As input, it receives the serializer, a message pointer, the payload and the payload’s length