fbacker / broadlink-mqtt-bridge

Bridge Broadlink RM Devices with MQTT and API for e.g. OpenHAB
41 stars 14 forks source link

TypeError: log is not a function #44

Closed digitlength closed 3 years ago

digitlength commented 4 years ago

I have installed using the manual method on https://github.com/fbacker/broadlink-mqtt-bridge/wiki/Installation.

The only difference is that I do not have the /srv/ directory, so I installed in my home directory to prevent requiring elevated user credentials.

On running npm run production I get the following output in the console:

pi@raspberrypi:~/broadlink-mqtt-bridge $ npm run production

> broadlink-mqtt-bridge@1.0.0 production /home/pi/broadlink-mqtt-bridge
> node -r esm index.js

LOGLEVEL: info
2020-04-27 19:35:57 [info]:     Starting Broadlink MQTT NodeJS Application 
(node:29037) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
    at /home/pi/broadlink-mqtt-bridge/src/actions/files.js:131:25
(node:29037) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:29037) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
TypeError: log is not a function
    at Broadlink.addDevice (/home/pi/broadlink-mqtt-bridge/node_modules/broadlinkjs-rm/index.js:219:7)
    at Broadlink.onMessage (/home/pi/broadlink-mqtt-bridge/node_modules/broadlinkjs-rm/index.js:185:10)
    at Socket.emit (events.js:310:20)
    at Socket.EventEmitter.emit (domain.js:482:12)
    at UDP.onMessage [as onmessage] (dgram.js:924:8)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! broadlink-mqtt-bridge@1.0.0 production: `node -r esm index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the broadlink-mqtt-bridge@1.0.0 production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2020-04-27T19_35_58_283Z-debug.log

The log file mentioned at the end of the error above shows as below:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/bin/npm', 'run', 'production' ]
2 info using npm@6.13.4
3 info using node@v12.16.2
4 verbose run-script [ 'preproduction', 'production', 'postproduction' ]
5 info lifecycle broadlink-mqtt-bridge@1.0.0~preproduction: broadlink-mqtt-bridge@1.0.0
6 info lifecycle broadlink-mqtt-bridge@1.0.0~production: broadlink-mqtt-bridge@1.0.0
7 verbose lifecycle broadlink-mqtt-bridge@1.0.0~production: unsafe-perm in lifecycle true
8 verbose lifecycle broadlink-mqtt-bridge@1.0.0~production: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/pi/broadlink-mqtt-bridge/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
9 verbose lifecycle broadlink-mqtt-bridge@1.0.0~production: CWD: /home/pi/broadlink-mqtt-bridge
10 silly lifecycle broadlink-mqtt-bridge@1.0.0~production: Args: [ '-c', 'node -r esm index.js' ]
11 silly lifecycle broadlink-mqtt-bridge@1.0.0~production: Returned: code: 1  signal: null
12 info lifecycle broadlink-mqtt-bridge@1.0.0~production: Failed to exec production script
13 verbose stack Error: broadlink-mqtt-bridge@1.0.0 production: `node -r esm index.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:310:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:310:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid broadlink-mqtt-bridge@1.0.0
15 verbose cwd /home/pi/broadlink-mqtt-bridge
16 verbose Linux 4.19.66-v7+
17 verbose argv "/usr/local/bin/node" "/usr/bin/npm" "run" "production"
18 verbose node v12.16.2
19 verbose npm  v6.13.4
20 error code ELIFECYCLE
21 error errno 1
22 error broadlink-mqtt-bridge@1.0.0 production: `node -r esm index.js`
22 error Exit status 1
23 error Failed at the broadlink-mqtt-bridge@1.0.0 production script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

For info, I'm trying to connect to an RM4C Mini.

martinstuga commented 4 years ago

I have the exact same error... any clue?

miguc commented 3 years ago

Hello, i was working about my own issue #46 and I think we have the same problem.

If you see the logs, there are two problems:

1st:

(node:29037) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at /home/pi/broadlink-mqtt-bridge/src/actions/files.js:131:25

In this line, the program was looking for the subdirectory /srv/openhab2-conf/broadlink-mqtt-bridge/commands

I create it with:

mkdir /srv/openhab2-conf/broadlink-mqtt-bridge/commands

Next I run the same script:

npm run production

I have an error in the run of the script, but it works and continue. The error is because the directory is empty (no command):

2020-07-05 10:11:53 [error]: Missing commands

2nd:

Next, I went to the next error, the log Error:

TypeError: log is not a function

I saw the code, and I saw than the error was produced by this code:

218 if (!isKnownDevice) {
219       log(`\n\x1b[35m[Info]\x1b[0m We've discovered an unknown Broadlink device. This likely won't cause any issues.\n\nPlease raise an issue     in the GitHub repository (https://github.com/lprhodes/homebridge-broadlink-rm/issues) with details of the type of device and its device type code: "    ${deviceType.toString(16)}". The device is connected to your network with the IP address "${host.address}".\n`);
220
221       return null;
222     }

This will indicate that ¡My Broadlink device is not recongnised! and that is the main problem of all.

I have a new RM4 mini... I think that is the problem...

I think that the log function is not correctly defined into this function. I make a little workaround adding "console" like that:

218 if (!isKnownDevice) {
219       console.log(`\n\x1b[35m[Info]\x1b[0m We've discovered an unknown Broadlink device. This likely won't cause any issues.\n\nPlease raise an issue     in the GitHub repository (https://github.com/lprhodes/homebridge-broadlink-rm/issues) with details of the type of device and its device type code: "    ${deviceType.toString(16)}". The device is connected to your network with the IP address "${host.address}".\n`);
220
221       return null;
222     }

And that works. The situation seems very diferent, because I can run the service and i recive next messages:

[Info] We've discovered an unknown Broadlink device. This likely won't cause any issues.

Please raise an issue in the GitHub repository (https://github.com/lprhodes/homebridge-broadlink-rm/issues) with details of the type of device and its device type code: "62bc". The device is connected to your network with the IP address "192.168.1.46".

2020-07-05 10:12:18 [info]:     Broadlink Discovery completed. Found 1 devices.
2020-07-05 10:12:53 [debug]:    Check if we have any devices: 1 found.

I continue working. In the lprhodes/homebridge-broadlink-rm/issues seems that is not attended...

fbacker commented 3 years ago

First error: I've updated so that if commands folder is missing (default or custom path in config) a better error is generated.

Second error: I've removed my custom fork from https://github.com/lprhodes/broadlinkjs-rm and now using this npm library. For support on devices they need to be fixed here.

Please post your issue there and when fixed I can make a library upgrade.