Setting up a generic camera / stream SXJ02ZM

I’m using the SXJ02ZM xiaomi all white camera with the openfang hack (https://github.com/anmaped/openfang). I have multiple problems which I don’t know how to deal with. My setup in my config is as follows:

stream:
camera:
  - platform: generic
    name: "Palantir"
    still_image_url: https://192.168.0.39/cgi-bin/currentpic.cgi
    stream_source: rtsp://192.168.0.39:8554/unicast
    verify_ssl: false

In this setup I get a preview image and the rtsp stream without any issues in lovelace (also with preview). When I try to record/snapshot it does not work though and most likely crash my rtsp stream/cam. When I try to stream it to my chromecast my image stays black on my chromecast after a loading screen.

Since openfang uses some encryption I also tried to enable verify_ssl: true. That resulted in the preview image not being shown anymore, the stream itself still worked. When I now try to record I get the message that it is already recording, although it never finishes/creates a file. The snapshot still does not work. When checking the logs I can find the following error:

2020-01-29 18:45:30 ERROR (MainThread) [homeassistant.components.generic.camera] Error getting new camera image: Cannot connect to host 192.168.0.39:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1076)')]
2020-01-29 18:45:30 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.2889301296] a bytes-like object is required, not 'NoneType'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 134, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1226, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1251, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 201, in handle_service
    self._platforms.values(), func, call, service_name, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 335, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 359, in _handle_service_platform_call
    await func(entity, data)
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 658, in async_handle_snapshot_service
    await hass.async_add_executor_job(_write_image, snapshot_file, image)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 655, in _write_image
    img_file.write(image_data)
TypeError: a bytes-like object is required, not 'NoneType'
2020-01-29 18:45:37 ERROR (MainThread) [homeassistant.components.generic.camera] Error getting new camera image: Cannot connect to host 192.168.0.39:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1076)')]

Unfortunately I have no idea how to set this up correctly. Having the rtsp stream working is nice, but not being able to record/take snapshots is kinda stupid. I also don’t really understand how the “preview” is working (since this is basically saving the stream) but actually recording something does not work.

Any help would be appreciated.

I’ve had some progress. Turns out I apparently had some permission issues for the recording/snapshots - so I got it working. The streaming to chromecast is still not working. I still get no error when trying to play to chromcast, but I occosionally see this erro:

2020-01-31 23:02:38 ERROR (stream_worker) [homeassistant.components.stream.worker] Error demuxing stream: No dts in packet

I also noticed that my recorded videos have information about their length (it displays 0 seconds long but it keeps on playing for how ever long I recorded it, I also cannot fast-forward etc.). Could this also be the problem why chromecast is not working? Is there maybe a way to try to fix this using ffmpeg?

Hi,

I have the same device and wanted to use this in HA.
This thread is the only solution I came to know so far.
Can you please guide me on how can I flash the openfang?

Thanks a ton.

There is a detailed description here: https://github.com/anmaped/openfang/blob/695670d5977bcb7b77c4fcbadeb9885c08546743/doc/install.md

In this description there is also a link to this guide: https://github.com/anmaped/openfang/blob/695670d5977bcb7b77c4fcbadeb9885c08546743/doc/SXJ02ZM/SXJ02ZM_instructions.md

1 Like

Thanks, I was not able to find the link to the guide, Now I got it.

Thanks a lot.

SXJ02ZM is almost useless with openfang (which is a dead project) and SXJ02ZM is only partially supported. It’s also very hard to hack this camera. Even open the case is a challenge. You have to compile fw yourself because links for compiled binary are not working (there isn’t bin for SXJ02ZM). After that you have to desolder one leg in smd chip… Difficult level 9/10 for me (and I’m not beginner in extreme electronics). Generally waste of time.

Yeah… There is somewhere a link to a compiled firmware and also a comment that it works even without desoldering the leg. But still, a lot of features don’t work properly and the cam crashes constantly for me (needs to be replugged).

@ciB did you have to open the camera and desolder and stuff or could you install openfang just by putting a firmware on the sdcard?

I had to open and disolder.

could you upload the compiled version of the firmware you used please (pretty please)?

I used these here:

https://www.icloud.com/iclouddrive/0H8if7EBB_qxo03mdVsmtu-hQ#u-boot-lzo-with-spl_t20_64M
https://www.icloud.com/iclouddrive/0m5dK_4geRcueh9aKBY2ezBXQ#rootfs.ext2

As mentioned before, for whatever reason the cam crashed quite often - I have added a smart plug and added a script to restart it once it becomes unresponsive :rofl:

i plan to do the same :smiley:

atleast ill get storage on the NAS and can cutoff access to my home surveillance from the cloud!

@ciB does the VCC leg (pin 8) of the SOP8 chip need to be resoldered back after flashing the firmware for the camera to work? I desoldered the pin, flashed the firmware using a CH341a programmer successfully, partitioned the sdcard, burned the rootfs to the sdcard correctly, etc but the camera doesnt show up any LEDs on turning it on now.

Yeah, I think it needs to be resoldered.

My cam also took a while before it started working, was about to throw it out, but the next time I plugged it in the leds turned on

You think or you did? Anyway i ended up destroying the SOP8 chip in my attempt to resolder. This is indeed too difficult to execute. The legs are too tiny and even a sharp soldering iron can’t cut them evenly. Ended up throwing it and buying a TP-Link Tapo C100 which supports RTSP out of the box (thanks tplink!)

Yeah… I bought one of them too just the other day from Amazon.es - was only around 13 euros :upside_down_face: