User Tools

Site Tools


doc:appunti:hardware:sjcam-8pro-ambarella-wifi-api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:hardware:sjcam-8pro-ambarella-wifi-api [2022/05/07 08:39] – [Video streaming] niccolodoc:appunti:hardware:sjcam-8pro-ambarella-wifi-api [2023/06/16 10:18] (current) – [SJCAM SJ8 Pro WiFi Ambarella API] niccolo
Line 5: Line 5:
 The server on the camera accepts **only one client at a time**. When the camera is connected to a WiFi client on the controlling port 7878/TCP it will **ignore the Auto Power Off** setting and it remains active. The server on the camera accepts **only one client at a time**. When the camera is connected to a WiFi client on the controlling port 7878/TCP it will **ignore the Auto Power Off** setting and it remains active.
  
-The protocol was at least partially **reversed engineered**. To analyze the protocol I used **tcpdump**; having a rooted Android phone it is possibile to install the **[[https://termux.com/|Termux]]** app to have a command line terminal, install the **tcpdump** tool and, as root, sniff all the TCP traffic from the host smartphone and the SJCAM camera while using the SJCAM Zone app.+The protocol was at least partially **reversed engineered**. Having a rooted Android phoneit was possibile to run the **tcpdump** tool to analyze the TCP traffic (''tcpdump'' is installed from the command line of the **[[https://termux.com/|Termux]]** app). As root I started tcpdump to capture the traffic exchanged from the smartphone and the SJCAM camerawhile using the SJCAM Zone app.
  
-See my other page about the SJCAM SJ8 Pro action camera: **[[sjcam-8pro]]****[[sjcam-8pro-ambarella-firmware-modding]]** and **[[sjcam-8pro-custom-firmware]]**.+See my other page about the SJCAM SJ8 Pro action camera: 
 + 
 +  * **[[sjcam-8pro]]** 
 +  * **[[sjcam-8pro-ambarella-firmware-modding]]** 
 +  * **[[sjcam-8pro-custom-firmware]]**
  
 ===== JSON Messages ===== ===== JSON Messages =====
Line 32: Line 36:
  
 The returned value **rval** should be **zero**, generally a negative number means some error occurred. The token is received into the **param** item, it is an integer increasing by one on every new connection. The returned value **rval** should be **zero**, generally a negative number means some error occurred. The token is received into the **param** item, it is an integer increasing by one on every new connection.
 +
 +**NOTICE**: Response messages from the SJCAM **do not end with a new line** character.
  
 ==== Ambarella msg_id Codes ==== ==== Ambarella msg_id Codes ====
Line 41: Line 47:
 | AMBA_STOP_SESSION    |    258 | Terminate the session.  | | AMBA_STOP_SESSION    |    258 | Terminate the session.  |
 | AMBA_GET_SETTING          1 | Get the value of a a single camera setting.  | | AMBA_GET_SETTING          1 | Get the value of a a single camera setting.  |
-| AMBA_SET_SETTING          2 | Set the value of a camera setting. Settings are the ones returned by AMBA_GET_ALL_CURRENT_SETTINGS, plus some others, like camera_clock, camera_mode, save_low_resolution_clip, stream_out_type, ...  |+| AMBA_SET_SETTING          2 | Set the value of a camera setting. Settings are the ones returned by AMBA_GET_ALL_CURRENT_SETTINGS, plus some others, like ''camera_clock''''camera_mode''''save_low_resolution_clip''''stream_out_type'', ...  |
 | AMBA_GET_ALL_CURRENT_SETTINGS  |  3 | Get current camera settings. Notice: some settings appear more than once, but setting one will change all of them.  | | AMBA_GET_ALL_CURRENT_SETTINGS  |  3 | Get current camera settings. Notice: some settings appear more than once, but setting one will change all of them.  |
 | AMBA_GET_SPACE            5 | Get card space, total and free.  | | AMBA_GET_SPACE            5 | Get card space, total and free.  |
Line 74: Line 80:
  
 <code> <code>
-SEND: {"msg_id":258,"token":0}+SEND: {"msg_id":258,"token":2}
 RECV: {"rval":0,"msg_id":258} RECV: {"rval":0,"msg_id":258}
 </code> </code>
Line 126: Line 132:
 == AMBA_GET_SINGLE_SETTING_OPTIONS == == AMBA_GET_SINGLE_SETTING_OPTIONS ==
  
-Enumerate all the possible values for one setting:+Enumerate all the possible values for LCD Off Time setting:
  
 <code> <code>
Line 132: Line 138:
 RECV: {"rval":0,"msg_id":9,"permission":"settable","param":"LCD Off Time", RECV: {"rval":0,"msg_id":9,"permission":"settable","param":"LCD Off Time",
        "options":["Off","30 Seconds","1 Minute","3 Minutes","5 Minutes"]}        "options":["Off","30 Seconds","1 Minute","3 Minutes","5 Minutes"]}
 +</code>
 +
 +Enumerate all the possible values for Resolution setting:
 +
 +<code>
 +SEND: {"msg_id":9, "param": "Resolution", "token":1}
 +RECV: {"rval":0,"msg_id":9,"permission":"settable","param":"Resolution","options":[
 +       "4K (3840x2160) 24FPS","4K (3840x2160) 25FPS","4K (3840x2160) 30FPS",
 +       "4K (3840x2160) 50FPS","4K (3840x2160) 60FPS",
 +       "4K UItra (3840X21 60) 24FPS","4K UItra (3840X2160) 30FPS",
 +       "2.7K (2720x1520) 24FPS","2.7K (2720x1520) 25FPS","2.7K (2720x1520) 30FPS",
 +       "2.7K (2720x1520) 50FPS","2.7K (2720x1520) 60FPS",
 +       "1440 (2560x1440) 24FPS","1440 (2560x1440) 25FPS","1440 (2560x1440) 30FPS",
 +       "1440 (2560x1440) 50FPS","1440 (2560x1440) 60FPS",
 +       "1080(1920x1080) 24FPS","1080(1920x1080) 25FPS","1080(1920x1080) 30FPS",
 +       "1080(1920x1080) 50FPS","1080(1920x1080) 60FPS","1080(1920x1080) 120FPS",
 +       "1080 Ultra(1920X1080) 30FPS","1080 Ultra(1920X1080) 60FPS",
 +       "720(1280x720) 240FPS"]}
 </code> </code>
  
Line 148: Line 172:
 SEND: {"msg_id":2,"type":"camera_clock","param":"2022-05-06 17:02:43","token":2} SEND: {"msg_id":2,"type":"camera_clock","param":"2022-05-06 17:02:43","token":2}
 RECV: {"rval":0,"msg_id":2,"type":"camera_clock"} RECV: {"rval":0,"msg_id":2,"type":"camera_clock"}
 +</code>
 +
 +Set the video mode:
 +
 +<code>
 +SEND: {"msg_id": 2, "type": "Resolution", "param": "1080(1920x1080) 30FPS", "token":1}
 +RECV: {"rval":0,"msg_id":2,"type":"camera_mode"}
 +</code>
 +
 +Set the camera mode to normal record:
 +
 +<code>
 +SEND: {"msg_id": 2, "type": "camera_mode", "param": "normal_record", "token":1}
 +RECV: {"rval":0,"msg_id":2,"type":"camera_mode"}{"msg_id":7,"type":"normal_record"}
 </code> </code>
  
Line 193: Line 231:
 == AMBA_BOSS_RESETVF == == AMBA_BOSS_RESETVF ==
  
-Sending the following two messages will start the RTSP video streamin server on port 554/TCP:+Sending the following two messages will start the RTSP video streaming server on port 554/TCP:
  
 <code> <code>
Line 252: Line 290:
 ===== Using Python to call the API ===== ===== Using Python to call the API =====
  
 +{{.:sjcam:sjcam-termux-shortcuts.png?direct&200 |Termux Widgets to start SJCAM scripts}}
 {{ .:sjcam:sj8pro-wifi-api-python-termux.png?220|Termux screen on Android smartphone}} {{ .:sjcam:sj8pro-wifi-api-python-termux.png?220|Termux screen on Android smartphone}}
 I wrote same **Python scripts** to execute simple actions, like **start** and **stop recording**, turning off the **front LCD** and **LEDs**. Python is very flexible: I can run the same scripts from my **GNU/Linux** PC or from the **Android** smartphone (once I installed the **[[https://termux.com/|Termux]]** app). Here it is a screenshot of the script launched from an icon on my Android device: I wrote same **Python scripts** to execute simple actions, like **start** and **stop recording**, turning off the **front LCD** and **LEDs**. Python is very flexible: I can run the same scripts from my **GNU/Linux** PC or from the **Android** smartphone (once I installed the **[[https://termux.com/|Termux]]** app). Here it is a screenshot of the script launched from an icon on my Android device:
  
 +On Android I installed also the **Termux:Widget** app which allows to add shortcut icons over the desktop which will launch the scripts. I have scripts to start and stop recording, to change white balance, to turn ON and OFF the front display and to power OFF the camera. Each launcher was customized with its own **icon** (se the screenshot to the left). When a script is launched, the output is printed into the text console; to have a more visible feedback I used the **figlet** program to print large ASCII-art messages (se the screenshot to the right).
 +
 +In this **[[https://github.com/RigacciOrg/ambarella-api-pytools|GitHub repository]]** you can find a Python module which contains basic functions to send and receive the JSON messages, plus some handy scripts to do basic operations, like **REC Start**, **REC Stop**, set **White Balance**, etc.
  
  
Line 263: Line 305:
 In this scenario the **RTOS** operating system on the camera uses the **telnet** command to talk to the **GNU/Linux** operating system running on the same camera, which handles the API requests (the camera actually runs two operating system simultaneusly: RTOS and Linux). In this scenario the **RTOS** operating system on the camera uses the **telnet** command to talk to the **GNU/Linux** operating system running on the same camera, which handles the API requests (the camera actually runs two operating system simultaneusly: RTOS and Linux).
  
-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.+I was able to **create a script** to select the Color Profile automatically at boot. Remember that, due a firmware bug, the color profile choice is not preserved across reboots, and you have to disable the Gyro Stabilizer before selecting the Color Profile
 + 
 +**NOTICE**: I had written this script because I had customized the //SJCAM - Vivid// profile and I wanted to select it at bootstrap, while the camera starts with a default profile which at the time I did not know how to customize. Today BitrateEditor exposes also the default profile, so I can customize every profile and this script is now useless for me.
  
 Executing that script at camera startup is a rather convoluted process: Executing that script at camera startup is a rather convoluted process:
doc/appunti/hardware/sjcam-8pro-ambarella-wifi-api.1651912774.txt.gz · Last modified: 2022/05/07 08:39 by niccolo