nfarina / homebridge-sonos

Sonos plugin for homebridge: https://github.com/nfarina/homebridge
155 stars 52 forks source link

Error while starting homebridge #55

Closed Tigrecito closed 5 years ago

Tigrecito commented 5 years ago

Today I updated my sonos speakers and also updated homebridge to current version. After reboot, I get these errors while starting homebridge: (currently it´s not possible to start homebridge without removing the plugin from config.json)

any ideas?

/usr/lib/node_modules/homebridge-sonos/index.js:174 topology.zones.forEach(function (group) { ^ TypeError: Cannot read property 'forEach' of null at SonosAccessory. (/usr/lib/node_modules/homebridge-sonos/index.js:174:56) at /usr/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:856:7 at Parser. (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:483:18) at emitOne (events.js:116:13) at Parser.emit (events.js:211:7) at SAXParser.onclosetag (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:444:26) at emit (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:624:35) at emitNode (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:629:5) at closeTag (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:889:7) at SAXParser.write (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:1436:13)

t1mlopez commented 5 years ago

Same

nfarina commented 5 years ago

The undefined ‘zones’ property makes it look like the Sonos API has changed in some way. There was a Homebridge update today but I don’t think that would cause this issue - if you want to try downgrading to the last published version of Homebridge it might be nice to verify that anyway though.

xMAIKx commented 5 years ago

Same

normanmaurer commented 5 years ago

Same problem here after only updating Sonos. So it has nothing to do with Homebridge itself.

ibjr commented 5 years ago

Same here; only Sonos updated. Sonos does not provide any information when requesting http://sonos-ip-adres:1400/status/topology. (result: <?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="/xml/review.xsl"?> )

ibjr commented 5 years ago

Result: no data between ZPSupportInfo and /ZPSupportInfo

rheid commented 5 years ago

I have now the same issue. Is there a fix possible?

rheid commented 5 years ago

Same on my site: TypeError: Cannot read property 'forEach' of null at SonosAccessory. (/usr/local/lib/node_modules/homebridge-sonos/index.js:174:56) at /usr/local/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:856:7 at Parser. (/usr/local/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:483:18) at emitOne (events.js:116:13) at Parser.emit (events.js:211:7) at SAXParser.onclosetag (/usr/local/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:444:26) at emit (/usr/local/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:624:35) at emitNode (/usr/local/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:629:5) at closeTag (/usr/local/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:889:7) at SAXParser.write (/usr/local/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:1436:13)

roe1974 commented 5 years ago

i think its due to the SONOS Update from today, v9.1 :-(

nfarina commented 5 years ago

Sure enough, mine broke today as well. Looking into it!

nfarina commented 5 years ago

OK so I've published a quick "fix" for this problem - I simply reverted to my original "discovery" logic that looks for the first controllable Sonos device.

I wasn't able to fix the code mostly written by @fwboettger, which is way more complex and covers a bunch of stuff like "coordinators" that I don't really understand (I guess my Sonos setup isn't very fancy). So I welcome any contributions to restore that logic, and especially to make it simpler and easier to understand (or at least extracting the deeply nested loops into functions in a separate module).

EDIT: The process still crashes due to a socket error after a while. Investigating.

nfarina commented 5 years ago

OK, looks like the sonos module itself has stopped working with 9.1. It seems Sonos is set to launch their official developer program today - once that opens up I'll look into fixing this to work with the new API.

rheid commented 5 years ago

Thanks Nick for your work!! I love to get running again. The same on my site: The process still crashes due to a socket error after a while. Investigating.

iRonin commented 5 years ago

Mine is still not working. Here are the logs (see how it found the same accessory on two IP addresses):

[2018-9-7 15:27:36] [Living Room Speakers] Found a playable device at 192.168.0.52 for room 'Living Room'
[2018-9-7 15:27:37] [Living Room Speakers] Found a playable device at 192.168.0.214 for room 'Living Room'
Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running
    at Socket._healthCheck (dgram.js:638:11)
    at Socket.close (dgram.js:516:8)
    at SonosAccessory.<anonymous> (/homebridge/node_modules/homebridge-sonos/index.js:187:23)
    at /homebridge/node_modules/sonos/lib/sonos.js:764:7
    at Parser.<anonymous> (/homebridge/node_modules/xml2js/lib/xml2js.js:483:18)
    at emitOne (events.js:116:13)
    at Parser.emit (events.js:211:7)
    at SAXParser.onclosetag (/homebridge/node_modules/xml2js/lib/xml2js.js:444:26)
    at emit (/homebridge/node_modules/sax/lib/sax.js:624:35)
    at emitNode (/homebridge/node_modules/sax/lib/sax.js:629:5)
    at closeTag (/homebridge/node_modules/sax/lib/sax.js:889:7)
    at SAXParser.write (/homebridge/node_modules/sax/lib/sax.js:1436:13)
    at Parser.exports.Parser.Parser.parseString (/homebridge/node_modules/xml2js/lib/xml2js.js:502:31)
    at Parser.parseString (/homebridge/node_modules/xml2js/lib/xml2js.js:7:59)
    at Request._callback (/homebridge/node_modules/sonos/lib/sonos.js:760:27)
    at Request.self.callback (/homebridge/node_modules/sonos/node_modules/request/request.js:198:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/homebridge/node_modules/sonos/node_modules/request/request.js:1035:10)
    at emitOne (events.js:121:20)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/homebridge/node_modules/sonos/node_modules/request/request.js:962:12)

Then it says

[2018-9-7 15:27:42] [Living Room Speakers] Found a playable device at 192.168.0.52 for room 'Living Room'

and

[2018-9-7 15:27:47] Homebridge is running on port 51826.
Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running
    at Socket._healthCheck (dgram.js:638:11)
    at Socket.send (dgram.js:435:8)
    at /homebridge/node_modules/sonos/lib/sonos.js:1047:19
    at Array.map (<anonymous>)
    at Timeout.sendDiscover [as _onTimeout] (/homebridge/node_modules/sonos/lib/sonos.js:1046:44)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)

Then again:

[2018-9-7 15:27:56] [Living Room Speakers] Found a playable device at 192.168.0.150 for room 'Living Room'

And it just keeps restarting…

iRonin commented 5 years ago

I checked my router and there are 4 SonosZP devices connected and one Living-Room but I think that's Apple TV.

ebaauw commented 5 years ago

See https://github.com/bencevans/node-sonos/issues/332.

lsmith07 commented 5 years ago

I appreciate the work being done to resolve. Optimistically looking forward to an update. In the interim, I removed my Sonos accessory lines from the Homebridge config.json file. It removed all of my speakers from Homekit and my scenes, but at least Homebridge stopped failing and all of my other Homebridge accessories are functioning normally again.

AlfaJackal commented 5 years ago

Same here like Ismith07: Removed all devices. Hopefully a fix (and after that new features like volume, choose playlist, etc.) will come soon! Appreciate any infos for possible next steps...

jcleek commented 5 years ago

The note ebaauw posted shows it is possible to work. Just need the dev of the plugin to fix it now.

williamli commented 5 years ago

This package seems to be using a rather old version of node-sonos (0.12.1), node-sonos 1.5 fixed resolved this problem... I wonder if there could be a quick fix by just upgrading from 0.12.1 to 1.5.1.

jcleek commented 5 years ago

I can tell you I installed node-sonos and it didn't fix homebridge. I am certainly no expert.

cvuzem commented 5 years ago

same here..removed the Sonos accessories to start the home bridge again. I hope someone can help.....

sebskuse commented 5 years ago

I was also getting the ERR_SOCKET_DGRAM_NOT_RUNNING error shortly after starting homebridge. Uninstalling homebridge-sonos from here and directly installing @antonino-u's fix in #57 appears to have resolved the issue

nfarina commented 5 years ago

OK this seems to be fixed now that #57 has been merged!

This still uses my original simplified discovery logic. If anyone wants to take a stab at fixing the fancier discovery code as described here I welcome a PR!

nfarina commented 5 years ago

FYI, this is how I upgraded my plugin: sudo npm install -g homebridge-sonos@latest.

Your command may vary depending on how you installed homebridge.

[edited to add -g option]

jcleek commented 5 years ago

Still not working for me. Sees all of my stuff as before, but Homebridge continues to crash seconds after starting with:

Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running at Socket._healthCheck (dgram.js:638:11) at Socket.send (dgram.js:435:8) at /usr/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:1047:19 at Array.map (<anonymous>) at Timeout.sendDiscover [as _onTimeout] (/usr/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:1046:44) at ontimeout (timers.js:498:11) at tryOnTimeout (timers.js:323:5) at Timer.listOnTimeout (timers.js:290:5) I upgraded with sudo npm install homebridge-sonos@latest as Nick indicated, then rebooted just to be safe.

nfarina commented 5 years ago

Ah crap - I mistyped my example upgrade command - there's supposed to be a -g in there because homebridge plugins are traditionally installed globally. Can you see if that's the issue? you probably installed the plugin in whatever directory you happened to be in at the time, and that won't be detected by homebridge.

jcleek commented 5 years ago

Winner Winner Chicken Dinner!

sudo npm install -g homebridge-sonos@latest

DarthXoc commented 5 years ago

@nfarina, are you able to confirm if the new build is compatible with stereo pairs? Everything seems to be back up on my end except a stereo pair that appears to be always 'on' and shows an error icon in Home.app.

nfarina commented 5 years ago

Unfortunately I don't own a stereo pair :(

DarthXoc commented 5 years ago

Dang! :-(

Well, here's the output from the console if that helps. Nothing obvious is jumping out at me but maybe there's something in there you (or someone else) might notice:

[2018-9-18 15:11:45] [Kitchen Speaker] Found a playable device at 10.0.3.16 for room 'Kitchen' [2018-9-18 15:11:45] [Kitchen Speaker] Found a playable device at 10.0.3.125 for room 'Kitchen' events.js:165 throw er; // Unhandled 'error' event ^

Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running at Socket._healthCheck (dgram.js:638:11) at Socket.close (dgram.js:516:8) at Search.destroy (/usr/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:1089:15) at SonosAccessory. (/usr/lib/node_modules/homebridge-sonos/index.js:187:16) at /usr/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:764:7 at Parser. (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:483:18) at Parser.emit (events.js:180:13) at SAXParser.onclosetag (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:444:26) at emit (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:624:35) at emitNode (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:629:5) at closeTag (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:889:7) at SAXParser.write (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:1436:13) at Parser.exports.Parser.Parser.parseString (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:502:31) at Parser.parseString (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:7:59) at Request._callback (/usr/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:760:27) at Request.self.callback (/usr/lib/node_modules/homebridge-sonos/node_modules/request/request.js:198:22) at Request.emit (events.js:180:13) at Request. (/usr/lib/node_modules/homebridge-sonos/node_modules/request/request.js:1035:10) at Request.emit (events.js:185:15) at IncomingMessage. (/usr/lib/node_modules/homebridge-sonos/node_modules/request/request.js:962:12) at IncomingMessage.emit (events.js:185:15) at endReadableNT (_stream_readable.js:1106:12) Emitted 'error' event at: at Parser.exports.Parser.Parser.parseString (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:506:16) at Parser.parseString (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:7:59) [... lines matching original stack trace ...] at endReadableNT (_stream_readable.js:1106:12) at process._tickCallback (internal/process/next_tick.js:178:19)

nfarina commented 5 years ago

@DarthXoc Isn't that the same socket error that was fixed with the latest update? Did you upgrade your plugin to latest?

DarthXoc commented 5 years ago

@nfarina Yes, I upgraded it. Package.json shows homebridge-sonos at 0.2.4.

It's odd, if I let HomeBridge startup as a service it starts up just fine, but then I run into the issue where my stereo pair is always showing as 'on' with the error flag in Home.app. If I kill that process and start it up as the local user, that's when I can see this error in terminal.

Edit: Occasionally it works too. I just rebooted my Pi to have to HomeBridge service start back up and it's working now. I believe this is the second time it's sporadically started working since the upgrade a few hours ago.

Edit (2): Another reboot and I've lost control and the error is back. I love software. :-P

ebaauw commented 5 years ago

For stereo pairs, you might have a lookup at homebridge-zp. It also handles home theatre setups.

lsmith07 commented 5 years ago

I'm having the same issue as DarthXoc. I also have a stereo pair in my kitchen and after updating my package to 0.2.4 I get the error below:

[9/19/2018, 9:12:31 PM] [Kitchen Speakers] Found a playable device at 10.0.1.16 for room 'Kitchen' [9/19/2018, 9:12:31 PM] [Kitchen Speakers] Found a playable device at 10.0.1.18 for room 'Kitchen' events.js:160 throw er; // Unhandled 'error' event ^

Error: Not running at Socket._healthCheck (dgram.js:530:11) at Socket.close (dgram.js:424:8) at Search.destroy (/usr/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:1089:15) at SonosAccessory. (/usr/lib/node_modules/homebridge-sonos/index.js:187:16) at /usr/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:764:7 at Parser. (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:483:18) at emitOne (events.js:96:13) at Parser.emit (events.js:188:7) at Object.onclosetag (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:444:26) at emit (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:624:35) at emitNode (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:629:5) at closeTag (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:889:7) at Object.write (/usr/lib/node_modules/homebridge-sonos/node_modules/sax/lib/sax.js:1436:13) at Parser.exports.Parser.Parser.parseString (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:502:31) at Parser.parseString (/usr/lib/node_modules/homebridge-sonos/node_modules/xml2js/lib/xml2js.js:7:59) at Request._callback (/usr/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:760:27)

Wish I knew enough to help debug beyond contributing my errors...:-(