-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autopark & Homelink returning a 400 Bad Request #14
Comments
I just gave it a try, indeed the Tesla API is now returning a 400 Bad Request whereas this worked before. I will have to track down what Tesla recently changed in their API, or if they are just intentionally disabling doing this now. |
Thanks for confirming, it was driving me nuts during the weekend to figure out what had happened! I see you have another ticket opened so probably we can close this one. |
Reopening as the other ticket is the fact that Homelink is also not working in addition to AutoPark. |
From @PolyPort here: https://teslamotorsclub.com/tmc/posts/1591755/
|
Here is the full API now over websockets for Autopark and Homelink: |
Ok, I have the basics working: package main
import (
"strconv"
"github.com/jsgoecke/tesla"
"encoding/base64"
"log"
"net/http"
"net/url"
"os"
"os/signal"
"time"
"github.com/gorilla/websocket"
)
var (
email = "valid_email"
server = "streaming.vn.teslamotors.com"
resource = "/connect/"
)
func main() {
token, vehicleID := getTesla()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
u := url.URL{Scheme: "wss", Host: server, Path: resource + vehicleID}
headers := setHeaders(token)
log.Printf("%s", u.String())
log.Println(headers)
c, _, err := websocket.DefaultDialer.Dial(u.String(), headers)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()
done := make(chan struct{})
go func() {
defer c.Close()
defer close(done)
log.Println("launching listener")
for {
_, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
log.Printf("recv: %s", message)
}
}()
log.Println("launching watcher")
for {
select {
case <-interrupt:
log.Println("interrupt")
select {
case <-done:
log.Println("done")
case <-time.After(1 * time.Second):
}
c.Close()
return
}
}
}
func setHeaders(token string) http.Header {
req, _ := http.NewRequest("GET", "http://localhost", nil)
data := []byte(email + ":" + token)
encodedToken := base64.StdEncoding.EncodeToString(data)
req.Header.Add("Authorization", "Basic "+encodedToken)
return req.Header
}
func getTesla() (string, string) {
client, err := tesla.NewClient(
&tesla.Auth{
ClientID: os.Getenv("TESLA_CLIENT_ID"),
ClientSecret: os.Getenv("TESLA_CLIENT_SECRET"),
Email: os.Getenv("TESLA_USERNAME"),
Password: os.Getenv("TESLA_PASSWORD"),
})
if err != nil {
panic(err)
}
vehicles, err := client.Vehicles()
if err != nil {
panic(err)
}
vehicle := vehicles[0]
return vehicle.Tokens[0], strconv.Itoa(vehicle.VehicleID)
} Results in: {"autopark":{"autopark_pause_timeout":2000,"autopark_stop_timeout":10000,"heartbeat_frequency":500},"connection_timeout":20000,"msg_type":"control:hello"} |
Some of the data output: 2016/06/22 10:41:02 recv: {"autopark":{"autopark_pause_timeout":2000,"autopark_stop_timeout":10000,"heartbeat_frequency":500},"connection_timeout":20000,"msg_type":"control:hello"}
2016/06/22 10:41:03 recv: {"autopark_state":"ready","msg_type":"autopark:status"}
2016/06/22 10:41:03 recv: {"homelink_nearby":true,"msg_type":"homelink:status"}
2016/06/22 10:41:05 recv: {"autopark_state":"preparing","msg_type":"autopark:status"}
2016/06/22 10:41:08 recv: {"autopark_state":"active_reverse","msg_type":"autopark:status"}
2016/06/22 10:41:13 recv: {"autopark_state":"preparing","msg_type":"autopark:status"}
2016/06/22 10:41:13 recv: {"autopark_state":"aborting","msg_type":"autopark:status"}
2016/06/22 10:41:13 recv: {"latitude":30,"longitude":-120,"msg_type":"vehicle_data:location"}
2016/06/22 10:41:13 recv: {"autopark_state":"ready","msg_type":"autopark:status"}
2016/06/22 10:41:15 recv: {"latitude":30,"longitude":-120,"msg_type":"vehicle_data:location"}
2016/06/22 10:41:17 recv: {"latitude":30,"longitude":-120,"msg_type":"vehicle_data:location"}
2016/06/22 10:41:18 recv: {"autopark_state":"preparing","msg_type":"autopark:status"}
2016/06/22 10:41:21 recv: {"autopark_state":"active_forward","msg_type":"autopark:status"}
2016/06/22 10:41:23 recv: {"msg_type":"control:goodbye","reason":"vehicle_disconnected"} |
AutoPark returns 400 bad_request
The text was updated successfully, but these errors were encountered: