ni-c / heimcontrol.js

Home-Automation with node.js and Raspberry PI
MIT License
1.41k stars 297 forks source link

Trying to write own plugin, error message and crash after startup from PluginHelper #96

Closed awkwardterrain-com closed 10 years ago

awkwardterrain-com commented 10 years ago

I've stripped heimcontrol from all plugins and now I am trying to write my own.

I want to speak JSON to a TCP-Server on another Raspberry Pi and I want to include this "VirtualJoystick" as control for it.

As I am very noob, I'm just trying to adapt the patterns I see in the other plugins.

Unfortunately when I try to start heimcontrol right now I get the following error message:

2 Oct 10:24:33 - [nodemon] starting `node heimcontrol.js`
   info  - socket.io started
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
heimcontrol.js listening on port 8080

/home/pi/heimcontrol.js/libs/PluginHelper.js:58
        pluginList.push(new Plugin(that.app));
                        ^
TypeError: undefined is not a function
    at /home/pi/heimcontrol.js/libs/PluginHelper.js:58:25
    at Object.context.execCb (/home/pi/heimcontrol.js/node_modules/requirejs/bin/r.js:1876:33)
    at Object.Module.check (/home/pi/heimcontrol.js/node_modules/requirejs/bin/r.js:1110:51)
    at Object.Module.enable (/home/pi/heimcontrol.js/node_modules/requirejs/bin/r.js:1381:22)
    at Object.Module.init (/home/pi/heimcontrol.js/node_modules/requirejs/bin/r.js:1018:26)
    at null._onTimeout (/home/pi/heimcontrol.js/node_modules/requirejs/bin/r.js:1651:36)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
2 Oct 10:25:06 - [nodemon] app crashed - waiting for file changes before starting...

I'm am 100% sure it is my plugin that is causing the issue, as heimcontrol starts up with no problem without any plugins or with the webcam plugin reinserted.

If I understand correctly PluginHelper is the code that tries to load my plugin into heimcontrol and also helps my plugin to connect to mongodb. Thats why I did what all the other plugins did:

this.pluginHelper = app.get('plugin helper');

The main problem is, that I don't understand the error message and therefore don't know where to look for an error in my plugin.

I've already tried to comment out all half finished or net yet completely understood code piece by piece (or basically everything) but I can't find what is causing this error.

ni-c commented 10 years ago

It seems that Plugin in pluginList.push(new Plugin(that.app)); is undefined, maybe your plugin class can not be found or is not correctly loaded.

The class of your plugin has to be in a file named "index.js" in your plugin folder and must be returned at the end. (See: https://github.com/ni-c/heimcontrol.js/blob/master/plugins/gpio/index.js#L144)

awkwardterrain-com commented 10 years ago

Thanks a lot. That was the problem. I didn't see it at first because the code was there, but there was a parentheses in the wrong place.