lukasroegner / homebridge-apple-tv-remote

Plugin for controlling Apple TVs in homebridge.
MIT License
131 stars 13 forks source link

Stability issues #46

Open lukasroegner opened 4 years ago

lukasroegner commented 4 years ago

There are three main issues with the plugin in its current state:

Delayed messages For some users, messages from the Apple TV to the plugin are delayed (sometimes for minutes), resulting in switches that are out of sync. As the on/off switch emulates remote input, it also cannot execute the correct action if the plugin state is out of sync with the Apple TV state.

On/off detection The logic to detect whether an Apple TV is on or off is not correct, yet. Currently, three state variables are considered to check whether the Apple TV is on:

    /**
     * Tries to get the on/off state of the Apple TV
     * @param messagePayload The message payload that contains the information to check whether the Apple TV is on.
     * @returns Returns a value that determines whether the Apple TV is on.
     */
    private getIsOn(messagePayload: any): boolean {

        // If the Apple TV is not a proxy for AirPlay playback, the logicalDeviceCount determines the state
        if (messagePayload.logicalDeviceCount > 0 && !messagePayload.isProxyGroupPlayer) {
            return true;
        }

        // If the Apple TV is a proxy for AirPlay playback, the logicalDeviceCount and the AirPlay state determine the state
        if (messagePayload.logicalDeviceCount > 0 && messagePayload.isProxyGroupPlayer && messagePayload.isAirplayActive) {
            return true;
        }
        return false;
    }

Crashes of homebridge For some users, connections to the Apple TV are suddenly closed, resulting in an unhandled exception when the plugin tries to send a message through the closed channel. The PR for fixing the request has also been submitted, but not accepted, yet: https://github.com/stickpin/node-appletv-x/pull/3

lukasroegner commented 4 years ago

If you have new findings and want to share them here, please make sure to

  1. Name the issue that your findings are about
  2. Create a PR or post the affected part of the source code
  3. Post your hardware/software configuration (Apple TV version, Apple TV OS version, Homebridge host OS and version, node version, special router in network?)
  4. Not just post logs without explanation

I'll start extensive testing in my environment soon and try to reproduce the networking issues (delayed messages) first with fix for crashes of Homebridge applied.

dmike3 commented 4 years ago

Homebridge is crashing for me. If I send a command to fast together it will crash.

I tried reinstalling the plugin.

sschuste commented 4 years ago

I'm not sure if I'm right in this thread. Since a few days the plugin crashes very often, on average every 30 to 45 minutes, without me using it or any automation triggering it. The error message is:

[6/13/2020, 11:36:19] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:454:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:153:33
    at new Promise (<anonymous>:null:null)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22

[6/13/2020, 11:36:19] Got SIGTERM, shutting down Homebridge...

Error: This socket has been ended by the other party. Which socket is meant and why there is a party on my Raspi? I've enabled the API of your plugin. I see that this error is triggered by node-apple-tv-x, so maybe I'm not only in the wrong thread, but I'm asking the wrong developer? :-D

lukasroegner commented 4 years ago

@sschuste You're at the right place! The PR has not been accepted by stickpin yet, I added a new comment, maybe he forgot about it. Anyways, if the PR is not not merged within the next days, I'll reference my fork of node-appletv-x in the plugin.

This should solve the issue of writing to the closed connection. I haven't found out why some people have this issue so often and others (including me) haven't seen this once.

sschuste commented 4 years ago

All right. I'll wait and see. Normally I would hardly notice a crash of the Homebridge, but I have a small monitoring system running and it generates an hearable acoustic signal when the Homebridge is down. At the moment the alarm is triggered very often.

Interesting might be the accumulation of alarms. I grep'd my logs starting at May 10th: May 21: 1 crash Jun 5: 1 crash Jun 11: 2 crashes Jun 12: 20 crashes Jun 13: 20 crashes (today, in only 12 hours so far)

Something has changed. Apple TV update?

kitsen13 commented 4 years ago

Great plugin!!

But I have the same problem AppleTv 4k 32go v13.3.1 (not the latest), Homebridge 1.1.1 , raspbian buster 4.19.66-v7+ and an error message at the startup of homebridge. (same error socket than sschuste). The normal CPU charge is about 2% without plugin and with plugin on the first hour was 8%, and then I had some crashes of homebridge 40% (no refresh of the accessories and impossible commands). API not activated. Homebridge-mqttthing v1.1.16 installed.

Thanks in advance

DJay-X commented 4 years ago

Looking forward to get this fix. Knowing it's not all in your hands @lukasroegner

[2020-6-18 18:17:07] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:454:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:153:33
    at new Promise (<anonymous>)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22
[2020-6-18 18:17:08] Got SIGTERM, shutting down Homebridge...
[2020-6-18 18:17:08] [AppleTvPlatform] Shutting down Apple TV clients...
[2020-6-18 18:17:09] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:454:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:153:33
    at new Promise (<anonymous>)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22
[2020-6-18 18:17:10] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:454:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:153:33
    at new Promise (<anonymous>)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22
[2020-6-18 18:17:11] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:454:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:153:33
    at new Promise (<anonymous>)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22
[2020-6-18 18:17:11] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:454:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:153:33
    at new Promise (<anonymous>)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22
[2020-6-18 18:17:12] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:454:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:153:33
    at new Promise (<anonymous>)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22
[2020-6-18 18:17:12] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:454:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:153:33
    at new Promise (<anonymous>)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22
[2020-6-18 18:17:13] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:454:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:153:33
    at new Promise (<anonymous>)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22
cgerke commented 4 years ago

Not sure yet if its relevant but I've been running this plugin for months without issue but last night updated from Jessie to Buster and immediately started seeing the socket issue above. Still poking around.

cgerke commented 4 years ago

Further to this, I simply removed the plugin from homebridge and re-added after the buster update and haven't seen the issue since.

Raspbian GNU/Linux Buster (10) Node.js v12.18.1 NPM v6.14.5

lukasroegner commented 4 years ago

New version is now on NPM, which points to my fork of node-appletv-x. This fork contains the fix for the "writeAfterFIN" issue.

RaymondMouthaan commented 4 years ago

Hi @lukasroegner,

Upgrading the plugin to 0.8.6 gives the following error:

USER: root
DIR: /homebridge
CMD: npm install --save homebridge-apple-tv-remote@latest

npm ERR! prepareGitDep 1> 
npm ERR! prepareGitDep > spawn-sync@1.0.15 postinstall /root/.npm/_cacache/tmp/git-clone-2a4912e7/node_modules/caporal/node_modules/spawn-sync
npm ERR! prepareGitDep > node postinstall
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > protobufjs@6.9.0 postinstall /root/.npm/_cacache/tmp/git-clone-2a4912e7/node_modules/protobufjs
npm ERR! prepareGitDep > node scripts/postinstall
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > node-appletv-x@1.0.18 prepare /root/.npm/_cacache/tmp/git-clone-2a4912e7
npm ERR! prepareGitDep > npm run build
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > node-appletv-x@1.0.18 build /root/.npm/_cacache/tmp/git-clone-2a4912e7
npm ERR! prepareGitDep > npm run clean
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 2> npm WARN install Usage of the `--dev` option is deprecated. Use `--only=dev` instead.
npm ERR! prepareGitDep npm WARN deprecated @types/ora@3.2.0: This is a stub types definition. ora provides its own type definitions, so you do not need this installed.
npm ERR! prepareGitDep npm ERR! missing script: clean
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /root/.npm/_logs/2020-06-21T07_56_23_407Z-debug.log
npm ERR! prepareGitDep npm ERR! code ELIFECYCLE
npm ERR! prepareGitDep npm ERR! errno 1
npm ERR! prepareGitDep npm ERR! node-appletv-x@1.0.18 build: `npm run clean`
npm ERR! prepareGitDep npm ERR! Exit status 1
npm ERR! prepareGitDep npm ERR! 
npm ERR! prepareGitDep npm ERR! Failed at the node-appletv-x@1.0.18 build script.
npm ERR! prepareGitDep npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /root/.npm/_logs/2020-06-21T07_56_23_421Z-debug.log
npm ERR! prepareGitDep npm ERR! code ELIFECYCLE
npm ERR! prepareGitDep npm ERR! errno 1
npm ERR! prepareGitDep npm ERR! node-appletv-x@1.0.18 prepare: `npm run build`
npm ERR! prepareGitDep npm ERR! Exit status 1
npm ERR! prepareGitDep npm ERR! 
npm ERR! prepareGitDep npm ERR! Failed at the node-appletv-x@1.0.18 prepare script.
npm ERR! prepareGitDep npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /root/.npm/_logs/2020-06-21T07_56_23_474Z-debug.log
npm ERR! prepareGitDep 
npm ERR! premature close

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-06-21T07_56_23_645Z-debug.log

Command failed. Please review log for details.
lukasroegner commented 4 years ago

Have you tried with sudo?

RaymondMouthaan commented 4 years ago

Have you tried with sudo?

npm install --save homebridge-apple-tv-remote@latest runs as root, as you can see at the top of the log file. However running it as sudo just doesn't help either ...

lukasroegner commented 4 years ago

I think the issue is that the dependency "node-appletv-x" is already installed, but now re-installed and updated from a different source. Can you try to uninstall the plugin (which should also uninstall "node-appletv-x" and reinstall it?

RaymondMouthaan commented 4 years ago

I am sorry but that didn't help either ... I uninstalled 0.8.5, restarted Homebridge and tried installing 0.8.6, but the same error occures ... it complains about a missing clean script ???

lukasroegner commented 4 years ago

This is what I did to check if installation works:

npm uninstall -g node-appletv-x
npm uninstall -g homebridge-apple-tv-remote
sudo npm install -g homebridge-apple-tv-remote
RaymondMouthaan commented 4 years ago

Did exactly what you did ...

/homebridge # npm uninstall -g node-appletv-x
up to date in 0.043s
/homebridge # npm uninstall -g homebridge-apple-tv-remote

up to date in 0.048s
/homebridge # 
/homebridge # 
/homebridge # sudo npm install -g homebridge-apple-tv-remote
npm ERR! prepareGitDep 1> 
npm ERR! prepareGitDep > spawn-sync@1.0.15 postinstall /root/.npm/_cacache/tmp/git-clone-2c257371/node_modules/caporal/node_modules/spawn-sync
npm ERR! prepareGitDep > node postinstall
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > protobufjs@6.9.0 postinstall /root/.npm/_cacache/tmp/git-clone-2c257371/node_modules/protobufjs
npm ERR! prepareGitDep > node scripts/postinstall
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > node-appletv-x@1.0.18 prepare /root/.npm/_cacache/tmp/git-clone-2c257371
npm ERR! prepareGitDep > npm run build
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > node-appletv-x@1.0.18 build /root/.npm/_cacache/tmp/git-clone-2c257371
npm ERR! prepareGitDep > npm run clean
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 2> npm WARN install Usage of the `--dev` option is deprecated. Use `--only=dev` instead.
npm ERR! prepareGitDep npm WARN deprecated @types/ora@3.2.0: This is a stub types definition. ora provides its own type definitions, so you do not need this installed.
npm ERR! prepareGitDep npm ERR! missing script: clean
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /root/.npm/_logs/2020-06-21T08_31_21_165Z-debug.log
npm ERR! prepareGitDep npm ERR! code ELIFECYCLE
npm ERR! prepareGitDep npm ERR! errno 1
npm ERR! prepareGitDep npm ERR! node-appletv-x@1.0.18 build: `npm run clean`
npm ERR! prepareGitDep npm ERR! Exit status 1
npm ERR! prepareGitDep npm ERR! 
npm ERR! prepareGitDep npm ERR! Failed at the node-appletv-x@1.0.18 build script.
npm ERR! prepareGitDep npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /root/.npm/_logs/2020-06-21T08_31_21_181Z-debug.log
npm ERR! prepareGitDep npm ERR! code ELIFECYCLE
npm ERR! prepareGitDep npm ERR! errno 1
npm ERR! prepareGitDep npm ERR! node-appletv-x@1.0.18 prepare: `npm run build`
npm ERR! prepareGitDep npm ERR! Exit status 1
npm ERR! prepareGitDep npm ERR! 
npm ERR! prepareGitDep npm ERR! Failed at the node-appletv-x@1.0.18 prepare script.
npm ERR! prepareGitDep npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /root/.npm/_logs/2020-06-21T08_31_21_233Z-debug.log
npm ERR! prepareGitDep 
npm ERR! premature close

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-06-21T08_31_21_275Z-debug.log
lukasroegner commented 4 years ago

If you try to install the previous version of the plugin, does that still work?

RaymondMouthaan commented 4 years ago

Yes that still works:

/homebridge # sudo npm install -g homebridge-apple-tv-remote@0.8.5

> protobufjs@6.9.0 postinstall /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/protobufjs
> node scripts/postinstall

> spawn-sync@1.0.15 postinstall /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/spawn-sync
> node postinstall

+ homebridge-apple-tv-remote@0.8.5
added 210 packages from 170 contributors in 11.567s
lukasroegner commented 4 years ago

What about

npm install -g node-appletv-x

vs.

npm install -g https://github.com/lukasroegner/node-appletv-x.git
RaymondMouthaan commented 4 years ago

The first command executes successful, but the second causes the error, apparently the fork doesn't want to get installed ...

lukasroegner commented 4 years ago

That is super strange. The only thing that I changed is a line of code and the version number...

RaymondMouthaan commented 4 years ago

Let me setup a new homebridge container to see if that solves the issue of installing the fork..

[update] in a container where neither node-appletv-x nor lukasroegner/node-appletv-x.git nor homebridge-apple-tv-remote has been installed before:

npm install -g https://github.com/lukasroegner/node-appletv-x.git still fails :(

lukasroegner commented 4 years ago

In the same container, does node-appletv-x install properly?

RaymondMouthaan commented 4 years ago

yes it does:

/homebridge # npm install -g node-appletv-x
/usr/local/bin/appletv -> /usr/local/lib/node_modules/node-appletv-x/bin/appletv

> spawn-sync@1.0.15 postinstall /usr/local/lib/node_modules/node-appletv-x/node_modules/spawn-sync
> node postinstall

> protobufjs@6.9.0 postinstall /usr/local/lib/node_modules/node-appletv-x/node_modules/protobufjs
> node scripts/postinstall

+ node-appletv-x@1.0.17
added 164 packages from 142 contributors in 7.602s
DJay-X commented 4 years ago

@lukasroegner I tried to update with config-ui-x and run into this error.

USER: pi
DIR: /usr/local/lib
CMD: sudo -E -n npm install homebridge-apple-tv-remote@latest

npm ERR! prepareGitDep 1> 
npm ERR! prepareGitDep > spawn-sync@1.0.15 postinstall /home/pi/.npm/_cacache/tmp/git-clone-36d51fed/node_modules/caporal/node_modules/spawn-sync
npm ERR! prepareGitDep > node postinstall
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > protobufjs@6.9.0 postinstall /home/pi/.npm/_cacache/tmp/git-clone-36d51fed/node_modules/protobufjs
npm ERR! prepareGitDep > node scripts/postinstall
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > node-appletv-x@1.0.18 prepare /home/pi/.npm/_cacache/tmp/git-clone-36d51fed
npm ERR! prepareGitDep > npm run build
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > node-appletv-x@1.0.18 build /home/pi/.npm/_cacache/tmp/git-clone-36d51fed
npm ERR! prepareGitDep > npm run clean
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 2> npm WARN install Usage of the `--dev` option is deprecated. Use `--only=dev` instead.
npm ERR! prepareGitDep npm WARN deprecated @types/ora@3.2.0: This is a stub types definition. ora provides its own type definitions, so you do not need this installed.
npm ERR! prepareGitDep npm ERR! missing script: clean
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /home/pi/.npm/_logs/2020-06-21T09_42_37_260Z-debug.log
npm ERR! prepareGitDep npm ERR! code ELIFECYCLE
npm ERR! prepareGitDep npm ERR! errno 1
npm ERR! prepareGitDep npm ERR! node-appletv-x@1.0.18 build: `npm run clean`
npm ERR! prepareGitDep npm ERR! Exit status 1
npm ERR! prepareGitDep npm ERR! 
npm ERR! prepareGitDep npm ERR! Failed at the node-appletv-x@1.0.18 build script.
npm ERR! prepareGitDep npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /home/pi/.npm/_logs/2020-06-21T09_42_37_359Z-debug.log
npm ERR! prepareGitDep npm ERR! code ELIFECYCLE
npm ERR! prepareGitDep npm ERR! errno 1
npm ERR! prepareGitDep npm ERR! node-appletv-x@1.0.18 prepare: `npm run build`
npm ERR! prepareGitDep npm ERR! Exit status 1
npm ERR! prepareGitDep npm ERR! 
npm ERR! prepareGitDep npm ERR! Failed at the node-appletv-x@1.0.18 prepare script.
npm ERR! prepareGitDep npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /home/pi/.npm/_logs/2020-06-21T09_42_37_673Z-debug.log
npm ERR! prepareGitDep 
npm ERR! premature close

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2020-06-21T09_42_37_971Z-debug.log

Command failed. Please review log for details.

2020-06-21T09_42_37_971Z-debug.log 2020-06-21T09_42_37_359Z-debug.log

adamrzanek commented 4 years ago

I have the same problem

lukasroegner commented 4 years ago

@RaymondMouthaan What happens if you install the node-appletv-x package via git (https://github.com/stickpin/node-appletv-x.git)?

RaymondMouthaan commented 4 years ago

Unfortunately,it doesn't install for the same reason.

lukasroegner commented 4 years ago

@RaymondMouthaan Can you try again? I updated the fork.

RaymondMouthaan commented 4 years ago

@lukasroegner,

Now it installs as it suppose to be 💯

/homebridge # npm install -g https://github.com/lukasroegner/node-appletv-x.git
/usr/local/bin/appletv -> /usr/local/lib/node_modules/node-appletv-x/bin/appletv
+ node-appletv-x@1.0.19
updated 1 package in 9.834s

[update] Also homebridge-apple-tv-remote 0.8.6 installs fine now 👍

lukasroegner commented 4 years ago

Then the plugin can also be installed.

For your info: there has been an unused/non-exisiting script in the package.json of the original project, named "clean".

RaymondMouthaan commented 4 years ago

Then the plugin can also be installed.

For your info: there has been an unused/non-exisiting script in the package.json of the original project, named "clean".

Ah that explains it 👍 , meanwhile I installed homebridge-apple-tv-remote 0.8.6 on my prd homebridge container, lets see if it runs more stable, however I didn't face issues on 0.8.5 before.

sschuste commented 4 years ago

@lukasroegner Installation was smooth and without any problems. But I have the problem that the load of the Raspi increases more than I expect. Normally my Raspi is working at 5% load. After installing the plugin and restarting the homebridge the load increases to 25%. At the same time the temperature of the Raspi climbs by 10 ºC.

The log is flooded with warnings from the plugins homebridge-zp and homebridge-hue (by ebaauw). These two plugins log a "drift" indicating that something is blocking the Nodejs process. See https://github.com/ebaauw/homebridge-zp/issues/127.

Of course the warnings of other plugins are not your concern. But the load, the temperature rise and the log entries belong together. As soon as I uninstall your plugin, the temperature and load will drop and the warnings will disappear from the log. Something is consuming resources on my Raspi and I can only imagine that it's about the network. I haven't done any more measurements yet, but I'd like to know if you know about the issue.

I use a Raspi 4 with 4GB RAM. Should be enough, right?

lukasroegner commented 4 years ago

@sschuste Yes, that should be more than enough. #45 describes the same problem. I'm now at the point where I think it is necessary to deep dive into the node-appletv-x library. It may be an issue with connections not being closed properly, so that more and more connections are kept open, consuming CPU.

whreams commented 4 years ago

Try to install the latest update, but get "xcode-select: note: no developer tools were found at '/Applications/Xcode.app'". Previous version didn't have this for some reason. While I do have Xcode installed, I don't really use it so unsure what changed. Went to the Apple Developer website and installed the latest Command Line Tools for Xcode (11.5) but still no change.

lukasroegner commented 4 years ago

@whreams This is due to the fact that a dependency points to GitHub. Git is part of xcode-select (or Xcode) on macOS.

whreams commented 4 years ago

Thanks for the explanation. Didn't have the issue previously, but do on this attempted install. How would I solution it?

whreams commented 4 years ago

False Alarm - apologies. Got my development vs production machines mixed up.

whreams commented 4 years ago

Just had a power outage. All is recovered, but the logs now show " Error while sending heartbeat: undefined". In my attempts to use the plugin to get everything in the right state, I get the following:

[6/23/2020, 12:48:49 PM] [Apple TV Platform] [ATVGrandHall] Error while pressing key topmenu: undefined [6/23/2020, 12:48:49 PM] [Apple TV Platform] [ATVGrandHall] Giving up. Error while switching on

Suggestions?

whreams commented 4 years ago

After re-pairing my ATV, all worked well for 2 days, then for some reason I woke up this AM to the below error. [Apple TV Platform] [ATVGrandHall] Error while sending heartbeat: undefined

Suggestions?

lukasroegner commented 4 years ago

After re-pairing my ATV, all worked well for 2 days, then for some reason I woke up this AM to the below error. [Apple TV Platform] [ATVGrandHall] Error while sending heartbeat: undefined

Suggestions?

Not really, I haven't had time to extensively check the issues (high CPU usage, disconnects, error messages).

lukasroegner commented 3 years ago

Error while sending heartbeat: undefined

I've tested the plugin during the weekend. Sadly, I haven't gotten a single error with sending the heartbeat. What I can clearly say now is:

High CPU load

I let the plugin run overnight, no CPU spikes during this testing period. I assume that the CPU load issues are also due to the socket being closed. Let's see if the new version solves your CPU issues.

sschuste commented 3 years ago

No changes on me. I don't have any problems with a crash of the plugin anymore, but the load still increases from 7% to 25% after I have installed and configured the plugin and restarted the homebridge.

I tried to read the log in debug mode, but of course this is an incredible amount of information. What should I look for?

To avoid a faulty installation of my Raspi 4, I installed the plugin on another homebridge. This homebridge is simply available at my place, but has no tasks to do. As a result, the utilization of this Raspi (3B) was 0%. After installing the plugin it increased to 28%.

Of course I don't see any CPU spikes either. The load simply increases and then stays at that level.

Boscosticks commented 3 years ago

Yo @lukasroegner

I've been using this plugin for the last few months without any issues. It's been super awesome to have within HomeKit. Yesterday, I updated to the tvOS 14 beta. Everything worked as intended, but today I started getting crashes/errors you have listed here.

Hardware:

  1. Headless raspberry pi 4
  2. Apple TV 4K

OS/Versions:

  1. HOOBS - 3.2.6
  2. Node - 12.14.1
  3. tvOS 14 (beta)

Steps To Repro:

  1. Have homebridge running.
  2. Attempt to turn your Apple TV on/off via switch in Homekit.
  3. Notice that homebridge shuts down.

Here is my config setup: { "platform": "AppleTvPlatform", "plugin_map": { "plugin_name": "homebridge-apple-tv-remote" }, "name": "Apple TV Platform", "scanTimeout": 10, "devices": [ { "name": "Doc Brown", "credentials": "xxx", "isOnOffSwitchEnabled": true, "onOffSwitchName": "Apple TV", "isPlayPauseSwitchEnabled": false, "playPauseSwitchName": "xxx" } ], "isApiEnabled": false } ] }

Here is my log after I attempt to turn off the Apple TV via HomeKit switch:

7/17/2020, 4:48:52 PM Bridge is running on port 51826. 7/17/2020, 4:49:00 PM [Apple TV Platform] [Doc Brown] Connected 7/17/2020, 4:49:00 PM [Apple TV Platform] [Doc Brown] Error while sending heartbeat: Socket closed. 7/17/2020, 4:54:34 PM [Apple TV Platform] [Doc Brown] On/off switch changed to false 7/17/2020, 4:54:34 PM [Apple TV Platform] [Doc Brown] Getting power state... 7/17/2020, 4:54:34 PM [Apple TV Platform] [Doc Brown] Returning cached value true for power state 7/17/2020, 4:54:34 PM [Apple TV Platform] [Doc Brown] Pressing key topmenu... 7/17/2020, 4:54:44 PM [Apple TV Platform] [Doc Brown] Connected 7/17/2020, 4:54:44 PM [Apple TV Platform] [Doc Brown] Error while pressing key topmenu: undefined 7/17/2020, 4:54:44 PM [Apple TV Platform] [Doc Brown] Pressing key topmenu... 7/17/2020, 4:54:54 PM [Apple TV Platform] [Doc Brown] Connected 7/17/2020, 4:54:54 PM Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:200:27) 7/17/2020, 4:54:54 PM Got SIGTERM, shutting down Bridge... 7/17/2020, 4:54:54 PM [Apple TV Platform] Shutting down Apple TV clients... 7/17/2020, 4:54:55 PM [Apple TV Platform] [Doc Brown] Error while pressing key topmenu: TypeError: Cannot read property 'sendKeyPress' of null 7/17/2020, 4:54:55 PM [Apple TV Platform] [Doc Brown] Giving up. Error while switching off

Thanks!

MsCopernic commented 3 years ago

Hi, I don't know what OS is being used by the persons that are reporting problems with this plugin, in my case I downloaded the Raspberry PI Raspbian image (from https://github.com/homebridge/homebridge-raspbian-image) and it's been running with 0 errors now for many months. I really appreciate the work done by lukasroegnser, I was using another software for my apple tv's (https://github.com/lprhodes/homebridge-apple-tv) that at the end gave me nothing but problems.

rohan-buechner commented 3 years ago

First time installing this plugin. The device pairing worked fine (via node-appletv-x) The TV switch is appearing on my Apple Home views (see below)

2020-07-28 at 18 32

But upon clicking the switch my homebridge dies with the following logs. (I've also seen this heartbeat issue mentioned elsewhere in here)

2020-07-28 at 18 34

My apply TV is currently on the latest tvOS14.

I've also seen this log printed after another failed attempt.

[7/28/2020, 6:32:39 PM] Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:455:14)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:154:37
    at new Promise (<anonymous>)
    at Connection.sendProtocolMessage (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:134:16)
    at Connection.send (/usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/connection.js:130:21)
    at /usr/local/lib/node_modules/homebridge-apple-tv-remote/node_modules/node-appletv-x/dist/lib/appletv.js:182:22
sschuste commented 3 years ago

After I noticed that there is a new update, I started the next attempt. I had this stupid load problem all the time and the temperature rise. In the end I had to uninstall your plugin.

I am thrilled! Now your plugin runs even with my setup. Load is stable, and so is the temperature of the Raspi.

Lukas, thank you very much for the effort you put into this plugin. My apartment has become a little more beautiful again. I only use the plugin to switch the ATV on and off. I can't say anything about all the other functions, but what I need works just fine.

try-and-error-and-repeat commented 3 years ago

Hey are you still on the part with the delayed messages since tvOS 14 it happens very often? Thank you for your work 😁

lukasroegner commented 3 years ago

@try-and-error-and-repeat I haven't had issues with delayed responses from the Apple TV in the past and cannot reproduce this issue on tvOS. It still seems to depend on the host system and/or network configuration.

I'm running the plugin on a Raspberry Pi 4, connected via Ethernet, plain Homebridge (no HOOBS), Amplifi router. The switches are updated within milliseconds.