doc:appunti:hardware:sjcam-8pro-api
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| doc:appunti:hardware:sjcam-8pro-api [2022/04/29 17:45] – [Ambarella msg_id Codes] niccolo | doc:appunti:hardware:sjcam-8pro-api [2022/05/02 11:22] (current) – removed niccolo | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== SJCAM SJ8 Pro WiFi API ====== | ||
| - | |||
| - | The camera offers an **API** over the **TCP protocol** on port **7878**. When the WiFi is on, you can open a open connection with it and exchange JSON messages to control the camera. This is the interface used by the official app. | ||
| - | |||
| - | The protocol was at least partially **reversed engineered** (see the [[# | ||
| - | |||
| - | ===== JSON Messages ===== | ||
| - | |||
| - | This is what a **JSON message** sent from the host (e.g. the Android smartphone) to the SJ8 Pro looks like: | ||
| - | |||
| - | < | ||
| - | {" | ||
| - | </ | ||
| - | |||
| - | The most important item of the message is the **msg_id**, for each code there may be other parameters that must be instantiated, | ||
| - | |||
| - | The first message sent from the host is the **AMBA_START_SESSION** (msg_id 0 257): | ||
| - | |||
| - | < | ||
| - | {" | ||
| - | </ | ||
| - | |||
| - | the answer from the SJCAM is something like this: | ||
| - | |||
| - | < | ||
| - | {" | ||
| - | </ | ||
| - | |||
| - | The returned value **rval** should be **zero**, generally a negative number means some error occurred. The token is received into the **param** item, generally is an integer increasing by one on every new connection. | ||
| - | |||
| - | ==== Ambarella msg_id Codes ==== | ||
| - | |||
| - | The names of the Ambarella codes (the first column in the following table) were taken from various sources on the net (see [[# | ||
| - | |||
| - | ^ Ambarella Name ^ Value ^ Use ^ | ||
| - | | AMBA_START_SESSION | ||
| - | | AMBA_STOP_SESSION | ||
| - | | AMBA_GET_SETTING | ||
| - | | AMBA_SET_SETTING | ||
| - | | AMBA_GET_ALL_CURRENT_SETTINGS | ||
| - | | AMBA_GET_SPACE | ||
| - | | AMBA_NOTIFICATION | ||
| - | | AMBA_GET_SINGLE_SETTING_OPTIONS | ||
| - | | AMBA_GET_DEVICEINFO | ||
| - | | ??? | ||
| - | | AMBA_GET_BATTERY_LEVEL | ||
| - | | AMBA_BOSS_RESETVF | ||
| - | | AMBA_STOP_VF | ||
| - | | AMBA_RECORD_START | ||
| - | | AMBA_RECORD_STOP | ||
| - | | AMBA_GET_RECORD_TIME | ||
| - | | AMBA_TAKE_PHOTO | ||
| - | | ??? | ||
| - | | ??? | ||
| - | |||
| - | |||
| - | ^ AMBA_GET_RECORD_TIME ^^^ | ||
| - | | Returned message ||| | ||
| - | | msg_id | ||
| - | | rval | -14 | Camera is not recording | ||
| - | | | ||
| - | | param | ||
| - | |||
| - | |||
| - | ===== Executing API commands at bootstrap ===== | ||
| - | |||
| - | It is possible to automatically execute some API calls at camera bootstrap, without connecting any WiFi device to the camera itself. | ||
| - | |||
| - | In this scenario the **RTOS** operating system on the camera uses the **telnet** command to talk to the **GNU/ | ||
| - | |||
| - | I was able to **create a script** to select the Color Profile automatically at boot. Remember that, due a firmware bug, the color profile choiche is not preserved across reboots, and you have to disable the Gyro Stabilizer before selecting the Color Profile. | ||
| - | |||
| - | Executing that script at camera startup is a rather convoluted process: | ||
| - | |||
| - | * At bootstrap, the RTOS executes the **autoexec.ash** Ambarella Script. | ||
| - | * Using the command **t ipc rpc clnt exec2** it is possible to execute a script into the **GNU/ | ||
| - | * The GNU/Linux environment has the **busybox** software, so it is possible to use the **telnet** command to establish a TCP connection with the API server at **localhost: | ||
| - | * The required **JSON commands** are sent to the API server to disable Gyro Stabilizer, select the Color Profile and then re enable Gyro Stabilizer. | ||
| - | |||
| - | **WARNING**: | ||
| - | |||
| - | Here there are the three files that must be created on the root directory of the SD card: | ||
| - | |||
| - | **autoexec.ash** | ||
| - | |||
| - | < | ||
| - | sleep 5000 | ||
| - | t ipc rpc clnt exec2 '/ | ||
| - | </ | ||
| - | |||
| - | **autoexec.rc** | ||
| - | |||
| - | < | ||
| - | #!/bin/sh | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | **api-set-options** | ||
| - | |||
| - | < | ||
| - | #!/bin/sh | ||
| - | # | ||
| - | # Send some commands to the TCP:7878 API. | ||
| - | # Set the color profile to "SJCAM - Vivid" and enable Gyro Stabilizer. | ||
| - | |||
| - | # We should get the token number from msg_id 257, but this script | ||
| - | # is executed at boot, so the token should be always " | ||
| - | T=1 | ||
| - | |||
| - | # A pause of 0.5 is required for each command to be completed. | ||
| - | # By trial we discovered that a pause of 0.4 is not sufficient. | ||
| - | S=0.52 | ||
| - | |||
| - | { | ||
| - | echo ' | ||
| - | echo ' | ||
| - | echo ' | ||
| - | echo ' | ||
| - | echo ' | ||
| - | sleep 1.0; | ||
| - | } | telnet localhost 7878 | ||
| - | echo | ||
| - | </ | ||
| - | |||
| - | ===== Web References ===== | ||
| - | |||
| - | * **HTTP API** | ||
| - | * **[[https:// | ||
| - | * **{{.: | ||
| - | * **{{.: | ||
| - | * **[[https:// | ||
doc/appunti/hardware/sjcam-8pro-api.1651247108.txt.gz · Last modified: by niccolo
