intel / iotivity-node

Node.js bindings for IoTivity
https://www.iotivity.org/
42 stars 44 forks source link

Update resourse event #74

Closed KunalSaini closed 8 years ago

KunalSaini commented 8 years ago

Hi, I am trying to update a resource however getting following error . Error: update: OCDoResource response failed following is my server / resource definition

var setpoint = 0;
device.register({
    id: { path: "/a/setpoint" },
    resourceTypes: [ "oic.r.switch.binary" ],
    interfaces: [ "oic.if.baseline" ],
    discoverable: true,
    observable: true,
    properties: { on: false }
  }).then((res) => {
    setpoint = res;
    device.addEventListener('observerequest', log);
    device.addEventListener('retrieverequest', log);
    device.addEventListener('updaterequest', log);
    console.log('setpoint register OK');
  }).catch(error => console.log(`error registering setpoint - ${error}`));

  function log(request) {
    console.log("setpoint: request " + request.type);
    request.sendResponse(setpoint);
  }

And following is the client

const client = require( "iotivity-node" )( "client" );
client.addEventListener( "resourcefound", function( event ) {
    if(event.resource.id.path === '/a/setpoint') {
        client.update({id: event.resource.id, setpoint: 10 })
        .then(() => console.log('changed setpoint'))
        .catch((error) => console.log(`unable to change setpoint - ${error}`));
    }
} );
client.findResources();
mythi commented 8 years ago

@KunalSaini please specify the ostro-os image you are using and the iotivity* versions.

KunalSaini commented 8 years ago

@mythi I am on the latest Ostro Os build 497 "ostro-image-swupd-all-intel-quark.dsk.xz" image. The Iotivity-node version is 1.1.0-4. I am not sure about the underlying iotivity version , however i think its 1.1.1

nagineni commented 8 years ago

@KunalSaini I don't see any issue running sample code with the iotivity-node v1.1.0-4.

Here is the client & server outptut:

# node client.js 
changed setpoint

# node server.js 
setpoint register OK
setpoint: request updaterequest
nagineni commented 8 years ago

BTW, latest Ostro has iotivity v1.1.0. Update for v1.1.1 is in pending queue.

KunalSaini commented 8 years ago

thanks @nagineni I guess I was running the client on iotivity-node 1.1.1-3 and server on 1.1.0-4 as I cant get the older version to install properly on my laptop. Hoping the ostro os will soon incorporate the latest version. meanwhile i also figured that passing the whole resource in client.update call resolves the issue for me.

gabrielschulhof commented 8 years ago

Since this issue seems to be fixed, I will close it.