Skip to content

Commit

Permalink
Fix Kasa KC200 cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed May 10, 2024
1 parent ee387b7 commit f7b9804
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,16 @@ echo -n "cloud password" | shasum -a 256 | awk '{print toupper($0)}'

[TP-Link Kasa](https://www.kasasmart.com/) non-standard protocol [more info](https://medium.com/@hu3vjeen/reverse-engineering-tp-link-kc100-bac4641bf1cd).

- `username` - urlsafe email, `alex@gmail.com` -> `alex%40gmail.com`
- `password` - base64password, `secret1` -> `c2VjcmV0MQ==`

```yaml
streams:
kasa: kasa://user:pass@192.168.1.123:19443/https/stream/mixed
kc401: kasa://username:password@192.168.1.123:19443/https/stream/mixed
```

Tested: KD110, KC200, KC401, KC420WS, EC71.

#### Source: GoPro

*[New in v1.8.3](https://github.com/AlexxIT/go2rtc/releases/tag/v1.8.3)*
Expand Down
22 changes: 21 additions & 1 deletion pkg/kasa/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,34 @@ func Dial(url string) (*Producer, error) {
return nil, err
}

// KC200
// HTTP/1.0 200 OK
// Content-Type: multipart/x-mixed-replace;boundary=data-boundary--
// KD110, KC401, KC420WS:
// HTTP/1.0 200 OK
// Content-Type: multipart/x-mixed-replace;boundary=data-boundary--
// Transfer-Encoding: chunked
// HTTP/1.0 + chunked = out of standard, so golang remove this header
// and we need to check first two bytes
buf := bufio.NewReader(res.Body)

b, err := buf.Peek(2)
if err != nil {
return nil, err
}

rd := struct {
io.Reader
io.Closer
}{
httputil.NewChunkedReader(res.Body),
buf,
res.Body,
}

if string(b) != "--" {
rd.Reader = httputil.NewChunkedReader(buf)
}

prod := &Producer{rd: core.NewReadBuffer(rd)}
if err = prod.probe(); err != nil {
return nil, err
Expand Down

0 comments on commit f7b9804

Please sign in to comment.