Bootstrap Discover operation

Bootstrap discover

The "Discover" operation on the Bootstrap Interface is used to discover which LWM2M Objects and Object Instances are supported by a certain LWM2M client. This operation is used to discover which Resources are instantiated in a given Object Instance. The returned payload is a list of application/link-format CoRE Links for each targeted Object and Object Instance, along with their assigned or attached attributes including the Object Version attribute, if required.

The "Discover" operation has the following parameters:

Table 1. Parameters
Parameter Required Default value Notes
Object ID Yes - Indicates the Object.
Object Instance ID No - Indicates the Object instance

In "Discover" command the targeted path '/' is accepted in place of the Object ID, to inform the Client to report all existing Object Instances.

Bootstrap payload and response

Following is an example script and response for Bootstrap Discover on root resource:

Script:

<primitiveImplementation type="BSLWM2M" id="lwm2m.new.bootstrap.psk.discover.root"><![CDATA[
var pskId = client.generatePskId();
var psk = client.generatePsk();
var reguri = client.getRegistrationServerUri();

var jsonRegSec = "{\"e\":[{\"n\":\"0\",\"sv\":\"" + reguri + "\"},{\"n\":\"1\",\"bv\":false},{\"n\":\"2\",\"v\":0},{\"n\":\"3\",\"sv\":\"" + pskId + "\"},{\"n\":\"5\",\"sv\":\""+ psk + "\"},{\"n\":\"10\",\"v\":1}]}";
var jsonRegSrv = "{\"e\":[{\"n\":\"0\",\"v\":1},{\"n\":\"1\",\"v\":60},{\"n\":\"2\",\"v\":1},{\"n\":\"3\",\"v\":1000},{\"n\":\"5\",\"v\":84600},{\"n\":\"6\",\"bv\":true},{\"n\":\"7\",\"sv\":\"UQ\"}]}";

lwm2m.write('/0/1', jsonRegSec);
lwm2m.write('/1/1', jsonRegSrv);

client.setCredentials(pskId, psk);

var response = lwm2m.discover('/');

output.set("responseCode", response.code);
output.set("responseStatus", response.status);
output.set("resourceValue", response.value);
lwm2m.finished();

]]>       
       </primitiveImplementation>

Response:

 "[;lwm2m=\"1.1\", <[</0>;ver=\"1.1\", </0/0>;ssid=\"0\";uri=\"coaps://127.0.0.1:5684\", 
</0/1>;ssid=\"0\";uri=\"coaps://127.0.0.1:5684\", </1>, </1/0>;ssid=\"12345\", </1/1>;ssid=\"12345\", 
</16>, </16/0>, </19>, </19/0>, </21>, </3>, </3/0>, </4>, </4/0>, </5>, </5/0>, </54321>, </54321/0>, 
</6>, </6/0>, </9>, </9/0>]>]"

Following is an example of Bootstrap Discover on /0 (security object):

Script:

<primitiveImplementation type="BSLWM2M" id="lwm2m.new.bootstrap.psk.discover"><![CDATA[
var pskId = client.generatePskId();
var psk = client.generatePsk();
var reguri = client.getRegistrationServerUri();

var jsonRegSec = "{\"e\":[{\"n\":\"0\",\"sv\":\"" + reguri + "\"},{\"n\":\"1\",\"bv\":false},{\"n\":\"2\",\"v\":0},{\"n\":\"3\",\"sv\":\"" + pskId + "\"},{\"n\":\"5\",\"sv\":\""+ psk + "\"},{\"n\":\"10\",\"v\":1}]}";
var jsonRegSrv = "{\"e\":[{\"n\":\"0\",\"v\":1},{\"n\":\"1\",\"v\":60},{\"n\":\"2\",\"v\":1},{\"n\":\"3\",\"v\":1000},{\"n\":\"5\",\"v\":84600},{\"n\":\"6\",\"bv\":true},{\"n\":\"7\",\"sv\":\"UQ\"}]}";

lwm2m.write('/0/1', jsonRegSec);
lwm2m.write('/1/1', jsonRegSrv);

client.setCredentials(pskId, psk);

var response = lwm2m.discover('/0');
var stringOfLinks =  response.value;
var strippedString = stringOfLinks.substring(1, stringOfLinks.length - 1);

var objectLinks = org.eclipse.leshan.Link.parse((strippedString).getBytes());

var filteredssids = filterSsids(objectLinks);

_log.info("ssids : " + filteredssids);
_log.info("ver : " + objectLinks[0].getAttributes().get("lwm2m"));

lwm2m.finished();

output.set("responseCode", response.code);
output.set("responseStatus", response.status);
output.set("resourceValue", response.value);

function filterSsids(links){
var filteredLinks = [];
for each(var link in links){
    if(link.getAttributes().containsKey("ssid")){
   
       filteredLinks.push(link.getAttributes().get("ssid"));
     }
   }
   return filteredLinks;
}

String.prototype.getBytes = function () {
  var bytes = [];
  for (var i = 0; i < this.length; ++i) {
    var char = str.charCodeAt(i);
    bytes.push(char >>> 8);
    bytes.push(char & 0xFF);
  }
  return bytes;
};

]]> </primitiveImplementation>

Response:

"[;lwm2m=\"1.1\", </0>;ver=\"1.1\", </0/0>;ssid=\"0\";uri=\"coaps://127.0.0.1:5684\", 
</0/1>;ssid=\"0\";uri=\"coaps://127.0.0.1:5684\"]"