sfeakes / homebridge-aqualinkd

1 stars 2 forks source link

cachedAccessories file causes accessory load error #1

Closed jhalligan1 closed 4 years ago

jhalligan1 commented 5 years ago

The homebridge and homebridge-aqualink plugins startup fine on first run, all accessories load successfully. After Ctrl+C shutdown and then restart homebridge find I need to delete /home/pi/.homebridge/accessories/cachedAccessories file to startup successfully again. See screen capture of messages in attached file.

Once it starts seems to run great.

capture-before-rm-cacheAccessories.txt capture-after-rm-cachedAccessories.txt

sfeakes commented 5 years ago

Do you have Homebridge running as a deamon? If so, can you try stopping the deamon and seeing if you get the same error? Something like sudo systemctl stop homebridge

jhalligan1 commented 5 years ago

Haven’t yet setup as demon, just running from shell prompt. I can reproduce it by starting homebridge, it creates the cacheAccessories file. Restart homebridge and error. Then rm cacheAccessories and starts fine. Almost like it’s getting confused between accessory information from aqualinkd and the cached accessory info when loading.

jhalligan1 commented 5 years ago

I’ll run the command though when home and see if something ran to set it up as such that I don’t know of.

jhalligan1 commented 5 years ago

Nothing running as deamon, tried the sudo systemctl stop homebridge. Then sudo systemctl list-unit-files and can see aqualinkd but no homebridge. Even ran sudo pkill -f homebridge, then immediately homebridge but same error loading accessories.

Only works if I delete the pi/.homebridge/accessories/cachedAccessories file.

Its reading the cachedAccessories file just it looks like it getting confused that an accessory is trying to use a UUID that is registered/cached to another accessory.

jhalligan1 commented 5 years ago

Well just as I say that ...found this... log_level parameter in /etc/aqualinkd.conf if toggled between DEBUG and INFO causes errors to disappear. See repro steps in attached. ErrorReproInDebugOnly.txt

sfeakes commented 5 years ago

Wow. I’ve been trying to reproduce this and couldn’t, so I was about to give you a lot of instructions to follow so I could get more information. I will try this now, and once reproduced I can fix the bug. I’m just so surprised that the log level in AqualinkD effected this in home ridge-AqualinkD. Thanks for playing with this to nail down how to reproduce it.

jhalligan1 commented 5 years ago

More info... noticed the platform.log error happens for about a minute after the aqualinkd service starts. I run homebridge over and over until starts successful. Homebridge seems to error until all the aqualinkd initialization finishes (asking for info, publishing accessories, etc.)

Almost like if the accessories aren't all published and homebridge tries to enumerate them the homebridge craps out. Once it gets into the listening loop, or just prior (after the heaters are published), homebridge starts and runs fine.

Hope this isn't a config issue on my side and have you chasing a ghost. Thanks again.

ErrorHappensEarly.txt

sfeakes commented 5 years ago

You have it accurate. It takes AqualinkD a minute or two to get all the information from the control panel after starting. If homekit-aqualinkd starts during this time it should use the cache accessories mixed with the limited accessories is get's from requesting the accessories direct from aqualinkd. This is what's broken. Simple temp fix is to wait 1 minute after starting AqualinkD before starting homekit-aqualinkd.

I'll post a fix soon.

jhalligan1 commented 5 years ago

Thanks. Think the first error on accessories cache was different than this one... platform.log undefined.

Noticed in index.js, you reference this.log or this.forcelog throughout to write to log. The undefined error in index.js: Line 137 show a single reference to platform.log, wondering if this should be this.log or forcelog.

For this error, don't think the code is having a problem recreating an accessory, rather think it's more erroring on log write call.

Been about 15-20 years since I coded anything so be gentle :-) Hope it helps.

sfeakes commented 5 years ago

You are right, in that platform.log will crash as it should be this.log in the context it's being executed within. But, once the code would get passed that, it would get to the next point in the code (where you showed the crash initially). So there are two problems within the code, that get initiated from the same thing (delete and re-create a device on startup).

sfeakes commented 5 years ago

I've just posted a fix. Please update and re-test. sudo npm update homebridge-aqualinkd

jhalligan1 commented 5 years ago

Away for the weekend. Will test when I get back tomorrow. Thanks again!

jhalligan1 commented 4 years ago

Took me few months to get everything re-installed & tested. I can confirm, the issue is resolved. Thanks!