TMC is an independent, primarily volunteer organization that relies on ad revenue to cover its operating costs. Please consider whitelisting TMC on your ad blocker or making a Paypal contribution here: paypal.me/SupportTMC

My Model S now tweets!

Discussion in 'Model S: User Interface' started by PureAmps, Feb 12, 2013.

  1. PureAmps

    PureAmps Model S P85 (#2817)

    Joined:
    Oct 22, 2012
    Messages:
    354
    Location:
    SF Bay Area
    #1 PureAmps, Feb 12, 2013
    Last edited: Feb 12, 2013
    Thanks to the Model S REST API and a little bit of Ruby, my Model S now tweets updates on its charging and driving status. You can follow @PureAmps on twitter if you are extremely bored. All posts to that account are automatically generated using data from the API.

    Now the first question you may ask is "why would I want my car to tweet"? The short answer is: "you wouldn't". :)

    The long answer is that I'm using this as an experiment to get useful data out of the vehicle including daily mileage and energy usage, that I will eventually use to put together some type of web app to track my vehicle's stats.
     
  2. dsm363

    dsm363 Roadster + Sig Model S

    Joined:
    May 17, 2009
    Messages:
    18,235
    Location:
    Las Vegas, NV
    That is crazy:smile: Nice work.

    Can you explain for non-programmers how this is all working? Thanks.
     
  3. pete8314

    pete8314 Vendor

    Joined:
    Jun 4, 2012
    Messages:
    1,947
    Location:
    DFW
    Will it follow me :)

    This is cool. Reminds me of the guy that set up his catflap to tweet each time Piddles came in or out. Useless, but strangely informative. I'd like to know how this can be deployed too, the Rest API thread might as well be written in Dutch for all the use it is to me :)
     
  4. PureAmps

    PureAmps Model S P85 (#2817)

    Joined:
    Oct 22, 2012
    Messages:
    354
    Location:
    SF Bay Area
    At a high level, I wrote a program that talks to the same Tesla servers that the mobile phone app uses to get information about the car. I then take that information and send an update to a twitter account I created for the car.

    The current version is pretty basic, it requests the car's "drive" and "charge" state every 5 minutes. The "drive" state indicates the car's position, speed, heading, and gear selection. Whenever the gear selection changes I tweet something relevant about its new state. For example, if it goes from Park to Drive, I will tweet the car's current speed. For charging, it looks for a state change to "Charging" or "Complete" and reports the current stats from the car. Twitter doesn't like duplicate status updates, so not all of the updates get posted if they happen to be identical to a previous update.

    I'm working on some improvements, which will hopefully include odometer readings. So I can tweet out the day's mileage or a even a trip mileage for each time the car transitions in/out of Park. After that, trying to figure out energy usage...
     
  5. FlasherZ

    FlasherZ Sig Model S + Sig Model X + Model 3 Resv

    Joined:
    Jun 21, 2012
    Messages:
    7,019
    I'm willing to bet the service center can fix the tweeting noise that your car makes.
     
  6. Bearman

    Bearman Member

    Joined:
    Nov 17, 2011
    Messages:
    363
    Location:
    Sweden
    Nice work PureAmps, and thanks for the explanation. :smile:
     
  7. dsm363

    dsm363 Roadster + Sig Model S

    Joined:
    May 17, 2009
    Messages:
    18,235
    Location:
    Las Vegas, NV
    Thanks for the explanation. Just don't make the Model S self-aware. We don't need an article about that online:smile:
     
  8. kendallpb

    kendallpb Model S: P 8061

    Joined:
    Oct 29, 2010
    Messages:
    1,185
    Location:
    MD, USA
    LOL! I like the "Look out, I'm backing up. Beep. Beep. Beep." one the best. ;-)

    Every 5 minutes (288/day) seems like a lot of tweets, and some of them seem oddly redundant, e.g., 3 in a row saying "Charging complete" but with different miles listed, all from 18 hours ago. I know this isn't the final thing you plan on...just thinking aloud, partially (me, I mean). Does this use up much? any noticeable? energy? Once they re-enable sleep mode, would this "wake" the car (I'm guessing yes)?

    Anyway, cool and mostly pretty amusing. I second the warning about self-aware cars (we don't want a "Christine" ;-) ).
     
  9. brianman

    brianman Burrito Founder

    Joined:
    Nov 10, 2011
    Messages:
    15,487
    @PureAmps - Did you put a governor on the speed reporting?

     
  10. PureAmps

    PureAmps Model S P85 (#2817)

    Joined:
    Oct 22, 2012
    Messages:
    354
    Location:
    SF Bay Area
    Thanks, glad you enjoyed. It shouldn't tweet every 5 minutes, as I only tweet on a state transition, let's say from Park to Drive. So it will only tweet within the first five minutes after you start driving, not every 5 minutes while you are driving. That would just be obnoxious. :) Some of the early "charing complete" tweets were just me playing around last night, switching between "max range" and "standard mode" while I tested the code (I just deleted a few of them).

    No idea on energy use yet, but I can't imagine it would use that much while driving as the 3G radio is already on for navigation, etc. While parked, it may contribute to "vampire" load, would have to experiment to see. When they turn sleep mode back on, I think one can detect if the car is sleeping via the API, and not wake it up.

    My hope is that while driving the additional power load is minimal, as my plan is to use the API to gather data on extended road trips. If measuring the car reduces range by 10% it would kind of defeat the purpose.

    - - - Updated - - -

    :) Not yet, but believe me the thought has crossed my mind....
     
  11. stevezzzz

    stevezzzz R;SigS;P85D;SigX

    Joined:
    Nov 13, 2009
    Messages:
    6,062
    Location:
    Colorado
    Didn't ol' Heisenberg have something to say on the subject? :wink::biggrin:
     
  12. kendallpb

    kendallpb Model S: P 8061

    Joined:
    Oct 29, 2010
    Messages:
    1,185
    Location:
    MD, USA
    Right, sorry, I said tweet--I meant checking--but also I misunderstood. Thanks. My reading comprehension sucks.

    I hope so (detecting if it's asleep, let it lie). And good point re. the 3G already on for other things--yeah, during those times...most of the time, I guess, until they enable sleep again!...that's gotta be no or next-to-no energy. I didn't think it through before posting.
     
  13. CapitalistOppressor

    CapitalistOppressor Active Member

    Joined:
    Jun 18, 2012
    Messages:
    1,621
    Did you connect over your home wifi and do packet sniffing to monitor the feed, or did you jail break your phone and install a monitoring app? :)

    Edit: Personally, I'd try packet sniffing, or set a PC as your router and just capture the data directly. But if you did it from an in phone app I totally want to know what you used, lol.. :)
     
  14. tdiggity

    tdiggity Member

    Joined:
    Oct 3, 2012
    Messages:
    721
    Location:
    Bay Area, CA
    You could blacklist hours that it is commonly parked so that you can avoid more vampire load.

    Or better yet, you could make the script txt/call/alarm you if it is moving in the middle of the night. I could imagine running a "I'm home" script that monitors this.

    Possibilities are endless. Cool stuff!
     
  15. PureAmps

    PureAmps Model S P85 (#2817)

    Joined:
    Oct 22, 2012
    Messages:
    354
    Location:
    SF Bay Area
    Initial credit should go to timdorr, who started the work on uncovering the Model S REST API. Of course, he had a head start because the android app was out ahead of the iphone app. :)

    I personally use mitmproxy, which requires me to install an SSL CA certificate on my iPhone and configure a proxy server. No jailbreaking required, just connect over my home wifi and proxy via my laptop. Traditional "packet sniffing" won't work as all traffic is encrypted with SSL, so you have to proxy the traffic to intercept it.

    However, for what I'm trying to do the REST API is useless, as it doesn't provide odometer readings. Luckily, Tesla provides a streaming API which does provide odometer data, just requires a little more effort to use....
     
  16. hans

    hans P631

    Joined:
    Sep 27, 2012
    Messages:
    1,123
    Location:
    Menlo Park
    "Open the pod bay doors, HAL"
     
  17. SuperCoug

    SuperCoug Model S Res #7734

    Joined:
    Mar 16, 2012
    Messages:
    225
    Location:
    Bothell, WA
    Your car's tweets are a Hell of a lot more interesting than anything Paris Hilton has ever posted! :biggrin:
     
  18. brianman

    brianman Burrito Founder

    Joined:
    Nov 10, 2011
    Messages:
    15,487
    Simplified it for you:
     
  19. PureAmps

    PureAmps Model S P85 (#2817)

    Joined:
    Oct 22, 2012
    Messages:
    354
    Location:
    SF Bay Area
    I updated my car's tweets to now include the miles driven for each "trip". Where a trip begins when the car is placed in drive and ends when it placed in park. Still working on calculating Wh/mile per trip, seems to be harder than I would have thought due to limited precision of the data, but I guess the API wasn't designed for my use case. :)

    It is interesting to watch, as I've never logged our driving habits to this level of detail. My wife had the car today and was running the kids around as well as some errands. It is kind of amazing how all of those short trips rack up the miles over the course of a day.
     
  20. brianman

    brianman Burrito Founder

    Joined:
    Nov 10, 2011
    Messages:
    15,487
    @PureAmps
    Now would be a great time to send a private mail to GeorgeB and/or Elon offering them a copy of your Twitter car feed. Would be very amusing had this been done to the NYT test drive vehicle.

     

Share This Page