Skip to content

nekman/node-vw-carnet-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-vw-carnet-lambda

A Node.js AWS Lambda with a API Gateway REST API. Uses Lambda API as application framework.

node-vw-carnet with chrome-aws-lambda is used to login on Volkswagen We Connect and store a token in memory that can be used to do operations on the car.

Running

To run locally:

# start at localhost:3000 (see local-server.js)
npm start

Developing

# install
npm i

# lint
npm run eslint

# test
npm test

# install & lint & test
npm run build-all

API

Available routes:

╔══════════╤══════════════════════════╗
║  METHOD  │  ROUTE                   ║
╟──────────┼──────────────────────────╢
║  GET     │  /                       ║
╟──────────┼──────────────────────────╢
║  POST    │  /login                  ║
╟──────────┼──────────────────────────╢
║  GET     │  /vehicle/emanager       ║
╟──────────┼──────────────────────────╢
║  GET     │  /vehicle/details        ║
╟──────────┼──────────────────────────╢
║  GET     │  /vehicle/info           ║
╟──────────┼──────────────────────────╢
║  POST    │  /climate/:state         ║
╟──────────┼──────────────────────────╢
║  POST    │  /window-heating/:state  ║
╟──────────┼──────────────────────────╢
║  POST    │  /action                 ║
╚══════════╧══════════════════════════╝

Login

POST /login
{
  "email": "<your-carnet-email>",
  "password": "<your-carnet-password>"
}

If email and password is used, node-wv-carnet is using puppeteer to login to the We-Connect portal. This can take long time (the request can timeout) etc. Try again if this happens.

Response

HTTP 201

{
    "token": "5ff11bfc-ea8f-4c2d-8307-fb1e6f78ac49",
    "options": {
        "carId": "WVWXYZ00000000000",
        "csrfToken": "abc00000",
        "cookies": [
            {
                "name": "sc_prevpage",
                "value": "Car-Net%20%3A%20Dashboard%20%3A%20General"
            }

        // ...
       ]
    }
}

The response contains one token and one options object. The token is be used to access the other methods in the API.

The options object contains the "session" that is used to communicate with the Volkswagen CarNet (think it's valid for ~10 minutes).

You can also "login" with a saved options object by posting it to the /login endpoint instead of username/password.

Login with options

POST /login
{
    "options": {
      "carId": "WVWXYZ00000000000",
      "csrfToken": "abc00000",
      "cookies": [
          {
              "name": "sc_prevpage",
              "value": "Car-Net%20%3A%20Dashboard%20%3A%20General"
          }

      // ...
      ]
  }
}

If the options object is valid (known by Volkswagen CarNet), a new token is returned.

Start the climate heater

The token can be used to call methods on the API.

POST /climate/on

headers: {
  token: 'token',
  x-api-key: 'api-key'
}

Run any node-vw-carnet client operation

POST /action?method=<node-vw-carnet-client-method>

Example: getLocation

POST /action?method=getLocation

headers: {
  token: 'token',
  x-api-key: 'api-key'
}

HTTP 200

{
    "errorCode": "0",
    "position": {
        "lat": 57.000000,
        "lng": 14.000000
    }
}

Deploying

Install on AWS using Cloudformation template

This will create a API Gateway REST API protected with an API key. (You need to manually connect the key to a usage plan in the AWS console).

Clean

# remove node_modules/ and install with npm i --production
npm run clean

Create AWS Resources

# package
npm run cf:package <aws-profile>

# deploy
npm run cf:deploy <aws-profile>

About

Run node-vw-carnet on AWS Lambda via API Gateway

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published