zephyr.js
zephyr.js copied to clipboard
[ocf] How to receive argument from terminal when running ocf client
Description
Now I need to receive a resource object from terminal when running command outdir/linux/release/jslinux, but I am not clear how to do it.
Test Code
client.js
var ocf = require('ocf');
var client = ocf.client;
var updateProperties = {
range: [0, 255]
};
console.log("Started OCF client");
function errorHandler(error) {
if (error.deviceId) {
console.log("Error for device: " + error.deviceId);
}
}
client.on('error', errorHandler);
function updateResource(resource, data){
resource.properties.minRange = updateProperties.range[0];
resource.properties.maxRange = updateProperties.range[1];
resource.properties.RValue = data[0];
resource.properties.GValue = data[1];
resource.properties.BValue = data[2];
console.log(resource.properties.RValue);
console.log(resource.properties.GValue);
console.log(resource.properties.BValue);
}
client.update(resource)
.then(
function(updateResource){
if(updateResource == resource){
console.log('updated resource');
}
},
function(error){
console.log('failed to update resource with error', error.message);
}
)
}
ocf.start();
updateResource(process.argv[2], process.argv[3])
- The
process.argv[2/3]is a hypothetical value.
Steps to reproduce
- Build server.js on A101
- Connect with BLE
- Build and run client.js on linux
Actual Result
Not clear how to receive the argument resource object.
Excepted Result
The client.js can get the argument from terminal and the update method can be executed successfully.
This will probably be a new feature, like if we want to support the process api