mercedes

package module
v0.0.0-...-6f9a740 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2020 License: MIT Imports: 6 Imported by: 0

README

Go SDK for Mercedes-Benz Connected Vehicle API

Overview

The Mercedes-Benz Connected Vehicle API is an experimental API for accessing connected vehicle data and for prototyping connected vehicle services. It provides extensive information about the vehicle itself (vehicle information, tire pressure, door status, location & heading, odometer, fuel level, as well as the state of battery charge for electric vehicles), while also providing limited actuation controls (door lock / unlock).

Installation

If not using Go modules, the SDK can be installed the same way as for other Go projects:

$ go get github.com/adaptant-labs/mercedes-connectedvehicle-go

Getting Started

1. Initiate a new client connection with your API key

// Initiate a new client connection. Set 'false' for tryout, 'true' for production API.
client := mercedes.NewClient(<API Key>, false)

2. Obtain a list of vehicles

vehicles, err := client.GetVehicles(context.TODO())

3. Choose a vehicle to perform operations on

vehicle := client.NewVehicle(vehicles[0].Id)

4. Carry out vehicle-specific operations

// Vehicle APIs
detail, err := vehicle.GetVehicleDetail(context.TODO())
tires, err := vehicle.GetTirePressure(context.TODO())
err := vehicle.LockDoors(context.TODO())
err := vehicle.UnockDoors(context.TODO())
doors, err := vehicle.GetDoorStatus(context.TODO())
location, err := vehicle.GetLocation(context.TODO())
distance, err := vehicle.GetDistanceDriven(context.TODO())
level, err := vehicle.GetFuelLevel(context.TODO())
charge, err := vehicle.GetStateOfCharge(context.TODO())

Testing with the Mercedes-Benz Car Simulator

The SDK itself can be used together with the Mercedes-Benz Car Simulator, but must go through the appropriate Oauth2 authentication flows in order to become accessible from the Connected Vehicle API. Note that in this case, the client must be configured for using the production API, and initiate the connection with the exchanged access token. A simple example of this is included in the examples directory.

Features and bugs

Please file feature requests and bugs concerning the SDK itself in the issue tracker. Note that as this is a third-party SDK and we have no direct affiliation with Mercedes-Benz, we are unable to handle feature requests for the REST API itself.

License

mercedes-connectedvehicle-go is released under the terms of the MIT license, the full version of which can be found in the LICENSE file included in the distribution.

Documentation

Index

Constants

View Source
const (
	Valid        RetrievalStatus = "VALID"
	Initialized                  = "INITIALIZED"
	Invalid                      = "INVALID"
	NotSupported                 = "NOT_SUPPORTED"
)

Variables

View Source
var (
	DefaultScopes = []string{"mb:user:pool:reader", "mb:vehicle:status:general"}
	Endpoint      = oauth2.Endpoint{
		AuthURL:  "https://api.secure.mercedes-benz.com/oidc10/auth/oauth/v2/authorize",
		TokenURL: "https://api.secure.mercedes-benz.com/oidc10/auth/oauth/v2/token",
	}
)

Functions

This section is empty.

Types

type ConnectedVehicle

type ConnectedVehicle struct {
	VehicleID string
	// contains filtered or unexported fields
}

func (*ConnectedVehicle) GetDistanceDriven

func (v *ConnectedVehicle) GetDistanceDriven(ctx context.Context) (DistanceDrivenResponse, error)

func (*ConnectedVehicle) GetDoorStatus

func (v *ConnectedVehicle) GetDoorStatus(ctx context.Context) (Doors, error)

func (*ConnectedVehicle) GetFuelLevel

func (v *ConnectedVehicle) GetFuelLevel(ctx context.Context) (FuelLevelResponse, error)

func (*ConnectedVehicle) GetLocation

func (v *ConnectedVehicle) GetLocation(ctx context.Context) (Location, error)

func (*ConnectedVehicle) GetStateOfCharge

func (v *ConnectedVehicle) GetStateOfCharge(ctx context.Context) (StateOfChargeResponse, error)

func (*ConnectedVehicle) GetTirePressure

func (v *ConnectedVehicle) GetTirePressure(ctx context.Context) (Tires, error)

func (*ConnectedVehicle) GetVehicleDetail

func (v *ConnectedVehicle) GetVehicleDetail(ctx context.Context) (VehicleDetail, error)

func (*ConnectedVehicle) LockDoors

func (v *ConnectedVehicle) LockDoors(ctx context.Context) error

func (*ConnectedVehicle) UnlockDoors

func (v *ConnectedVehicle) UnlockDoors(ctx context.Context) error

type ConnectedVehicleClient

type ConnectedVehicleClient struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string, productionMode bool) *ConnectedVehicleClient

func (*ConnectedVehicleClient) GetVehicles

func (m *ConnectedVehicleClient) GetVehicles(ctx context.Context) ([]Vehicle, error)

func (*ConnectedVehicleClient) NewVehicle

func (m *ConnectedVehicleClient) NewVehicle(vehicleId string) *ConnectedVehicle

type DistanceDriven

type DistanceDriven struct {
	Unit            DistanceUnit    `json:"unit"`
	Value           int             `json:"value"`
	RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
	Timestamp       int64           `json:"timestamp"`
}

type DistanceDrivenResponse

type DistanceDrivenResponse struct {
	Odometer           DistanceDriven `json:"odometer"`
	DistanceSinceReset DistanceDriven `json:"distancesincereset"`
	DistanceSinceStart DistanceDriven `json:"distancesincestart"`
}

type DistanceUnit

type DistanceUnit string
const (
	Kilometers DistanceUnit = "KILOMETERS"
)

func (*DistanceUnit) UnmarshalJSON

func (du *DistanceUnit) UnmarshalJSON(b []byte) error

type DoorLockChangeRequestBody

type DoorLockChangeRequestBody struct {
	Command DoorLockCommand `json:"command"`
}

type DoorLockCommand

type DoorLockCommand string
const (
	Lock   DoorLockCommand = "LOCK"
	Unlock                 = "UNLOCK"
)

func (*DoorLockCommand) UnmarshalJSON

func (dl *DoorLockCommand) UnmarshalJSON(b []byte) error

type DoorLockState

type DoorLockState string
const (
	Locked   DoorLockState = "LOCKED"
	Unlocked               = "UNLOCKED"
)

func (*DoorLockState) UnmarshalJSON

func (ds *DoorLockState) UnmarshalJSON(b []byte) error

type DoorLockStatus

type DoorLockStatus struct {
	Value           DoorLockState   `json:"value"`
	RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
	Timestamp       int64           `json:"timestamp"`
}

type DoorOpenStatus

type DoorOpenStatus struct {
	Value           DoorState       `json:"value"`
	RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
	Timestamp       int64           `json:"timestamp"`
}

type DoorState

type DoorState string
const (
	Open   DoorState = "OPEN"
	Closed           = "CLOSED"
)

func (*DoorState) UnmarshalJSON

func (ds *DoorState) UnmarshalJSON(b []byte) error

type Doors

type Doors struct {
	DoorStatusFrontLeft      DoorOpenStatus `json:"doorstatusfrontleft"`
	DoorStatusFrontRight     DoorOpenStatus `json:"doorstatusfrontright"`
	DoorStatusRearLeft       DoorOpenStatus `json:"doorstatusrearleft"`
	DoorStatusRearRight      DoorOpenStatus `json:"doorstatusrearright"`
	DoorLockStatusFrontLeft  DoorLockStatus `json:"doorlockstatusfrontleft"`
	DoorLockStatusFrontRight DoorLockStatus `json:"doorlockstatusfrontright"`
	DoorLockStatusRearLeft   DoorLockStatus `json:"doorlockstatusrearleft"`
	DoorLockStatusRearRight  DoorLockStatus `json:"doorlockstatusrearright"`
	DoorLockStatusDeckLid    DoorLockStatus `json:"doorlockstatusdecklid"`
	DoorLockStatusGas        DoorLockStatus `json:"doorlockstatusgas"`
	DoorLockStatusVehicle    DoorLockStatus `json:"doorlockstatusvehicle"`
}

type FuelLevel

type FuelLevel struct {
	Unit            PercentUnit     `json:"unit"`
	Value           int             `json:"value"`
	RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
	Timestamp       int64           `json:"timestamp"`
}

type FuelLevelResponse

type FuelLevelResponse struct {
	FuelLevelPercent FuelLevel `json:"fuellevelpercent"`
}

type Location

type Location struct {
	Latitude  LocationCoordinate `json:"latitude"`
	Longitude LocationCoordinate `json:"longitude"`
	Heading   LocationCoordinate `json:"heading"`
}

type LocationCoordinate

type LocationCoordinate struct {
	Value           float64         `json:"value"`
	RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
	Timestamp       int64           `json:"timestamp"`
}

type PercentUnit

type PercentUnit string
const (
	Percent PercentUnit = "PERCENT"
)

func (*PercentUnit) UnmarshalJSON

func (pu *PercentUnit) UnmarshalJSON(b []byte) error

type PressureUnit

type PressureUnit string
const (
	KiloPascal PressureUnit = "KILOPASCAL"
)

func (*PressureUnit) UnmarshalJSON

func (pu *PressureUnit) UnmarshalJSON(b []byte) error

type RetrievalStatus

type RetrievalStatus string

func (*RetrievalStatus) UnmarshalJSON

func (rs *RetrievalStatus) UnmarshalJSON(b []byte) error

type StateOfCharge

type StateOfCharge struct {
	Unit            PercentUnit     `json:"unit"`
	Value           int             `json:"value"`
	RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
	Timestamp       int64           `json:"timestamp"`
}

type StateOfChargeResponse

type StateOfChargeResponse struct {
	StateOfCharge StateOfCharge `json:"stateofcharge"`
}

type TirePressureStatus

type TirePressureStatus struct {
	Unit            PressureUnit    `json:"unit"`
	Value           float64         `json:"value"`
	RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
	Timestamp       int64           `json:"timestamp"`
}

type Tires

type Tires struct {
	TirePressureFrontLeft  TirePressureStatus `json:"tirepressurefrontleft"`
	TirePressureFrontRight TirePressureStatus `json:"tirepressurefrontright"`
	TirePressureRearLeft   TirePressureStatus `json:"tirepressurerearleft"`
	TirePressureRearRight  TirePressureStatus `json:"tirepressurerearright"`
}

type Vehicle

type Vehicle struct {
	Id           string `json:"id"`
	LicensePlate string `json:"licenseplate"`
	VIN          string `json:"finorvin"`
}

type VehicleDetail

type VehicleDetail struct {
	Id               string `json:"id"`
	LicensePlate     string `json:"licenseplate"`
	SalesDesignation string `json:"salesdesignation"`
	VIN              string `json:"finorvin"`
	ModelYear        string `json:"modelyear"`
	ColorName        string `json:"colorname"`
	FuelType         string `json:"fueltype"`
	PowerHP          string `json:"powerhp"`
	PowerKW          string `json:"powerkw"`
	NumberOfDoors    string `json:"numberofdoors"`
	NumberOfSeats    string `json:"numberofseats"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL