Okay, I'm guessing my car was doing something earlier tonight that was keeping it online while I was polling - for all I know there might be an update there... It looks like it goes to sleep somewhere around 10-15 minutes:
Fri Aug 30 00:06:11 CDT 2013
"state": "online",
Fri Aug 30 00:11:12 CDT 2013
"state": "online",
Fri Aug 30 00:16:13 CDT 2013
"state": "asleep",
...I woke it back up...
Fri Aug 30 00:21:14 CDT 2013
"state": "online",
Fri Aug 30 00:26:15 CDT 2013
"state": "online",
Fri Aug 30 00:31:15 CDT 2013
"state": "asleep",
So it looks like you
can call /vehicles and get the state without affecting it. Any command that involves a specific vehicle (e.g., vehicles/001/command/charge_state) appears to wake it up. This means the streaming code will likely have to change a bit:
Periodically call /vehicles:
* If car is asleep, leave it alone. (Don't wake up a sleeping baby!)
* If car is online, and our last poll was "asleep" or "waking", call charge_state to see if we're charging, set up streaming.
* If car is online, and our last poll was "online", and last charge_state poll showed we were charging, call charge_state again (also renews tokens)
* If car is online, and our last poll was "online", and last charge_state poll showed charge complete, don't call charge_state for at least <x> minutes (20? 30? ...basically, allow the car to fall sleep) -- this also provides backwards-compatibility with 4.5
* If car is online, and our tokens have expired, and we have registered a speed, or we registered a location change since our last renewal, renew tokens
* Otherwise, leave it alone.
This has a hole that I'm not sure how we can address... If the car came online (say, from an interior temp check on the app), then the tokens expired, and *then* you get in the car and leave before the app sleeps, the script will not have acquired tokens and won't get streaming data. We won't know, until charge_state is called and new tokens are acquired, that the car is moving, which could be upwards of 30 minutes or so.
Seem right?