Minimal BLE adapter interface and implementations, based on vehicle-command#400 (unmerged), for easy integration and runtime selection.
This package lets you use either go-ble or tinygo BLE implementations via a common interface, as proposed in the MR above, before the PR is merged upstream.
The vehicle-command repository currently does not allow runtime selection between BLE implementations. This repo extracts the interface and adapters from the MR #400, so you can:
- Choose and switch between TinyGo and go-ble BLE backends at runtime
- Integrate with your vehicle-command based code now, before upstream merge
- Help develop and test the adapter interface cross-platform
- Unified BLE Adapter Interface
- Plug-and-play implementations using go-ble and tinygo
- Trivial runtime backend selection
- Will track and adapt to any upstream changes in MR #400
go get github.com/zlymeda/tzla-blepackage main
import (
"context"
"time"
"github.com/teslamotors/vehicle-command/pkg/cache"
"github.com/teslamotors/vehicle-command/pkg/vehicle"
"github.com/zlymeda/tzla-ble"
"github.com/zlymeda/tzla-ble/goble"
)
// ignoring error handling for brevity
func main() {
var adapter ble.Adapter
// Example: select go-ble implementation
adapter, _ = goble.NewAdapter("")
// Or: use tinygo implementation
// adapter = tinygo.NewAdapter("")
// Use adapter as needed...
requestCtx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
vin := "your_vehicle_vin_here"
adv, _ := ble.ScanVehicleBeacon(requestCtx, vin, adapter)
conn, _ := ble.NewConnectionFromBeacon(requestCtx, vin, adv, adapter)
car, _ := vehicle.NewVehicle(conn, loadPrivateKey(), cache.New(0))
// now you can use car as needed
}package main
import (
"github.com/zlymeda/tzla-ble"
"github.com/zlymeda/tzla-ble/goble"
"github.com/zlymeda/tzla-ble/tinygo"
)
func PickAdapter(name string) (ble.Adapter, error) {
switch name {
case "tinygo":
return tinygo.NewAdapter("")
default:
return goble.NewAdapter("")
}
}The upstream repo does not yet support runtime BLE adapter selection (as of this writing). This standalone repo enables experimentation and integration until MR #400 is merged.
Feedback and PRs are welcome—especially for additional BLE implementations, documentation, or compatibility testing.
Apache 2.0, same as vehicle-command.
Attribution:
Based on the work in vehicle-command#400 and the original Tesla Motors project.
Links:
This repository is not affiliated with Tesla or the original vehicle-command developers.