Update README.md

This commit is contained in:
xfarrow 2023-09-17 22:56:30 +02:00 committed by GitHub
parent 2fa32b088c
commit 234efa6e79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 69 deletions

View File

@ -1,26 +1,14 @@
# Secret APIs # Secret APIs
Tapo cameras provide undocumented APIs we can use to control the camera (like using its official app). I did not do anything, Tapo cameras provide undocumented APIs we can use to control the camera (like using its official app).
I am writing this document while looking at the code of the awesome project [pytapo](https://github.com/JurajNyiri/pytapo), which seems it does not have a documentation on You can download my [Insomnia](https://github.com/Kong/insomnia) API suite [at this link](https://github.com/xfarrow/tapo-camera/blob/main/secret-apis/TapoCameraAPIs.yaml). The suite is not complete yet.
the usage of the APIs yet.
## Preface I am writing this suite also by giving a look at the code of the awesome project [pytapo](https://github.com/JurajNyiri/pytapo).
The APIs are accessed via `HTTP` requests.
## Headers ## Getting a Stok
There are the headers `pytapo` uses, probably not all of them are necessary: Each API call is in the form `https://{cameraa_ip}/stok={stok}/ds`, hence you need your camera's IP and a token, called stok. You can obtain the stok by calling the `GetStok` request. Keep in mind that this token expires every `x` minutes (did not test the actual expiration time).
```
> Host: [camera ip]
> Content-Type: application/json; charset=UTF-8
> User-Agent: Tapo CameraClient Android
> Accept: application/json
> Accept-Encoding: gzip, deflate
> Connection: close
> requestByApp: true
```
You must use these headers for each call.
## Error codes ## Error codes
```
"-40401": "Invalid stok value", "-40401": "Invalid stok value",
"-40210": "Function not supported", "-40210": "Function not supported",
"-64303": "Action cannot be done while camera is in patrol mode.", "-64303": "Action cannot be done while camera is in patrol mode.",
@ -33,55 +21,4 @@ You must use these headers for each call.
"-40209": "Invalid login credentials", "-40209": "Invalid login credentials",
"-64304": "Maximum Pan/Tilt range reached", "-64304": "Maximum Pan/Tilt range reached",
"-71103": "User ID is not authorized", "-71103": "User ID is not authorized",
## Get token
To use the camera's functionalities, we need to get a token first (also called stok).
Create a `POST` request to `https://ip_of_your_camera`
with this `JSON` body
``` ```
{
"method": "login",
"params" : {
"hashed" : true,
"password" : "MD5_UPPERCASE_HASH_OF_YOUR_TPLINK_ACCOUNT",
"username" : "admin"
}
}
```
You must provide the value `admin` for `username`, and the MD5 hash of your Tp-Link account's password as the value of `password`. You will get a token named `stok`.
You'll receive something like
```
{
"error_code": 0,
"result": {
"stok": "*****",
"user_group": "root"
}
}
```
## Move the camera's motors
Create a `POST` request to `https://ip_of_your_camera/stok={your_stok}/ds`
with this `JSON` body
```
{
"method": "do",
"motor": {
"movestep": {
"direction": "direction_value"
}
}
}
```
`direction_value` can be one of these values
direction | description
----|-----------
0 | It will move horizontally to the position 0°
90 | It will move vertically to the uppermost point
180 | It will move horizontally to the position 360°
270 | Il will move vertically to the bottommost point