zephyr.js icon indicating copy to clipboard operation
zephyr.js copied to clipboard

[ocf] How to receive argument from terminal when running ocf client

Open wanghongjuan opened this issue 8 years ago • 1 comments

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])

server.js

  • The process.argv[2/3] is a hypothetical value.

Steps to reproduce

  1. Build server.js on A101
  2. Connect with BLE
  3. 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.

wanghongjuan avatar Jul 26 '17 07:07 wanghongjuan

This will probably be a new feature, like if we want to support the process api

jimmy-huang avatar Jul 31 '17 20:07 jimmy-huang