Skip to content

Server to Simulator Client API

Glen Pike edited this page Feb 2, 2016 · 4 revisions

Introduction

The Simulator Client will provide an API for the server to push commands to. It will mirror the Vechicle Commands API provided for the Tesla.

Transport

Via Websockets - http://www.html5rocks.com/en/tutorials/websockets/basics/

Protocol

Communication will be done using JSON

##Initialisation

Connection will be initiated from the client to the server with the Simulator "logging in" to the server for each vehicle it is simulating.

The client will connect to the server using a normal AJAX request, sending an email address provided for simulation. This will match the email used in the "credentials to access the Tesla API. We can extend this to require a password should it be necessary.

The server will manage vehicle id's for sessions on the simulator.

This vehicle ID will be sent by the server in future commands, enabling the client to simulate multiple vehicles.

Request

{
    "command": "login",
    "params: {
        "email_address": "testing@test.com"
    }
}

Response (200 for okay)

{
   "vehicle_id": "abc1234"
}

In future the client should be able to display multiple vehicles. We would need a method of "unauthenticated" login to be able to get a list of vehicle id's for display, example shown below.

Request

{
    "command": "list_vehicle_ids"
}

Response (200 for okay)

{
   ["abc1234", "def5678", "ace1357", "bdf2468" ]
}

##Responding to Commands

Each command from Server to Client will be sent as a JSON object, containing the vehicle ID, the command name and any parameters encapsulated as a sub-object.

JSON object keys and the command value will be underscored to match those used in the REST API.

The protocol may be extended in the future to allow arrays of commands to be sent at once.

The client will not "reply" to the server for each command.

Examples

Honk the Horn

{
   "vehicle_id": "abc1234",
   "command": "honk_horn"
}

REST Reference

Set Temperature

{
    "vehicle_id": "abc1234",
    "command": "set_temps",
    "params": {
        "driver_temp": 23.7,
        "passenger_temp": 18.0
    }
}

REST Reference