greghesp / ha-bambulab

A Home Assistant Integration for Bambu Lab Printers
856 stars 69 forks source link

[Bug] EXTERNAL: Error opening camera streams due to X1 firmware issues #221

Open bubbleytea opened 1 year ago

bubbleytea commented 1 year ago

Describe the bug

Camera streams stopped working and I see this error in the logs:

2023-09-19 21:17:18.749 ERROR (stream_worker) [homeassistant.components.stream.stream.camera.x1c_****_camera] Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtsps://****:****@192.168.1.168/streaming/live/1

Camera streams time out: image

They were working before when I first set up the integration.

To Reproduce

Install integration and add devices. Eventually the streams just stop loading.

Expected Behaviour

Camera stream loads

What device are you using?

X1C

Firmware Version

01.06.03.00

Home Assistant Version

2023.9.2

Component Version

1.5.0

Log Extracts

2023-09-19 21:17:18.749 ERROR (streamworker) [homeassistant.components.stream.stream.camera.x1c*_camera] Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtsps://**:****@192.168.1.168/streaming/live/1

Other Information

I don't see any other errors in the logs. Is there anything else I can do to help debug?

greghesp commented 1 year ago

Has the IP of your printer changed by any chance?

bubbleytea commented 1 year ago

Has the IP of your printer changed by any chance?

No, I checked and the IPs of all the printers are still the same. All of the other sensors are working properly (I'm assuming those would be broken too, if the IP changed?).

greghesp commented 1 year ago

Ah yeah you're right. I got the logic mixed up with something else I did.

Can you access the stream via VLC?

IIDemoniaKII commented 1 year ago

Hello,

I have the same problem.

Error from stream worker: Error opening stream (EXIT, Immediate exit requested) rtsps://:@us.mqtt.bambulab.com/streaming/live/1

greghesp commented 1 year ago

Ohhh ok, I know the cause of this now. The URL is populated from the config flow, not the MQTT. Will revert

IIDemoniaKII commented 1 year ago

Thank you for your work !

greghesp commented 1 year ago

Can you try the latest pre-release please: https://github.com/greghesp/ha-bambulab/releases/tag/v1.7.1-dev1

IIDemoniaKII commented 1 year ago

Hello,

Still does not work.

Tried to install locally, without success.

I am attaching error logs, but I am not sure that they correspond to this problem.


Logger: aiohttp.server Source: custom_components/bambu_lab/camera.py:64 Integration: Bambu Lab (documentation, issues) First occurred: 18:10:13 (2 occurrences) Last logged: 18:11:23

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle result = await handler(request, **request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 763, in get return await self.handle(request, camera) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 803, in handle stream = await camera.handle_async_mjpeg_stream(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 624, in handle_async_mjpeg_stream return await self.handle_async_still_stream(request, self.frame_interval) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 612, in handle_async_still_stream return await async_get_still_stream( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 280, in async_get_still_stream img_bytes = await image_cb() ^^^^^^^^^^^^^^^^ File "/config/custom_components/bambu_lab/camera.py", line 76, in async_camera_image stream_source = await self.stream_source() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/bambu_lab/camera.py", line 64, in stream_source url = URL(self.coordinator.get_model().camera.rtsp_url).with_user('bblp').with_password( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/yarl/_url.py", line 835, in with_user raise ValueError("user replacement is not allowed for relative URLs") ValueError: user replacement is not allowed for relative URLs

greghesp commented 1 year ago

Hello,

Still does not work.

Tried to install locally, without success.

I am attaching error logs, but I am not sure that they correspond to this problem.

Logger: aiohttp.server Source: custom_components/bambu_lab/camera.py:64 Integration: Bambu Lab (documentation, issues) First occurred: 18:10:13 (2 occurrences) Last logged: 18:11:23

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle result = await handler(request, request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 763, in get return await self.handle(request, camera) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 803, in handle stream = await camera.handle_async_mjpeg_stream(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 624, in handle_async_mjpeg_stream return await self.handle_async_still_stream(request, self.frame_interval) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 612, in handle_async_still_stream return await async_get_still_stream( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init**.py", line 280, in async_get_still_stream img_bytes = await image_cb() ^^^^^^^^^^^^^^^^ File "/config/custom_components/bambu_lab/camera.py", line 76, in async_camera_image stream_source = await self.stream_source() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/bambu_lab/camera.py", line 64, in stream_source url = URL(self.coordinator.get_model().camera.rtsp_url).with_user('bblp').with_password( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/yarl/_url.py", line 835, in with_user raise ValueError("user replacement is not allowed for relative URLs") ValueError: user replacement is not allowed for relative URLs

Oops, minor issue. New dev release: https://github.com/greghesp/ha-bambulab/releases/tag/v1.7.1-dev2

You might need to reload the integration

IIDemoniaKII commented 1 year ago

Hello, I can't find the version on HACS.

greghesp commented 1 year ago

Hello, I can't find the version on HACS.

Have you go the Beta toggle ticked?

IIDemoniaKII commented 1 year ago

Yes, i see v1.7.1-dev1

greghesp commented 1 year ago

Yes, i see v1.7.1-dev1

Odd. I just checked my production instance and it's there. Maybe try toggling it? Sometimes its in the drop-down, but you have to select off if and then back into it for it to select

IIDemoniaKII commented 1 year ago

I will try to uninstall completely and download again

IIDemoniaKII commented 1 year ago

No, it doesn't appear 1 2

IIDemoniaKII commented 1 year ago

Capture d'écran 2023-09-30 210234

greghesp commented 1 year ago

Ahhhh, I'd created the tag but not the release. Oops! Try again now

IIDemoniaKII commented 1 year ago

Upload the file directly to home assistant, unfortunately it still doesn't work

Logger: homeassistant.components.stream.stream.camera.x1c_00m09a371200619_camera Source: components/stream/init.py:434 Integration: Stream (documentation, issues) First occurred: 21:30:52 (7 occurrences) Last logged: 21:34:22

Error from stream worker: Error opening stream (PROTOCOL_NOT_FOUND, Protocol not found) ://bblp:edc1d6f5@disable

IIDemoniaKII commented 1 year ago

Now i see, i test

Capture d'écran 2023-09-30 213642

greghesp commented 1 year ago

Oh - you don't have RTSP enabled on your printer. After the @ sign in that URL should have the IP address, but its reporting disabled instead

IIDemoniaKII commented 1 year ago

My fault, I forgot to reactivate live. It works, thank you very much! Beautiful evening

greghesp commented 1 year ago

Seems I've also got the same issue as OP 2023-10-01 11:19:06.584 ERROR (stream_worker) [homeassistant.components.stream.stream.camera.x1c_00m00a280103660_camera] Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtsps://****:****@192.168.1.64/streaming/live/1

I'm not sure this is an issue with the integration, as VLC cannot access the stream either.

@bubbleytea - Have you got Timelapse on? I've never had this issue before, and I've just turned timelapse on and now have this issue

IIDemoniaKII commented 1 year ago

Hello,

New problem it seems, my timelaps is activate

Logger: homeassistant.components.stream.stream.camera.x1c_00m09a371200619_camera Source: components/stream/init.py:434 Integration: Stream (documentation, issues) First occurred: 12:39:31 (5 occurrences) Last logged: 12:42:02

Error from stream worker: Error opening stream (INVALIDDATA, Invalid data found when processing input) rtsps://:@192.168.68.140/streaming/live/1 Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtsps://:@192.168.68.140/streaming/live/1 Error from stream worker: Error opening stream (PROTOCOL_NOT_FOUND, Protocol not found) ://bblp:edc1d6f5@disable

greghesp commented 1 year ago

Error from stream worker: Error opening stream (PROTOCOL_NOT_FOUND, Protocol not found) ://bblp:edc1d6f5@disable

This looks like it's been disabled again

IIDemoniaKII commented 1 year ago

Reactivate..., this printer likes to play jokes on me...

Logger: homeassistant.components.stream.stream.camera.x1c_00m09a371200619_camera Source: components/stream/init.py:434 Integration: Stream (documentation, issues) First occurred: 12:46:29 (1 occurrences) Last logged: 12:46:29

Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtsps://:@192.168.68.140/streaming/live/1

greghesp commented 1 year ago

I'm also getting this issue as well. It's nothing to do with HA from what I can tell, as I'm also unable to access the stream from VLC. Must be a bug in the firmware

AdrianGarside commented 10 months ago

Re-added IP fix up workaround: #299

mateuszdrab commented 9 months ago

Re-added IP fix up workaround: #299

I've applied the fix to my copy of the component but it's still showing me the same error as @IIDemoniaKII has:

Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtsps://****:****@192.168.0.136/streaming/live/1

greghesp commented 9 months ago

Re-added IP fix up workaround: #299

I've applied the fix to my copy of the component but it's still showing me the same error as @IIDemoniaKII has:

Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtsps://****:****@192.168.0.136/streaming/live/1

Double check that its enabled on your printer. This error is the printer not returning a stream, usually because its disabled

mateuszdrab commented 9 months ago

Lan View is enabled - I was just playing with the local instance of Bambu Studio and figured out I can get a cloud stream on demand by running bambu_source and piping it into ffmpeg which is what the studio does. bambu_source takes a token from a file called url.txt which I presume is populated from some API call the studio does.

Printer is in cloud mode - integration is connected using cloud mode as well

greghesp commented 9 months ago

Yep, that cloud stream has nothing to do with rtsp, and its a proprietary streaming protocol.

Can you try disabling and enabling it on your printer?

AdrianGarside commented 9 months ago

Lan View is enabled - I was just playing with the local instance of Bambu Studio and figured out I can get a cloud stream on demand by running bambu_source and piping it into ffmpeg which is what the studio does. bambu_source takes a token from a file called url.txt which I presume is populated from some API call the studio does.

Printer is in cloud mode - integration is connected using cloud mode as well

Can I get more details on the steps to view the cloud stream?

mateuszdrab commented 9 months ago

Yep, that cloud stream has nothing to do with rtsp, and its a proprietary streaming protocol.

Can you try disabling and enabling it on your printer?

I've done that but it made no difference. I can't see any rtsp/rtsps ports open on the printer. I did find that the FTP server is available, I think this could be utilized to integrate with the media browser to provide users with timelapse video access directly from HA.

Regarding the camera, does anyone with X1C actually got it working? If so, I'll just go and check things with Bambu support.

I was thinking of using the proprietary Bambu source executable to provide the stream to home assistant via rtp for now, hence my attempts at working out how it works.

mateuszdrab commented 9 months ago

Lan View is enabled - I was just playing with the local instance of Bambu Studio and figured out I can get a cloud stream on demand by running bambu_source and piping it into ffmpeg which is what the studio does. bambu_source takes a token from a file called url.txt which I presume is populated from some API call the studio does.

Printer is in cloud mode - integration is connected using cloud mode as well

Can I get more details on the steps to view the cloud stream?

I just figured out what happens behind the scenes when you Go Live from Bambu Studio. If you enable that switch there, you can access the camera via ftp://localhost:1234 which is the result of Bambu Source bring executed and piping the output into ffmpeg which is then made to listen on port 1234. However, the token in the url.txt file which is needed to start bambu source isn't valid forever so I'd need to figure out how that token is generated before the above steps make sense.

greghesp commented 9 months ago

Lan View is enabled - I was just playing with the local instance of Bambu Studio and figured out I can get a cloud stream on demand by running bambu_source and piping it into ffmpeg which is what the studio does. bambu_source takes a token from a file called url.txt which I presume is populated from some API call the studio does. Printer is in cloud mode - integration is connected using cloud mode as well

Can I get more details on the steps to view the cloud stream?

I just figured out what happens behind the scenes when you Go Live from Bambu Studio. If you enable that switch there, you can access the camera via ftp://localhost:1234 which is the result of Bambu Source bring executed and piping the output into ffmpeg which is then made to listen on port 1234. However, the token in the url.txt file which is needed to start bambu source isn't valid forever so I'd need to figure out how that token is generated before the above steps make sense.

That's purely for their "go live" functionality that allows you to stream to Twitch or whatever. All that does is take the proprietary stream, and then re-broadcasts it on a local IP address from your machine.

Regarding the camera, does anyone with X1C actually got it working? If so, I'll just go and check things with Bambu support.

Sometimes. I've already raised it with them and they are aware and have found the bug

mateuszdrab commented 9 months ago

Lan View is enabled - I was just playing with the local instance of Bambu Studio and figured out I can get a cloud stream on demand by running bambu_source and piping it into ffmpeg which is what the studio does. bambu_source takes a token from a file called url.txt which I presume is populated from some API call the studio does. Printer is in cloud mode - integration is connected using cloud mode as well

Can I get more details on the steps to view the cloud stream?

I just figured out what happens behind the scenes when you Go Live from Bambu Studio. If you enable that switch there, you can access the camera via ftp://localhost:1234 which is the result of Bambu Source bring executed and piping the output into ffmpeg which is then made to listen on port 1234. However, the token in the url.txt file which is needed to start bambu source isn't valid forever so I'd need to figure out how that token is generated before the above steps make sense.

That's purely for their "go live" functionality that allows you to stream to Twitch or whatever. All that does is take the proprietary stream, and then re-broadcasts it on a local IP address from your machine.

Regarding the camera, does anyone with X1C actually got it working? If so, I'll just go and check things with Bambu support.

Sometimes. I've already raised it with them and they are aware and have found the bug

Awesome, I hope the fix makes it into the new upcoming firmware.

brantje commented 9 months ago

I get the same error, but my URL looks very different:

Error from stream worker: Error opening stream (PROTOCOL_NOT_FOUND, Protocol not found) ://bblp:4xxfxxe@disable

I suppose re-adding the integration will solve this?

greghesp commented 9 months ago

I get the same error, but my URL looks very different:

Error from stream worker: Error opening stream (PROTOCOL_NOT_FOUND, Protocol not found) ://bblp:4xxfxxe@disable

I suppose re-adding the integration will solve this?

What version are you on? On the latest dev version, should be able to see in the logs

homeassistant | 2023-12-22 14:13:17.461 DEBUG (MainThread) [custom_components.bambu_lab] Camera RTSP Feed is rtsps://bblp:<access_code>@192.168.1.64/streaming/live/1
AdrianGarside commented 9 months ago

I get the same error, but my URL looks very different:

Error from stream worker: Error opening stream (PROTOCOL_NOT_FOUND, Protocol not found) ://bblp:4xxfxxe@disable

I suppose re-adding the integration will solve this?

@disable means you don't have lan view enabled.

AdrianGarside commented 9 months ago

Fix to make Camera entity disabled when lan view is not enabled:

325

AdrianGarside commented 9 months ago

I'm going to mark this as won't fix for now as there are no known issues in the integration handling of the rtsp feed - all indications are that the remaining problems are all bugs in the firmware implementation on the Bambu side.

mateuszdrab commented 9 months ago

Are there any updates on the support case with Bambu Lab?

Lastest firmware came in recently and the issue still exists.

anoblet commented 9 months ago

I can get a camera stream after first boot on an X1C using HA. After that it drops off. I'm not sure when, or why, though diffing the i/o could provide a clue. Does the FW just drop multiple streams? Does it fallback on trusted domains?

Anyways please take some time for the holidays, we'll always be here :)

AdrianGarside commented 9 months ago

The RTSP support in the firmware is just very buggy unfortunately.

anoblet commented 9 months ago

It hasn't bothered me much, it seems like a finicky problem to solve. Everything else works great :)

jmwaldrip commented 9 months ago

I was having the same right after I upgraded to firmware 1.7.01.00. I played with it for a while, but after I hard rebooted the printer it started working.

I am having some timestamp differences errors but it seems to be working well.

image

I will add another comment if it stops working or has any issues. So far seems pretty stable.

I am also starting to play with WebRTC and streaming it through that to see if it makes a difference.

AdrianGarside commented 9 months ago

What I’m finding is that with webrtc and pointing both my production and test instance of home assistant at the same go2rtc instance then I have a reliable connection. But if I restart home assistant (and with my docker based setup that restarts go2rtc) then the connection is broken until I restart the printer.

AdrianGarside commented 9 months ago

While when I had two separate go2rtc instances the connection I think was not reliable even if I didn’t restart my production home assistant instance but I’m not certain.

jmwaldrip commented 9 months ago

Oh interesting, I haven't had time to try the a webrtc server yet. What are you using for the docker container? I was thinking of throwing it on my k8s cluster.

jneilliii commented 9 months ago

go2rtc is one I've used outside of HA before, but think it's actually bundled in HA too IIRC