Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement displaying jpeg possible? #2328

Open
KjellVerb opened this issue Oct 17, 2024 · 11 comments
Open

Enhancement displaying jpeg possible? #2328

KjellVerb opened this issue Oct 17, 2024 · 11 comments
Labels
Enhancement For suggestions that add new features or improve existing functionalities. Page: image (future) To handle requests for a future image display

Comments

@KjellVerb
Copy link

Enhancement Summary

display image

Detailed Description

Would it in any way be possible to download and display an image from an http server or does the NSpanel architecture with the nextion display prevent this?
It would be awesome to have the panel display a photo from the doorbell camera whenever somebody rings it.

Additional Context

No additional context...

@KjellVerb KjellVerb added the Enhancement For suggestions that add new features or improve existing functionalities. label Oct 17, 2024
@KjellVerb KjellVerb changed the title Enhancement Enhancement displaying jpeg possible? Oct 17, 2024
@edwardtfn
Copy link
Collaborator

Please take a look at this:

Technically, transfer an image is feasible, however the settings used by Nextion isn't the best for this.
Currentlyl we are communicating to the display at 115200bps, and if we transfer pixel by pixel for a 480x320 pixels, 16bit color, it would take at best more than 20sec (just the theoretical communication without any error control). But the normal Nextion protocol requires several bytes per pixel.
We can increase this rate (up to 921600bps is supported) but will still a slow process, most likely driving to buffer overflows (already an issue today with the normal pages).
Another option would be converting the image to more advanced geometry, as Nextion accepts lines, circles and rectangles so we could reduce the communication when areas of the picture have the same color, however this will require way more advanced logic in the Blueprint (or ESPHome) side, and I'm not sure I can do it without additional hands. 😩

@KjellVerb
Copy link
Author

Apologies that I did not find the case you referenced. The necessary transfer time would make it useless anyway for the case that I proposed. Thanks for your answer and I will close this case now.

@edwardtfn
Copy link
Collaborator

No need for apologies, please. :)

I still wanna find some time to look at this anyways. I do consider changing the baud rate to 921600bps, but that would require tons of tests.

@KjellVerb
Copy link
Author

Were there any signal integrity measurements executed on the UART? I could take a look at it to see whether reliable 921600bps would be achievable.

There is limited info on dynamic image display but it seems like this should be possible: https://community.home-assistant.io/t/upload-an-image-to-nextion-intelligent-series/403764
I'm happy to collaborate but not very skilled at SW design as a HW engineer.

@KjellVerb
Copy link
Author

Collecting some more relevant links here in case I or anyone else feels like picking this up.
https://www.youtube.com/watch?v=hTtUgQ8Vkek
https://www.youtube.com/watch?v=JLrLsmf9c4M
https://www.youtube.com/watch?v=nKL0M23c_HU

@edwardtfn
Copy link
Collaborator

Collecting some more relevant links here in case I or anyone else feels like picking this up.

Thanks for sharing!! I wanna go deep on this some time in the future, but would be really nice if someone else could take a look sooner.

About the links you shared, these are based on twfile command, which is not available on the Nextion model used on NSPanel. 😞

I believe for this model the best approach would be using advanced reparse mode to implement a protocol to transfer initial coordinates and a sequence of colors, and process it into the display itself to plot each pixel. With this we reduce a lot the amount of bytes needed on the transfer and therefore could make it possible to transfer in a reasonable amount of time.
I'm also working on changing the default baud rate to 921600 and, if this works fine, the transfer time would be 1/8 of what it is today.

@KjellVerb
Copy link
Author

I'd love to support you in this investigation but I'm not sure I have the skills :-)

@edwardtfn
Copy link
Collaborator

Maybe you can help with specifications and testing at least. 😉

My idea was to have an action to display an image where the user provides a url for that image.
ESPHome should then download that image and convert it to a matrix of colors on it's PSRAM, then transfer all the pixels to Nextion, which will open a specific empty page, process that info and plot the pixels in the screen...

What should be the maximum time acceptable from sending the action from HA to the image being completely visible on the panels display?

@KjellVerb
Copy link
Author

I did some further thinking about the specification:

  • what type of image file can be supported --> resolution, extension, compression, ...?
  • can we add a "tap screen to refresh" function? Or just in general an event when tapping this specific page that we can capture in HA?
  • For me personally the maximum time would be in the order of 5 seconds. That feels like an acceptable time between the doorbell being pressed and me seeing who is there. We could also try some fancy stuff by scanning through the pixels in a certain order, for instance first plotting every odd row or column and then in a 2nd pass filling in the missing lines, that way a blurrier image is already visible in half the time.

@edwardtfn
Copy link
Collaborator

My idea is to start with the minimum functional solution, then improve it over time...

  • what type of image file can be supported --> resolution, extension, compression, ...?

I would try to use as much as possible the Online Image component currently available on ESPHome to transfer the image to PSRAM and then get the color of each pixel to be sent to Nextion (to be developed).
I'm not sure which formats are supported, but all their docs mentions PNG only. Anyhow, if adding support to additional formats, I woukd prefer to add on that component, and not an implementation specifically for NSPanel.

  • can we add a "tap screen to refresh" function? Or just in general an event when tapping this specific page that we can capture in HA?

This wouldn't be hard... Even to pass a refresh interval as a parameter when calling the action to plot the picture.

  • For me personally the maximum time would be in the order of 5 seconds. That feels like an acceptable time between the doorbell being pressed and me seeing who is there. We could also try some fancy stuff by scanning through the pixels in a certain order, for instance first plotting every odd row or column and then in a 2nd pass filling in the missing lines, that way a blurrier image is already visible in half the time.

Ok, I think I will start trying to make this working within 5s. It should be feasible, but must be tested as many things could interfere (including the processing limitations on both sides).
After having it functional, improve it to interlacing lines and/or columns shouldn't be hard.

@KjellVerb
Copy link
Author

I would try to use as much as possible the Online Image component currently available on ESPHome to transfer the image to PSRAM and then get the color of each pixel to be sent to Nextion (to be developed).
I'm not sure which formats are supported, but all their docs mentions PNG only. Anyhow, if adding support to additional formats, I would prefer to add on that component, and not an implementation specifically for NSPanel.

For now I would indeed start with PNG as that seems to be the only one currently supported by that ESPHome component. Handling conversion and even rescaling in HA is probably the best starting point. Then your code can assume it gets an image with the correct extension and size.

One possible option to handle the HA "preprocessing" of the image is to create a shell script that calls imagekick:
sudo apt-get install imagemagick
convert -resize 480X320 source.jpg dest.png

@edwardtfn edwardtfn reopened this Oct 29, 2024
@edwardtfn edwardtfn added the Page: image (future) To handle requests for a future image display label Oct 31, 2024
edwardtfn added a commit that referenced this issue Nov 19, 2024
Solves #2230
Helps with the following:
- #1270
- #2328
- #2357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For suggestions that add new features or improve existing functionalities. Page: image (future) To handle requests for a future image display
Projects
None yet
Development

No branches or pull requests

2 participants