cflurin / homebridge-mqtt

Homebridge-mqtt is a Plugin for Homebridge.
Apache License 2.0
229 stars 38 forks source link

Plugin interfering with multiple instances of Homebridge #66

Closed bohtho closed 6 years ago

bohtho commented 6 years ago

I have multiple instances of Homebridge where only one is configured to use homebridge-mqtt, but the mere existence (and loading) of the globally installed homebridge-mqtt plugin causes the second one to fail to start.

There's a simple fix to this bug proposed here (two possible solutions) if you agree and could implement:

https://github.com/oznu/homebridge-config-ui-x/issues/17#issuecomment-389465345

cflurin commented 6 years ago

Hi, Please try it, just change index.js, comment line 34:

  if (typeof(config) === "undefined" || config === null) {
    this.log.error("config undefined or null!");
    this.log("storagePath = %s", storagePath);
    //process.exit(1);
  }

Regarding line 24: I think true can not be removed. Take a look here:

  // For platform plugin to be considered as dynamic platform plugin,
  // registerPlatform(pluginName, platformName, constructor, dynamic), dynamic must be true
  homebridge.registerPlatform("homebridge-samplePlatform", "SamplePlatform", SamplePlatform, true);

but you can try it.

bohtho commented 6 years ago

You may be right about the second way. But I tried the first way (commenting out process.exit(1);) but then I get this error:

Process: 4502 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (co de=exited, status=1/FAILURE) Main PID: 4502 (code=exited, status=1/FAILURE) CGroup: /system.slice/homebridge-ext.service ├─4544 /bin/sh -c npm view homebridge-mqtt version └─4546 npm

Presumably because I messed with a npm module which does now not match the version's hash or something ? Sorry, I'm not very knowledgable with npm or node.

cflurin commented 6 years ago

Please post the log from homebridge start. Probably you will see an error message: config undefined or null!

bohtho commented 6 years ago

I used to get config undefined or null! on my second instance (with no mqtt plugin in config), see that log here: https://github.com/oznu/homebridge-config-ui-x/issues/17#issuecomment-389236469

Now after commenting out process.exit(1); in index.js I get this:

May 16 20:52:09 LillePi homebridge[8057]: [2018-5-16 20:52:09] [homebridge-mqtt.mqtt] Number of cached Accessories: 0 May 16 20:52:09 LillePi homebridge[8057]: /usr/local/lib/node_modules/homebridge-mqtt/lib/model.js:34 May 16 20:52:09 LillePi homebridge[8057]: var url = this.config.url; May 16 20:52:09 LillePi homebridge[8057]: ^ May 16 20:52:09 LillePi homebridge[8057]: TypeError: Cannot read property 'url' of null May 16 20:52:09 LillePi homebridge[8057]: at Model.start (/usr/local/lib/node_modules/homebridge-mqtt/lib/model.js:34:25) May 16 20:52:09 LillePi homebridge[8057]: at Controller.start (/usr/local/lib/node_modules/homebridge-mqtt/lib/controller.js:361:14) May 16 20:52:09 LillePi homebridge[8057]: at PluginPlatform. (/usr/local/lib/node_modules/homebridge-mqtt/index.js:69:23) May 16 20:52:09 LillePi homebridge[8057]: at API.emit (events.js:180:13) May 16 20:52:09 LillePi homebridge[8057]: at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:98:13) May 16 20:52:09 LillePi homebridge[8057]: at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10) May 16 20:52:09 LillePi homebridge[8057]: at Object. (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22) May 16 20:52:09 LillePi homebridge[8057]: at Module._compile (module.js:649:30) May 16 20:52:09 LillePi homebridge[8057]: at Object.Module._extensions..js (module.js:660:10) May 16 20:52:09 LillePi homebridge[8057]: at Module.load (module.js:561:32) May 16 20:52:09 LillePi systemd[1]: homebridge-ext.service: Main process exited, code=exited, status=1/FAILURE May 16 20:52:09 LillePi systemd[1]: homebridge-ext.service: Unit entered failed state. May 16 20:52:09 LillePi systemd[1]: homebridge-ext.service: Failed with result 'exit-code'.

cflurin commented 6 years ago
    this.log.error("config undefined or null!");
    this.log("storagePath = %s", storagePath);

these logs show the error and the storagePath, so I need the log of the instance using homebridge-mqtt.

bohtho commented 6 years ago

Sorry if I'm not following but the other (first) instance that is configured to use homebridge-mqtt logs this without error (even after my out-commenting in index.js):

May 16 22:22:13 LillePi homebridge[28553]: [2018-5-16 22:22:13] Loaded plugin: homebridge-config-ui-x May 16 22:22:13 LillePi homebridge[28553]: [2018-5-16 22:22:13] Registering platform 'homebridge-config-ui-x.config' May 16 22:22:13 LillePi homebridge[28553]: [2018-5-16 22:22:13] --- May 16 22:22:13 LillePi homebridge[28553]: [2018-5-16 22:22:13] Plugin /usr/local/lib/node_modules/homebridge-hue requires Node version of ^8.11.1 which does not satisfy the current Node version of v9.9.0. You may need to upgrade your installation of Node. May 16 22:22:15 LillePi homebridge[28553]: [2018-5-16 22:22:15] Loaded plugin: homebridge-hue May 16 22:22:15 LillePi homebridge[28553]: [2018-5-16 22:22:15] Registering platform 'homebridge-hue.Hue' May 16 22:22:15 LillePi homebridge[28553]: [2018-5-16 22:22:15] --- May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] Loaded plugin: homebridge-mqtt May 16 22:22:16 LillePi homebridge[28553]: homebridge API version: 2.2 May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] Registering platform 'homebridge-mqtt.mqtt' May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] --- May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] Loaded config.json with 0 accessories and 3 platforms. May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] --- May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] Loading 3 platforms... May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [Config] Initializing config platform... May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [Config] Spawning homebridge-config-ui-x with PID 28594 May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [mqtt] Initializing mqtt platform... May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [mqtt] homebridge-mqtt v0.4.8 May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [Hue] Initializing Hue platform... May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [Hue] homebridge-hue v0.9.2, node v9.9.0, homebridge v0.4.42 May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [Hue] warning: not using recommended node version v8.11.1 LTS May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [Hue] warning: not using recommended homebridge version v0.4.38 May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] Loading 0 accessories... May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [mqtt] Number of cached Accessories: 11 May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [mqtt] clientId = homebridge-mqtt_05073749 May 16 22:22:16 LillePi homebridge[28553]: [2018-5-16 22:22:16] [mqtt] Connecting.. May 16 22:22:17 LillePi homebridge[28553]: [2018-5-16 22:22:17] [mqtt] connected (url = mqtt://127.0.0.1)

cflurin commented 6 years ago

Ok, it seems to be a multi-instance issue. Have a look here: https://github.com/nfarina/homebridge/issues/1160

I have to investigate, but you can try to replace line 34 with return;

-- process.exit(1);
++ return;
bohtho commented 6 years ago

Yep, that works! The second Homebridge instance now manages to start up (without homebridge-mqtt configured as a platform in its config.json). It just logs the following on this instance but continues:

[2018-5-16 23:29:35] [homebridge-mqtt.mqtt] config undefined or null! [2018-5-16 23:29:35] [homebridge-mqtt.mqtt] storagePath = /var/lib/homebridge-ext

cflurin commented 6 years ago

I've uploaded a new version, please install from gitHub:

sudo npm install -g --unsafe-perm cflurin/homebridge-mqtt
bohtho commented 6 years ago

Awesome! Will you push it to npmjs as well?

  1. mai 2018 kl. 11:48 skrev cflurin notifications@github.com:

I've uploaded a new version, please install from gitHub:

sudo npm install -g --unsafe-perm cflurin/homebridge-mqtt — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

cflurin commented 6 years ago

homebridge-mqtt v0.5.0 on npm available.

bohtho commented 6 years ago

Works great.