CoAP API

Connector functions JS API guide for the CoAP protocol

This file provides methods and properties to specify a custom return code and a custom body in the CoAP response that is sent from the OpenGate platform to the device.

coap.server.response Object: Specifying a custom CoAP response to the device.

The coap.server.response global object provides all the necessary functionality to be able to specify both the state and the body of the CoAP response to return to the device.

coap.server.response Object Properties

Property Type Default Description
status number 204 The returned status, as a three digits number without dots
body Uint8Array [] The body of the returned CoAP response, as array of bytes

coap.server.response Object Methods

send ()

The status and body are saved for inclusion in the CoAP response.

Example of use

// sending CHANGED status (2.04), and a number 1 as body (two bytes unsigned integer - little endian)
coap.server.response.status = 204; 
coap.server.response.body = new Uint8Array([01, 00]); 
coap.server.response.send();