Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activities and the related task and event. #10

Open
GuySawyer opened this issue Oct 17, 2014 · 9 comments
Open

Activities and the related task and event. #10

GuySawyer opened this issue Oct 17, 2014 · 9 comments

Comments

@GuySawyer
Copy link

I sit now with what looks like a complex problem.
I am trying to use an Event, a Task and an Activity to create an automated control loop.
First I'll explain how the event, task and activity are created and the Steward responses, then I'll explain the issues.

The event was created and got this response from the Steward:

//Function called to taas-client from the test.js file
steward.createEvent('motion', 'event1', 'device/6', 'motion', 'motion detected', "", function(message) {    
            console.log(require('util').inspect(message, { depth: null }));
        });

//Response from Steward
{ path: '/api/v1/event/create/motion',
  name: 'motion',
  uuid: 'event1',
  actor: 'device/6',
  observe: 'motion',
  parameter: '"motion detected"',
  comments: '',
  requestID: 2 }
management
{ requestID: '2' }
{ requestID: '2' }
Socket message: {
  "manage": [
    {
      "date": "2014-10-14T09:46:59.529Z",
      "level": "info",
      "message": "wss 192.168.2.101 56628 /manage",
      "meta": {
        "message": {
          "path": "/api/v1/event/create/motion",
          "name": "motion",
          "uuid": "event1",
          "actor": "device/6",
          "observe": "motion",
          "parameter": "\"motion detected\"",
          "comments": "",
          "requestID": "2"
        }
      }
    }
  ]
}
management
{ requestID: '2', result: { event: '9' } }
{ requestID: '2', result: { event: '9' } }

The Task was created and got this response from the Steward:

//Function called to taas-client from the test.js file
steward.createTask('relay', 'task1', 'device/9', 'toggle', 'on', "", function(message) {
            console.log(require('util').inspect(message, { depth: null }));
        });

//Response from Steward
{ path: '/api/v1/task/create/relay',
  name: 'relay',
  actor: 'device/9',
  perform: 'toggle',
  parameter: '"on"',
  comments: '',
  requestID: 2 }
management
{ requestID: '2' }
{ requestID: '2' }
Socket message: {
  "manage": [
    {
      "date": "2014-10-14T10:02:34.708Z",
      "level": "info",
      "message": "wss 192.168.2.101 57425 /manage",
      "meta": {
        "message": {
          "path": "/api/v1/task/create/relay",
          "name": "relay",
          "actor": "device/9",
          "perform": "toggle",
          "parameter": "\"on\"",
          "comments": "",
          "requestID": "2",
          "guard": "/"
        }
      }
    }
  ]
}
management
{ requestID: '2', result: { task: '2' } }
{ requestID: '2', result: { task: '2' } }

And the Activity was created and got this response from the Steward:

//Function called to taas-client from the test.js file
steward.createActivity('motionRelay', 'act1', 'event/9', 'task/2', 'yes', "", function(message) {       // 'event/9' and 'task/2' activity result is 'activity/9'
            console.log(require('util').inspect(message, { depth: null }));
        });

/Response from Steward
{ path: '/api/v1/activity/create/motionRelay',
  name: 'motionRelay',
  uuid: 'act1',
  event: 'event/9',
  task: 'task/2',
  armed: 'yes',
  comments: '',
  requestID: 2 }
management
{ requestID: '2' }
{ requestID: '2' }
Socket message: {
  "manage": [
    {
      "date": "2014-10-14T10:08:02.725Z",
      "level": "info",
      "message": "wss 192.168.2.101 57697 /manage",
      "meta": {
        "message": {
          "path": "/api/v1/activity/create/motionRelay",
          "name": "motionRelay",
          "uuid": "act1",
          "event": "event/9",
          "task": "task/2",
          "armed": "yes",
          "comments": "",
          "requestID": "2"
        }
      }
    }
  ]
}
management
{ requestID: '2', result: { activity: '9' } }
{ requestID: '2', result: { activity: '9' } }

The first problem is in Thing-client.

The Observe request is working correctly, but for some reason I get an invalid event ID error from the Steward after thing-client sends the report information.

From receiving the observe request up until the error message looks like this:

>>> recv: {"path":"/api/v1/thing/observe","requestID":"110","events":{"20130314":{"thingID":"03096609","observe":"motion","parameter":"\"motion detected\"","testOnly":false}}}
{ path: '/api/v1/thing/observe',
  requestID: '110',
  events: 
   { '20130314': 
      { thingID: '03096609',
        observe: 'motion',
        parameter: '"motion detected"',
        testOnly: false } } }
>>> send: {"path":"/api/v1/thing/report","requestID":"110","events":{"20130314":{"success":true}}}
>>> recv: {"requestID":"110","events":{"20130314":{"error":{"permanent":false,"diagnostic":"invalid eventID"}}}}

The Observe and Report sections of my code (i.e. test.js) that interacts with thing-client.js looks like this:

var f = { '/api/v1/thing/observe':
                function() {
                  var event, eventID, response;

                  response = { path: '/api/v1/thing/report', requestID: message.requestID, events: {} };

                  for (eventID in message.events) if (message.events.hasOwnProperty(eventID)) {
                    event = message.events[eventID];

                    if (event.observe !== 'motion') {
                      response.events[eventID] = { error: { permanent: true, diagnostic: 'invalid observe value' }
                                                 , reason: 'observe'
                                                 };
                      continue;
                    }
                    if (!event.testOnly) observe[eventID] = event;
                    response.events[eventID] = { success: true };
                  }
                  thing.reply(response);
                }
            , '/api/v1/thing/report':
                function() {
                  var event, eventID, response;

                  response = { path: '/api/v1/thing/report', requestID: message.requestID, events: {} };

                  for (eventID in message.events) if (message.events.hasOwnProperty(eventID)) {
                    event = message.events[eventID];

                    if (event.reason !== 'cancel') {
                      response.events[eventID] = { error: { permanent: true, diagnostic: 'invalid reason' }};
                      continue;
                    }
                    if (!!observe[eventID]) {
                      response.events[eventID] = { error: { permanent: true, diagnostic: 'invalid eventID' }};
                      continue;
                    }
                    delete(observe[eventID]);
                    response.events[eventID] = { success: true };
                  }
                  thing.reply(response);
                }

The second problem is that when I create motion so that thing-client registers the 'motion detected' variable, the activity does not carry out the task.
I'm not sure if this is the duty of the Steward to handle, or if I should be adding to my test.js file to carry out the activity...?

Your help is always greatly appreciated.
Regards
Guy

@mrose17
Copy link
Member

mrose17 commented Nov 2, 2014

sorry for the delay in replying.

the second question is easy to answer: if the steward has an activity defined, it is responsible for carrying out the task when the event occurs. the question is what is going on, and this is the first question you ask.

i am looking into the issue now. what you are doing in the code looks right to me, so this is a bit perplexing.

@GuySawyer
Copy link
Author

Ok the answer to the second question is good news, and I was sure that is how it's supposed to be.

The first question, it seems that the problem is centred around that event ID.
The only other place the event ID comes up is during creation of the Activity, So I can't determine whats causing an eventID error.

@mrose17
Copy link
Member

mrose17 commented Nov 2, 2014

i am unable to reproduce what you are seeing. however, i found a bug in my client and the steward, which his now fixed.

please run the latest version of the steward. please also get the latest version of this library and compare test.js to your javascript file. you will see on line 204, i changed:

    <                     response.events[eventID] = { success: true };
    ---
    >                     response.events[eventID] = { status: 'proceed' };

make that change to your client and try it. if it still fails, then please email me your javascript file so i can test what you are using. sorry!

@GuySawyer
Copy link
Author

Great, it is at least good news that you found bugs. I will update now, I follow with some debugging. If there is no luck, I shall post here again, and also email you my file.

Thank you so much

@GuySawyer
Copy link
Author

Mr. Rose

I have been attempting to update Steward for a while now.
I keep getting an ENOENT error at various points during the "npm install -l", as well as a tar.unpack error, looking like this:

npm ERR! tar.unpack untar error /root/.npm/underscore/1.4.4/package.tgz
npm ERR! Error: ENOENT, lstat '/home/debian/steward/steward/node_modules/zbee/node_modules/nedb/node_modules/underscore/underscore-min.js'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>
npm ERR! System Linux 3.8.13-bone30
npm ERR! command "node" "/usr/local/bin/npm" "install" "-l"
npm ERR! cwd /home/debian/steward/steward
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.4.4
npm ERR! path /home/debian/steward/steward/node_modules/zbee/node_modules/nedb/node_modules/underscore/underscore-min.js
npm ERR! fstream_path /home/debian/steward/steward/node_modules/zbee/node_modules/nedb/node_modules/underscore/underscore-min.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/writer.js:284:26

Eventually it ends with this error:

> [email protected] install /home/debian/steward/steward/node_modules/irobot/node_modules/serialport
> node-gyp rebuild

gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/0.10.22"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/debian/steward/steward/node_modules/irobot/node_modules/serialport/.node-gyp"
gyp http GET http://nodejs.org/dist/v0.10.22/node-v0.10.22.tar.gz
gyp http 200 http://nodejs.org/dist/v0.10.22/node-v0.10.22.tar.gz
make: Entering directory `/home/debian/steward/steward/node_modules/irobot/node_modules/serialport/build'
  CXX(target) Release/obj.target/serialport/src/serialport.o
  CXX(target) Release/obj.target/serialport/src/serialport_unix.o
  CXX(target) Release/obj.target/serialport/src/serialport_poller.o
  SOLINK_MODULE(target) Release/obj.target/serialport.node
  SOLINK_MODULE(target) Release/obj.target/serialport.node: Finished
  COPY Release/serialport.node
make: Leaving directory `/home/debian/steward/steward/node_modules/irobot/node_modules/serialport/build'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/debian/steward/steward/npm-debug.log
npm ERR! not ok code 0

I'm not sure what to make of this.

@mrose17
Copy link
Member

mrose17 commented Nov 10, 2014

sorry for the (usual) delay in replying.

i don't understand how the superuser (root) can get an EACCES error, since the root is supposed to be able to access everything. stackoverflow has a number of suggestions at http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo that may help. since i don't know the details of your installation, i can't really assist more than that. sorry!

@GuySawyer
Copy link
Author

Thanks for your response

I think I have the access problems solved, thanks for that link. A few other people have had the same issue with root user being denied permission.

After that, it seems as though the install completes successfully. Although I had to run through it 2 or three times, the final run through had only two errors.

  1. The first error was a fail to parse the JSON in package.json (It happened in the middle of a long line of "npm http GET"):
npm http 304 https://registry.npmjs.org/thirty-two/0.0.1
npm http 304 https://registry.npmjs.org/ezcrypto/0.0.3
npm ERR! Failed to parse json
npm ERR! Unexpected end of input
npm ERR! File: /root/.npm/oauth/0.9.9/package/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! System Linux 3.8.13-bone30
npm ERR! command "node" "/usr/local/bin/npm" "install" "-l"
npm ERR! cwd /home/debian/steward/steward
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.4.4
npm ERR! file /root/.npm/oauth/0.9.9/package/package.json
npm ERR! code EJSONPARSE
  1. The second error came right at the end with no reference to anything (The last make install was that of [email protected]):
make: Leaving directory `/home/debian/steward/steward/node_modules/soap/node_modules/node-expat/build'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/debian/steward/steward/npm-debug.log
npm ERR! not ok code 0

So ignoring these errors, I tried to run the steward and view the log with "./run.sh" and I got this:

debian@steward:~/steward/steward$ ./run.sh
info: running on Linux Debian 7.2 ( 3.8.13-bone30 armv7l)
info: using node v0.10.22
alert: [steward] exception diagnostic=Cannot find module './build/Release/pcap_binding'
alert: [steward] exception stack=[{"fileName":"module.js","lineNumber":338,"functionName":"Function.Module._resolveFilename","typeName":"Function","methodName":"Module._resolveFilename","columnNumber":15,"native":false},{"fileName":"module.js","lineNumber":280,"functionName":"Function.Module._load","typeName":"Function","methodName":"Module._load","columnNumber":25,"native":false},{"fileName":"module.js","lineNumber":364,"functionName":"Module.require","typeName":"Module","methodName":"require","columnNumber":17,"native":false},{"fileName":"module.js","lineNumber":380,"functionName":"require","typeName":"Object","methodName":null,"columnNumber":17,"native":false},{"fileName":"/home/debian/steward/steward/node_modules/pcap/pcap.js","lineNumber":6,"functionName":"","typeName":"Object","methodName":null,"columnNumber":21,"native":false},{"fileName":"module.js","lineNumber":456,"functionName":"Module._compile","typeName":"Module","methodName":"_compile","columnNumber":26,"native":false},{"fileName":"module.js","lineNumber":474,"functionName":"Object.Module._extensions..js","typeName":"Object","methodName":"Module._extensions..js","columnNumber":10,"native":false},{"fileName":"module.js","lineNumber":356,"functionName":"Module.load","typeName":"Module","methodName":"load","columnNumber":32,"native":false},{"fileName":"module.js","lineNumber":312,"functionName":"Function.Module._load","typeName":"Function","methodName":"Module._load","columnNumber":12,"native":false},{"fileName":"module.js","lineNumber":364,"functionName":"Module.require","typeName":"Module","methodName":"require","columnNumber":17,"native":false}]
uncaught exception: Error: Cannot find module './build/Release/pcap_binding'
Press ^C to exit or wait 10 seconds to restart

Apart from running the install again (which is what I'm doing now) I can't figure out why I'm all of a sudden having these problems. It was never such an issue to perform an upgrade in the past.

Any thoughts or help is appreciated.
Guy

@GuySawyer
Copy link
Author

Hi Mr. Rose.

I'm slowly nearing a deadline in which I would like to demonstrate these functions. Might you be able to give me an estimate on when you would be able to handle this?

@mrose17
Copy link
Member

mrose17 commented Nov 22, 2014

hi. sorry for the delay. i am no longer able to contribute to the thing system or it's repos. there simply aren't enough cycles available to me. an announcement has been made on the community page, https://plus.google.com/communities/113042377519941328693

you may be able to get someone there to help.

i just no longer have enough time, sorry.

  • marshall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants