dhleong / ps4-waker

Wake your PS4 over LAN (with help from the Playstation App)
MIT License
451 stars 40 forks source link

ps4-waker search causing over 100% cpu usage #127

Closed Jafalex closed 4 years ago

Jafalex commented 4 years ago

I believe everything is fine with my install of Homebridge, node, etc.

I just installed cmdswitch2 and ps4-waker and only have two switches within the cmdSwitch2 platform. I realised that when running Homebridge, the 6 core CPU on my new 2019 Mac mini go well over 100% usage, to the point the OS is barely responsive enough to allow me to shut down Homebridge via Terminal.

Fiddling around in my config.json, the problem goes completely away when I remove this line:

"state_cmd": "npx ps4-waker search | grep -i '200 Ok'"

Note 1: For some reason I can only run ps4-waker with npx, otherwise I get command not found. Note 2: if I run the ps4-waker search command directly in the terminal using npx, cpu usage peaks to 25% for 2 seconds. It's like the process is hanging or something when used via Homebridge?

Edit: in activity monitor I can see a handful of node processes going nuts when the issue is present.

Hopefully someone can help me debug this!

Here's the platform:

{ "platform": "cmdSwitch2", "name": "CMD Switch", "switches": [ { "name" : "PS4", "on_cmd": "npx ps4-waker", "off_cmd": "npx ps4-waker standby", "state_cmd": "npx ps4-waker search | grep -i '200 Ok'", "polling": true, "interval": 5, "timeout": 2000, "manufacturer": "Sony Corporation", "model": "PS4", "serial": "PS4" }, { "name" : "FIFA 20", "on_cmd": "npx ps4-waker start CUSA15545", "off_cmd": "npx ps4-waker remote ps", "state_cmd": "npx ps4-waker search | grep -i 'CUSA15545'", "polling": true, "interval": 5, "timeout": 2000, "manufacturer": "Sony Corporation", "model": "PS4", "serial": "PS4" } ] }

Jafalex commented 4 years ago

Well, I've solved my issue but created another. For those interested:

  1. After writing my original post, I went back and tracked why I had to use npx.
  2. Turns out I was running node@latest and not node@stable, I thought it was worth trying with stable.
  3. I had to reinstall all my node modules, including ps4-waker, to get Homebridge to boot error-free.
  4. ps4-waker now launching without using npx
  5. CPU usage back to minimal ...
  6. Oops ps4-waker can't find the ps4 anymore

Could not detect any matching PS4 device

I'm searching for a solution now...

dhleong commented 4 years ago

I don't know anything about homebridge so I can't help you there. Running ps4-waker search locally doesn't really affect my CPU usage at all; I'm on a 2015 MacBook Pro. However, if interval is in milliseconds then you're setting it to run quite frequently; even if it's in seconds, that's quite a lot.

You can avoid npx with npm i -g ps4-waker to install it globally. Not doing that is the source of "command not found." (You seem to have figured that out, but for anybody coming here from the future.)

Have you followed the troubleshooting about ps4-waker not being able to find the device?

Jafalex commented 4 years ago

Thanks a lot Dhleong for supporting your community of users! I'm pretty confident this issue isn't related to Homebridge at all, so we can park that I think.

I think the mistake I made was to delete the ps4-waker device from the iOS Second Screen app. I did that to 'start fresh'... I also removed ps4-waker by running npm remove -g ps4-waker along with removing the .ps4-wake.credentials.json and removing the entry in the PS4 mobile settings.

When I first installed ps4-waker (before this drama), the second screen app on iOS had successfully registered ps4-waker as a device, despite the fact that it says it's not possible in the link you shared. So when I try to follow the steps to install ps4-waker from scratch again, I can never get the second screen app to register the ps4-waker device fully again, it's stuck on 'connecting' then times out. However everything works fine with the CLI, I add the 8 digit pin code found in the settings page of my PS4 and ps4-waker says everything should be fine next time it runs.

Now if the ps4 is ON, then I can use ps4-waker to launch an app or a game, and even turn it off. Anything after that fails though. I can't check the status of the console, and I can't turn it back ON.

This is what I get when running ps4-waker in the terminal with no parameters (used to work fine):

WAKEUP sent to device... 192.168.8.16 Logging in... Login connect refused; retrying soon Login connect refused; retrying soon Login connect refused; retrying soon Login connect refused; retrying soon Error logging in: Error: connect ECONNREFUSED 192.168.8.16:997 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1126:14) { errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect', address: '192.168.8.16', port: 997 } Unexpected error Error: No socket at /usr/local/lib/node_modules/ps4-waker/dist/device.js:561:38 at Ps4Socket. (/usr/local/lib/node_modules/ps4-waker/dist/waker.js:374:5) at Ps4Socket.emit (events.js:210:5) at Socket. (/usr/local/lib/node_modules/ps4-waker/dist/ps4socket.js:164:10) at Socket.emit (events.js:210:5) at emitErrorNT (internal/streams/destroy.js:91:8) at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) at processTicksAndRejections (internal/process/task_queues.js:80:21)

Hope that's helpful to help me troubleshoot? Thanks again for your help!

Jafalex commented 4 years ago

This confuses me even more, ps4-waker search doesn't return any error and even seems to return current state of the PS4.

ps4-waker search

{
  "type": "device",
  "statusLine": "620 Server Standby",
  "statusCode": "620",
  "status": "Standby",
  "host-id": "2CCC4492E578",
  "host-type": "PS4",
  "host-name": "Alex's PS4",
  "host-request-port": "997",
  "device-discovery-protocol-version": "00020020",
  "system-version": "06720001",
  "address": "192.168.8.16"
}

Also, forgot to ask, what's a good interval delay? The Homebridge tutorial has the 5 and 2000 as shown in my original post. Cheers

Jafalex commented 4 years ago

Looking into Node.js manual for this specific errors, it looks like ECONNREFUSED relates to:

ECONNREFUSED (Connection refused): No connection could be made because the target machine actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host.

No idea what to do with that... I didn't change anything on the PS4, and things where working 100% fine as far as controlling the ps4 goes (on the server side though... CPU was cranking to >100%). It's only since getting rid of using npx that the PS4 won't wake up from standby mode anymore.

dhleong commented 4 years ago

Being able to turn off but not on sounds like https://github.com/dhleong/ps4-waker/wiki/Troubleshooting#ps4-waker-can-put-the-ps4-to-sleep-but-not-wake-it-up .

On Wed, Oct 2, 2019 at 4:32 PM Alex notifications@github.com wrote:

Looking into Node.js manual https://nodejs.org/api/errors.html#errors_common_system_errors for this specific errors, it looks like ECONNREFUSED relates to:

ECONNREFUSED (Connection refused): No connection could be made because the target machine actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host.

No idea what to do with that... I didn't change anything on the PS4, and things where working 100% fine as far as controlling the ps4 goes (on the server side though... CPU was cranking to >100%). It's only since getting rid of using npx that the PS4 won't wake up from standby mode anymore.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dhleong/ps4-waker/issues/127?email_source=notifications&email_token=AAGHIFX6NVV76UF42IMWSP3QMUAOVA5CNFSM4I4S6H4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAGCU6A#issuecomment-537668216, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGHIFUBNGE6AUFZKG5TUQ3QMUAOVANCNFSM4I4S6H4A .

Jafalex commented 4 years ago

Hi Daniel. Yip, that's the first thing I checked after your first response. It was ticked, but somehow got unticked during all my troubleshooting... Thanks for making me check it out again.

Ticked it back just now, and now I can turn on/off the PS4.

Though the process in terminal still keeps on returning

[10/3/2019, 10:32:49 AM] Failed to determine PS4 state. [10/3/2019, 10:32:49 AM] Could not detect any matching PS4 device

These repeat at the set interval it seems... Maybe some problem with search. Hard to tell..

I guess so long as it works, I'm happy!?

Thanks for your support!!

dhleong commented 4 years ago

Glad to hear it's working for you!