diff options
author | Cui Yan <yanx.cui@intel.com> | 2017-04-20 00:55:51 +0800 |
---|---|---|
committer | Geoff Gustafson <geoff@linux.intel.com> | 2017-04-19 09:55:51 -0700 |
commit | 46c8cc28f546db6700082eea391459113bc0a163 (patch) | |
tree | a7b89a702361bd8b626fcfb6e007d7e09fe21921 | |
parent | 6d1818a92de0380bb45f9e65c3f764701e8ffa3b (diff) |
Sync 0.3 docs fix and sample added (#1036)
Signed-off-by: cuiyanx <yanx.cui@intel.com>
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | docs/console.md | 2 | ||||
-rw-r--r-- | samples/OcfSensorClient.js | 46 |
3 files changed, 48 insertions, 2 deletions
@@ -360,7 +360,7 @@ upload the K64F [hello world application](https://developer.mbed.org/platforms/F Then, you could try the Zephyr OS `hello_world` sample to narrow down the problem: ```bash -cd deps/zephyr/samples/hello_world/nanokernel +cd deps/zephyr/samples/hello_world/ make pristine && make BOARD=frdm_k64f cp outdir/frdm_k64f/zephyr.bin /media/<USERNAME>/MBED/ ``` diff --git a/docs/console.md b/docs/console.md index 16c7b85..a03aebe 100644 --- a/docs/console.md +++ b/docs/console.md @@ -54,4 +54,4 @@ difference to `stdout`. Sample Apps ----------- -* [Console sample](../samples/Console.js) +* [Console sample](../samples/tests/Console.js) diff --git a/samples/OcfSensorClient.js b/samples/OcfSensorClient.js new file mode 100644 index 0000000..4f0aca7 --- /dev/null +++ b/samples/OcfSensorClient.js @@ -0,0 +1,46 @@ +// Copyright (c) 2017, Intel Corporation. + +// Sample client that works with OcfSensorServer.js + +var client = require('ocf').client; + +console.log("Started OCF client"); + +client.on('error', function(error) { + if (error.deviceId) + console.log("Error for device: " + error.deviceId); +}); + +function onupdate(resource) { + console.log("Resource updated:"); + console.log(" deviceId: " + resource.deviceId); + console.log(" resourcePath: " + resource.resourcePath); + if (resource.properties != undefined) { + console.log("Resource property 'sensor' is " + resource.properties.sensor); + } else { + console.log("resource.properties not found"); + } +} + +client.on('update', onupdate); + +var lightOn = true; + +// TODO: Must save away the timer handle or else GC will destroy it after a few iterations +var t1 = null; + +function onfound(resource) { + t1 = setInterval(function() { + client.retrieve(resource.deviceId, { observable: false }).then(function(res) { + console.log("retrieve() was successful, deviceId=" + res.deviceId); + }).catch(function(error) { + console.log("retrieve() returned an error: " + error.name); + }); + }, 1000); +} + +client.findResources({ resourceType:"core.sensor" }, onfound).then(function(resource) { + console.log("findResources() was successful, deviceId=" + resource.deviceId); +}).catch(function(error) { + console.log("findResources() returned an error: " + error.name); +}); |