secesh / node-rgb

Communication driver for WiFi-CON (an network adapter for RGB LED controller)
GNU General Public License v3.0
8 stars 2 forks source link

Error - "object expected" #1

Closed ghost closed 10 years ago

ghost commented 10 years ago

If I try to use this script on Windows 7 Node.JS with the "easy example code" I get the error that an object was expected. As this also turns up when I run notify.js alone I think there's the error. If I run index.js it says "exports is not defined" but I think thats no problem, right?

And a question besides the error: Can you use this script for pulsaiting blue lights on Wifi-370 (started and timed or stopped from python or shell script)?

ghost commented 10 years ago

notify.js contains this code:

var lights = require("rgb-led") var led = require('rgb-led') var Office = new led.wifi370('10.1.1.65')

//send arguments as: red, green, blue //color values are 0-255. Office.writeToLight(255, 255, 255)

ghost commented 10 years ago

This is what turns up when I run it in CMD (before I ran it whitout the node in front)

node notify.js

module.js:340 throw err; ^ Error: Cannot find module 'rgb-led' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object. (C:\Users\windows\Desktop\node-rgb-master\notify.js:1: 76) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10)

secesh commented 10 years ago

please add the following to your notify.js:

var led = require('rgb-led')

ghost commented 10 years ago

I have that:

var lights = require("rgb-led") var led = require('rgb-led') <== here(!!) var Office = new led.wifi370('10.1.1.65')

//send arguments as: red, green, blue //color values are 0-255. Office.writeToLight(255, 255, 255)

secesh commented 10 years ago

ha. oops!

ghost commented 10 years ago

That might be the problem... I was not aware that it's necessary to install it. But as I plan to run the script on Linux, i'll try again on ubuntu.

npm gives error Error: ENOENT, stat 'C:\Users\windows\AppData\Roaming\npm'

secesh commented 10 years ago

npm is not necessary to install it, but one thing npm does is create a folder hierarchy within your project directory that makes modules able to be found by node. I'm strictly a linux user, so I don't know about the availability of npm on windows offhand, but I would expect it could be installed since npm is rather important to the overall node ecosystem.

anyway, to make the module able to be found by require, you can go about it a couple ways. The easiest would be to explicitly specify the file location.

var path = require('path')
var led = require(path.join(__dirname, 'index.js')) //where index.js is rgb-led file.

//It's best to use this method of requiring path and joining with __dirname
//rather than just 
//var led = require('./index.js')
//since it allows you to run the node application from anywhere while still
//enabling node to find the package.

Another possibility would be to make your own npm-style folders.

This way you should be able to require rgb-led and node should magically find node_modules/rgb-led/index.js

ghost commented 10 years ago

I booted up Ubuntu now, but I'll test in a few minutes. Thanks for the fast answers :) I got it running in Ubuntu now (can't test the fuction for now, as I don't have the wifi-370, yet)

secesh commented 10 years ago

np; you happened to catch me online! I'll close this issue, but would be happy to help if needed -- matt@chasefox.net