jsgoecke/tesla

Support the streaming API

jsgoecke opened this issue · 1 comments

Currently this:

func (v Vehicle) RequestStream(c *Client) (*Vehicle, error) {
    url := StreamingURL + "/stream/" + strconv.FormatInt(v.ID, 10) + "?values=" + StreamParams
    req, _ := http.NewRequest("GET", url, nil)
    req.SetBasicAuth(os.Getenv("TESLA_USERNAME"), v.Tokens[0])

    fmt.Println("*****")
    fmt.Println("Username => " + os.Getenv("TESLA_USERNAME"))
    fmt.Println("Password/Token => " + v.Tokens[0])
    fmt.Println(req)
    fmt.Println("*****")

    resp, err := c.HTTP.Do(req)
    if err != nil {
        fmt.Println(err)
    }

    reader := bufio.NewReader(resp.Body)
    fmt.Println("Listening...")
    for {
        line, err := reader.ReadBytes('\n')
        if err != nil {
            if err != io.EOF {
                fmt.Println("Err => " + err.Error())
            }
        } else {
            fmt.Println("Line => " + string(line))
        }
    }
    return nil, nil
}

Results in:

*****
Username => foo
Password/Token => bar
&{GET https://streaming.vn.teslamotors.com/stream/1234?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading HTTP/1.1 1 1 map[Authorization:[Basic foobar]] <nil> 0 [] false streaming.vn.teslamotors.com map[] map[] <nil> map[]   <nil> <nil>}
*****
Listening...
Line => Can't validate password. 

That token as 'password' should work.