Giter Site home page Giter Site logo

nikola's Introduction

Nikola · Maintainability Test Coverage Build Status

AWS Lambda that handles click events from Amazon's AWS IoT Button, a customizable version of their dash button, to send commands to a Tesla vehicle. Watch a demo of the charging port and trunk being opened from a single click on my Instagram or YouTube.

Prerequisites

Set up the button

  1. Set up your IoT Button.
  2. Clone or download repo.
  3. Copy env.yml.template to env.yml
  4. Replace YOUR_DSN_HERE value with your IoT Button DSN.
  5. Provide USERNAME, PASSWORD, and VEHICLE_ID (the id or id_s value from vehicles endpoint reponse) values.
  6. Configure the click commands as you see fit.
  7. Install Node
  8. Install Serverless Framework, npm i -g serverless
  9. Deploy Lambda, sls deploy -r aws-region-code
  10. Go to IoT Button app and change to Lambda.
  11. Click button and show off to friends.

Finding Your Vehicle ID

Get an access token by making a request to the token endpoint. Copy and paste the command below and replace YOUR_TESLA_LOGIN_EMAIL and YOUR_TESLA_LOGIN_PASSWORD with your values before running the command.

curl -X POST \
  https://owner-api.teslamotors.com/oauth/token \
    -d 'grant_type=password' \
    -d 'client_id=81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384' \
    -d 'client_secret=c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3' \
    -d 'email=YOUR_TESLA_LOGIN_EMAIL&password=YOUR_TESLA_LOGIN_PASSWORD'

A successful response looks something like this.

{
  "access_token":"8unc4ofnumb3r5a17dl3tt3r5ih0p3urn0tr36d1ngth15b1337w00tth33nd",
  "token_type":"bearer",
  "expires_in":3888000,
  "refresh_token":"8jdf9j3hd82kd02o5djs92dq8id03odkw2kdk034odkwf23ekri0356ks24tk",
  "created_at":1535859787
}

Use the value of the access_token key to make a request for all vehicles in your account. Copy and paste the command below and replace with your access token. I've used the access token from the example response above so you can see what it should look like below.

curl -X GET \
  https://owner-api.teslamotors.com/api/1/vehicles \
  -H 'Authorization: Bearer 8unc4ofnumb3r5a17dl3tt3r5ih0p3urn0tr36d1ngth15b1337w00tth33nd'

The response will have a key called response whose value is an array of vehicles.

{
  "response": [
    {
      "id": 70987654321234567,
      "vehicle_id": 1430999717,
      "vin": "5YJ3E1A2B3C4D5E6F",
      "display_name": "null",
      "option_codes": "AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,MI00,CDM0",
      "color": null,
      "tokens": [
        "5282a1b2c3d45e6f",
        "7f09a1b2c3d45e6f"
      ],
      "state": "online",
      "in_service": false,
      "id_s": "70987654321234567",
      "calendar_enabled": true,
      "backseat_token": null,
      "backseat_token_updated_at": null
    }
  ],
  "count": 1
}

You will need the value from the id or id_s field to set the VEHICLE_ID in the env.yml configuration file. Hint: To tell which vehicle is which, look at the option_codes and look for MDL3, MDLS, or MDLX for the Model 3, Model S, and Model X, respectively.

Design Philosophy (or lack thereof)

I took the approach of less is more:

  • Single Source File
    • editable directly in AWS console.
  • No Dependencies
    • secure by nature of smaller attack surface area.
    • faster deployment and runtime execution.
  • Vehicle ID Required
    • saves the hassle of having to fetch it at runtime.

nikola's People

Contributors

josephyi avatar dependabot[bot] avatar tsturtz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.