amybytes / nanoleaf-desktop

A modern desktop application for the Nanoleaf Aurora and Canvas
MIT License
166 stars 13 forks source link

Improve syncing / finalizing connection #9

Closed jvivian closed 5 years ago

jvivian commented 5 years ago

Hey there,

Thank you for the great tool, the ambient lighting linked to the monitor is legitimately awesome.

It might be the old house's lead paint interfering with the wifi, but it typically takes me 3-5 attempts to sync the program to the lights. When I press and hold the power button for 5-7 seconds, the message asking me to do so instantly goes away, which leads me to believe this connection step is working: https://github.com/rowak/nanoleaf-desktop/blob/3f18e825fe5e983a2d4a274d48ee6d167d7ce594/src/io/github/rowak/nanoleafdesktop/ui/dialog/AuroraFinder.java#L132-L166 , but then it only sometimes completes finalizing the syncing connection. Usually, it will sit there with the spinning animation indefinitely until I restart the app and retry the connection. When it works, it typically instantly loads after the "hold power button" message goes away.

I'm getting some wifi repeaters soon, so can let you know if that resolves the issue.

amybytes commented 5 years ago

Hey, I'm glad you like the app!

Just to clarify, you don't need to connect every time you launch the app, right? After the device finder connects to your device it immediately stores the info in "~\AppData\Roaming\Nanoleaf for Desktop\preferences.txt". If you exit out of the app and then open it again you shouldn't be faced with the device finder, but your device should load up instead. If this isn't happening for you maybe try connecting to your device and watching the data file at the same time to see if the info is stored after the device finder closes.

Once the device finder is closed, it's job is done. Because of this, I'm thinking that the problem lies more in the main connection method. I admit that the connection code is pretty janky, but it does seem to work pretty reliably at least for me. I originally thought this might be a threading sync issue, but I tried reconnecting my lights over a dozen times and I still couldn't get the setup to fail once. This leads me to believe that there might be something on your end causing this to happen. I'm not sure how fast your wifi is, but assuming you can use the app at a decent speed (when it is working) I'd say you're probably good. Make sure your network is configured to use 2.4GHz instead of 5GHz (see here) because apparently that can interfere with the lights.

I'll do some more digging on this as well.

jvivian commented 5 years ago

@rowak — Thank you for the clarification. I'm guessing the issue is on my end and related to the poor wifi signal. Both upstairs people had to get power-over-ethernet to play games and when I try to run "ambient" mode in multiplayer games I get too much packet loss so I'm guessing this will be remedied by a couple repeaters to boost wifi signal in the house.

Currently, every time I load the app it goes to the device finder, so I'll check for the preferences.txt when I get home. I have no experience with Java, otherwise I'd try and be more helpful re: pull requests.

jvivian commented 5 years ago

@rowak -- Ok, pretty interesting. Initially, the file just contained:

windowWidth1050
windowHeight800

I failed to connect a few times so I deleted it. After I deleted it, it connected again and now properly has the device information

devices{"<IP>":"Dankleaf"}

When I close and reboot the app, preferences.txt now contains the following, and asks me to reconnect again (and fails to):

devices{"<IP>":"Dankleaf"}
windowWidth1050
windowHeight800

I don't need to delete preferences.txt to make it work, but I have to go to "change device" and reselect the device, and then it will connect. I tested this multiple times and it's reproducible. If I start the app, immediately close out of the device search, and just connect via menu > change device, it will connect but I have to pair it every time. It's odd because I'd imagine it's the same code for "change device" as is used in the initial connection attempt, so I have no idea why the former works but not the latter.

Let me know if you want me to try/test anything out!

amybytes commented 5 years ago

Thanks for all this info, I just did some testing as well and it looks like you were right! The dialog that pops up when you start the app is actually a lot different from the device changer than you'd think (it's a lot older). I'll be replacing the old device finder with the device changer in future releases.

It seems the problem with the device needing to be reconnected every time is that the device info isn't being stored in the data file. The device info for a single device is stored using the key "lastSession", and it should appear in the file even before the "devices" key does. The "devices" key simply stores a map of the names of devices with their IPs. I am genuinely confused by this since it seems this only happens to some people. Here's a few things to try:

jvivian-atreca commented 5 years ago

@rowak — Was busy this weekend, but will try to test these out soon.

jvivian commented 5 years ago

Hi @rowak -- New job and all that, sorry for the delay. I can confirm that the latest version, 0.8.3 reconnects without issue. Thank you for the fix!