0

UPDATE: There seems to be an issue with the cylon.js library. https://github.com/hybridgroup/cylon/issues/277

I am working on my first Node project and have run into some small issues with dependencies.

If I execute my server.js using node server.js, everything works as expected, all my deps are in the correct place and read just fine.

However, if I attempt to use init.d scripts to call it, or attempt to call it from within a different node program, I get errors that some of my dependencies are not found. It suggests using npm to reinstall them, and I have added the npm install line to the script just to make sure, but that has not had any effect.

I, [2015-06-29T17:29:12.661Z] INFO -- : [ardrobot] - Initializing connections.

Cannot find the 'cylon-intel-iot' module. This problem might be fixed by installing it with 'npm install cylon-intel-iot' and trying again.

    'use strict';

    var wait = require('wait.for')
    var Cylon = require('cylon');
    var bleno = require('bleno');
    var ip = require('ip');

    require('wait.for/parallel-tests.js')

    Cylon.robot({
      name: 'ardrobot',

      connections: {
        edison: { adaptor: 'intel-iot' }
      },
      devices: {
        turnServo: { driver: 'servo', pin: 3, },
        driveServo: { driver: 'servo', pin: 5, }
      },

      //These correspond to the actual api endpoints
      commands: function() {
        return {
          //servo
          set_angle: this.setAngle,
          set_drive_speed: this.setSpeed,
          do_arm: this.arm
        };
      },

      setAngle: function(val) {
        if (val != null) {
          this.turnServo.angle(this.turnServo.safeAngle(+val));
        }
      },
      setSpeed: function(val) {
        if (val != null) {
          this.driveServo.angle(this.driveServo.safeAngle(+val));
        }
      },

      arm: function() {
        var my = this;

        function arm1(param, callback){
          console.log('Arming sequence 1');
          my.setSpeed(180);
          wait.miliseconds(5000);
        };

        function arm2(param, callback){
          console.log('Arming sequence 2');
          my.setSpeed(0);
          wait.miliseconds(5000);
        };
        function arm3(param, callback){
          console.log('Arming sequence 3');
          my.setSpeed(90);
        };
        function prepareArm(){
          console.log('Beginning arming sequence');
          wait.for(arm1);
          wait.for(arm2);
          wait.for(arm3);
          console.log('Finished arming sequence');
        };

        wait.launchFiber(prepareArm);
      },
      work: function(my) {
      }
    }).start();

  Cylon.api(
      'http',{
      host: ip.address(),
      ssl: false,
      port: '3000'
    });
r2DoesInc
  • 3,759
  • 3
  • 29
  • 60
  • Can you add `console.log(require.resolve('cylon'));console.log(require.resolve('cylon-intel-iot'));` to the top of `server.js`, execute it successfully and with the error, and show us the output in both cases? – eush77 Jun 29 '15 at 19:06
  • /home/root/hellonode/node_modules/cylon/lib/cylon.js /home/root/hellonode/node_modules/cylon-intel-iot/lib/cylon-intel-iot.js both times. – r2DoesInc Jun 29 '15 at 20:04
  • Does it work under `NODE_ENV=test` environment variable? – eush77 Jun 29 '15 at 23:28
  • 1
    Can you `require('cylon-intel-iot')` from Node repl started at your project directory? – eush77 Jun 29 '15 at 23:31
  • Oh man, that was it. my package.json was corrupted. Thank you! – r2DoesInc Jun 30 '15 at 13:33

1 Answers1

0

Try setting the NODE_PATH variable when you launch server.js.

The docs.

Patosai
  • 750
  • 1
  • 6
  • 16