Skip to content

Instantly share code, notes, and snippets.

@pbaja
Last active February 23, 2023 12:35
Show Gist options
  • Save pbaja/f57e6cff7fa14601f6b256926aa33437 to your computer and use it in GitHub Desktop.
Save pbaja/f57e6cff7fa14601f6b256926aa33437 to your computer and use it in GitHub Desktop.
Xiaomi Yi JSON Protocol Reverse Enginnering

Xiaomi Yi JSON Protocol Reverse Engineering

First, connect to your camera via WiFi. Then you can send data to 192.168.42.1:7878

HELP IS APPRICIATED

Get token

Request:

{"msg_id":257,"token":0}

Response:

{ "msg_id": 7, "type": "vf_stop" }
{ "rval": 0, "msg_id": 257, "param": 1 }

"param" - Your token, you need to pass it in later requests.
Messages with id 7 are status updates:
"vf_stop" - ????

Take a photo

Request:

{"msg_id":769,"token":1}

Response:

{"rval":-27,"msg_id":769}

"rval" - When this equals -27, that means error occured (Probably sdcard is missing/busy)

{"rval":0,"msg_id":769}
{ "msg_id": 7, "type": "start_photo_capture" ,"param":"precise quality;off"}
{ "msg_id": 7, "type": "precise_capture_data_ready" }
{ "msg_id": 7, "type": "photo_taken" ,"param":"/tmp/fuse_d/DCIM/127MEDIA/YDXJ0373.jpg"}
{ "msg_id": 7, "type": "vf_start" }

"rval" - When this equals 0, that means everything is ok. Messages with id 7 are status updates:
"start_photo_capture" - Camera is taking photo
"precise_capture_data_ready" - Photo taken, camera is processing it.
"photo_taken" - Photo has been saved to sdcard, you have path to it in "param"
"vf_start" - ?????

Get battery status

Request:

{"msg_id":13,"token":1}

Response:

{"rval":0,"msg_id":13,"type":"adapter","param":"100"}

"param" - Battery level in percent
"type" - adapter or battery

Get all settings

Request:

{"msg_id":3,"token":1}

Response:

{ "rval": 0, "msg_id": 3, "param": [ { "camera_clock": "2015-04-07 02:32:29" }, { "video_standard": "NTSC" }, { "app_status": "idle" }, { "video_resolution": "1920x1080 60P 16:9" }, { "video_stamp": "off" }, { "video_quality": "S.Fine" }, { "timelapse_video": "off" }, { "capture_mode": "precise quality" }, { "photo_size": "16M (4608x3456 4:3)" }, { "photo_stamp": "off" }, { "photo_quality": "S.Fine" }, { "timelapse_photo": "60" }, { "preview_status": "on" }, { "buzzer_volume": "mute" }, { "buzzer_ring": "off" }, { "capture_default_mode": "precise quality" }, { "precise_cont_time": "60.0 sec" }, { "burst_capture_number": "7 p / s" }, { "restore_factory_settings": "on" }, { "led_mode": "all enable" }, { "dev_reboot": "on" }, { "meter_mode": "center" }, { "sd_card_status": "insert" }, { "video_output_dev_type": "tv" }, { "sw_version": "YDXJv22_1.0.7_build-20150330113749_b690_i446_s699" }, { "hw_version": "YDXJ_v22" }, { "dual_stream_status": "on" }, { "streaming_status": "off" }, { "precise_cont_capturing": "off" }, { "piv_enable": "off" }, { "auto_low_light": "on" }, { "loop_record": "off" }, { "warp_enable": "off" }, { "support_auto_low_light": "on" }, { "precise_selftime": "5s" }, { "precise_self_running": "off" }, { "auto_power_off": "5 minutes" }, { "serial_number": "xxxxx" }, { "system_mode": "capture" }, { "system_default_mode": "capture" }, { "start_wifi_while_booted": "off" }, { "quick_record_time": "0" }, { "precise_self_remain_time": "0" }, { "sdcard_need_format": "no-need" }, { "video_rotate": "off" } ] }

Get setting choices

Request:

{"msg_id":9,"param":"video_resolution","token":1}

"param" - The key you want choices for
Response:

{ "rval": 0, "msg_id": 9, "param": "video_resolution", "permission": "settable", "options": [ "1920x1080 60P 16:9", "1920x1080 30P 16:9", "1920x1080 48P 16:9", "1920x1080 24P 16:9", "2304x1296 30P 16:9", "1280x960 60P 4:3", "1280x960 48P 4:3", "1280x720 60P 16:9", "1280x720 48P 16:9", "1280x720 120P 16:9", "848x480 240P 16:9" ] }

"options" - Available options for requested key, in this example "video_resolution"

Get single setting

Request:

{"msg_id":1,"type":"video_resolution","token":1}

"type" - The key you want
Response:

{"rval":0,"msg_id":1,"type":"video_resolution","param":"1920x1080 60P 16:9"}

Get sdcard space

Request:

{"msg_id":5,"type":"free","token":1}

"type" - free or total
Response:

{ "rval": 0, "msg_id": 5, "param": 15146464 }

"param" - Free (Or total) space on sdcard in bytes

Set single setting

Request:

{"msg_id":2,"type":"video_resolution","param":"1920x1080 60P 16:9","token":1}

"type" - Key you want to set
"param" - Value from available choices
Response:

{ "rval": 0, "msg_id": 2 ,"type":"video_resolution","param":"1920x1080 60P 16:9"}

"rval" - Return value, should be 0 if everything is ok

@Informatic
Copy link

If anyone needed, I've released a MIT-licensed python library to control these cameras a long time ago:
https://github.com/Informatic/ambarpc/blob/master/ambarpc.py

@cara
Copy link

cara commented Nov 29, 2018

@Nokius how did you create the tcpdump? Because of direct AP I don't find it that easy to log it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment