aboutsummaryrefslogtreecommitdiff
path: root/samples/OcfPlatformInfo.js
blob: fd9060e1965312ad472c06c605b667c938a57cc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2016-2017, Intel Corporation.

// Sample server that works with the linux server found in iotivity-constrained
// This sample will find the resource and retrieve its platform info

var ocf = require('ocf');
var client = ocf.client;

console.log("Started OCF client");

client.on('platformfound', function(platform) {
    console.log("Platform found:");
    console.log("    id: " + platform.id);
    console.log("    Manufacturer Name: " + platform.manufacturerName);
});

client.on('error', function(error) {
  if (error.deviceId)
    console.log("Error for device: " + error.deviceId);
});

function onfound(resource) {
    console.log("Resource found: path=" + resource.resourcePath + " id=" + resource.deviceId);

    client.getPlatformInfo(resource.deviceId).then(function(info) {
        console.log("Got platform info for: " + info.id);
    }).catch(function(error) {
        console.log("Error getting platform info: " + error.name);
    });
}

ocf.start();

client.findResources({ resourceType:"oic.r.light" }, onfound).then(function(resource) {
    console.log("findResources() was successful, deviceId=" + resource.deviceId);
}).catch(function(error) {
    console.log("findResources() returned an error: " + error.name);
});