geraldoramos / nikola

⚡Unofficial cross-platform desktop app to monitor and control Tesla vehicles, powered by Electron & React
https://nikola.site
MIT License
149 stars 43 forks source link

Polling too often for multiple car accounts #30

Closed traviscollins closed 5 years ago

traviscollins commented 5 years ago

I own two vehicles in one tesla account. I found that I'm not able to use the Tesla app or Tesla Homekit services when the Nikola app is open. It appears the Nikola app is polling at the max rate limit for one vehicle. When you have more than one, the Nikola app reports 408 errors and nothing else works.

I think the Nikola app polling should be slowed way down when running in the background. For example, it could just not poll in the background or poll once every five minutes. Then when the app is opened, speed up polling - but take into account the number of vehicles in the account so as to avoid the per account max rate limit.

geraldoramos commented 5 years ago

It currently does 10s polling but only when the window is open. It will not hit Tesla servers if the main window is not visible. Do you think the 10s (when the user is engaging with the window) is still too much?

traviscollins commented 5 years ago

I didn’t have the window open (but was having that window can’t be seen issue). I went on a walk, and found that the Tesla app wasn’t working. When I came home I pushed my HomeKit button and found it wasn’t working. Then returned to my desk, shutdown the app, and a few minutes later it all started working. Maybe environmental - but I also saw 408 error logs.

Nothing else in my setup polls for information. Just single click button requests.

On Jun 19, 2019, at 4:58 PM, Geraldo Ramos notifications@github.com wrote:

It currently does 10s polling but only when the window is open. It will not hit Tesla servers if the main window is not visible. Do you think the 10s (when the user is engaging with the window) is still too much?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

geraldoramos commented 5 years ago

I have a logic in the polling mechanism that if main window is not visible, the portion of the code that retrieves data from Tesla does not run.

You can test by running the app from the console. Every time it hits tesla API, it will log Hitting Tesla API on Wed Jun 19 2019 16:42:09 GMT-0600 (Mountain Daylight Time). You can just hide the window and monitor the console and see if it runs

I just tested here and confirmed that it will not poll anything if the window is hidden. I believe the behavior you described could be related to the delay from Tesla servers to open up again once it's "closed".

With that said, I will increase the polling time on the next release, I think it's reasonable to make it longer anyway.

Let me know if you find that for some reason the app is polling even with the window not visible.

Thanks