qistoph/MMM-MyCommute

Bug: Heavy use of API calls

Closed this issue · 18 comments

Copy of my posting found here:
https://forum.magicmirror.builders/topic/2555/mmm-mycommute/266?page=27

Okay, played around a bit. Set the module to show times only from 5am to 5pm. And I added a “pollFrequency: 15 * 60 * 1000,” to my config.
While the first one works (the module disappears at night), the second one does not seem to work:

grafik

This is the Traffic from the last 2 days. You can see the requests are paused last night. I made changes to the poll frequency yesterday in the afternoon, no change.

The module used up nearly all of my €300 starting balance. I wonder if this will go on like this.

API calls in the last 48 hours:
grafik

API calls in the last ONE hour:

grafik

Which I do not understand: No errors. Poll Frequency of every 15 Minutes. 2 Mirrors with 4 destinations each. So 4*8=24 API calls/hour would be what I expect to see…

Config:
{
module: 'MMM-MyCommute',
position: 'top_right',
config: {
apiKey: 'apikey',
origin: 'Home Address',
pollFrequency: 15 * 60 * 1000,
startTime: '05:30',
endTime: '17:00',
destinations: [
{
destination: 'dest1',
label: 'something',
mode: 'driving',
},
{
destination: 'dest2',
label: 'another label',
mode: 'driving'
},
{
destination: 'dest3',
label: 'yet another label',
mode: 'driving',
hideDays: [0,6]
},
{
destination: 'dest4',
label: 'yet another one',
mode: 'driving'
}
]
}
},

I'm sorry to see you running out of credits so fast.

Your configuration seems fine.

Do you maybe have a module that (suspends and) resumes the MyCommute module? Looking at the code I think that would force an update, even if the polling delay has not passed since the last check.

I do use mmm-pages and of course, MMM-MyCommute is only on one of the pages. 4 Pages, rotating every 10 seconds.
I hope that this does not result in a request every 40 seconds?!

It does seem that might be the case

https://github.com/edward-shen/MMM-pages/blob/b554ee86b185b146334788e605e354b0ea358f66/MMM-pages.js#L189

My first suggestion would be to update MyCommute to not refresh (on resume) unless enough time since last check has passed

Sounds good. Seem this has to be in the MyCommute code?
I worked around it by just triggering on the workdays which are set in my calendar (which is a more elegant way anyway).
But of course, I'd love to see a solution to this.

Could you give the new brach https://github.com/qistoph/MMM-MyCommute/tree/issue17 a try and see if it reduces the number of requests?

How do I pull another branch and how do I revert back to master afterwards?

Assuming you have already cloned the repo from git:

cd modules/MMM-MyCommute
git checkout issue17

Then restart MagicMirror.

To revert back to the regular version

git checkout master

Done so. Does it pull the changes with the checkout command? "git pull" gave me an "already up to date" afterwards.

I'll see and report back in a while.

The first time a branch is cloned, the latest changes are automatically pulled. To update a branch later on you would indeed use 'git pull'.

Looking forward to your report.

Okay, running on test branch since yesterday evening. Today in the morning (on activation), the module appeared correctly with the configured destination (I have changed my config, see below). But since then, there seem to be no more updates. Right now (at 11:20 am), the destination is shown with "13 minutes - 6:17". I also see no more calls in the API Dashboard.

Changed config:
{ module: 'MMM-MyCommute', position: 'top_right', config: { apiKey: 'apikey', origin: 'origin', pollFrequency: 15 * 60 * 1000, startTime: '05:30', endTime: '17:00', maxCalendarEvents: 3, destinations: [ { destination: 'dest1', label: 'label1', mode: 'driving', hideDays: [0,2,4,5,6] }, { destination: 'dest 2', label: 'label2', mode: 'driving', hideDays: [0,1,2,3,4,6] } ] } },

Dashboard:
grafik

Yep, just restarted: Now polls only a single time after restart of MM. (Automatic crontab reboot at 6 am, so 2x2 polls in the morning)

Thanks for testing.

I've included another, minor change, in the branch. That should fix it for you, hopefully.

git checkout issue17
git pull
git log -1 # should show commit ca137b371a20187a754a9c4777d93b8976dd6e6f

Looks better now. I have hit my self-set limit (I am out of free API calls and don't want a huge bill), which was set very, very restrictive. After raising it, it now seems to work as intended. Only thing: Arrival times only update on refresh.
So, lets say

1st API call 6 pm, 15 min driving time, arrival: 6.15 pm
At 6.09pm: Arrival still 6.15
2nd API call 6.10 pm, stil 15 min driving time, arrival: 6.25 pm

Maybe you could calculate arrival time from current time?

Hmm 🤔 that's an interesting suggestion...
I'm creating a new issue to sketch some new functionality there.

Maybe you could have a look and tell me (there) what you think.

Final feedback:

I think the current update can be merged to master.

Last 4 days; I think you can see where the fix was made:
grafik

Last 24 hours:

grafik

Thanks!

Hi, I wonder if this fix has already been pushed to the master commit?

Works fine, btw!

Yes, it's merged to master:
https://github.com/qistoph/MMM-MyCommute/branches

Forgot to mention it here and close the issue.