Unofficial Nextion/TJC User Forum

Convert Nextion to Text

Hello everyone,

It bothered me that you can’t see the changes to your Nextion UI in a git commit diff. Of course you can’t, because it’s a binary file. This also means, that although you might have an open source project, everyone needs to use the - proprietary - Nextion Editor to be able to read the source.
Edit: aaand you can‘t get an overview of all the code that‘s on a page. You can‘t search through it and you have to check every single component if you don‘t know where‘s the code you‘re looking for.

I didn’t like that so I wrote a Python script that converts a given HMI file to text files, one for each page. They contain the essential information about every component (type, local/global, …) and all the event code. Effectively it would be possible to understand how the UI works with these text files.

If this sounds interesting to you, have a look over here (Example included): https://github.com/MMMZZZZ/Nextion2Text

Kind regards,
Max

2 Likes

What a great tool, thanks @Max!

1 Like

Wow! Got a shot, cool one must say :wink:

1 Like

@luma @xwintk Thank you!

Unfortunately I just discovered a problem. Components - and even entire pages - are stored multiple times in the .HMI file. The current version (of course…) and sometimes one or even multiple previous versions even though you have no “undo” option in the editor. When I created the tool it looked like the last version in the file is the most recent one. But now I found out it’s not. Since a few people here have played with the Nextion files, could someone tell me how I can find out which version is the most recent one?

Thanks,
Max

That explains why the HMI file sizes are all over the place from one version to another of the same HMI project.

This is a poor situation, especially when you have a HMI that is close to the memory limits.

I’m now thinking the best interim measure is to export the pages out of the current (and most likely bloated HMI) and import them into a fresh HMI project.

Are you reading this Patrick?
If you’re as clever as you think you are, fix the memory leaks.

@DVEous remember, this is the uncompiled file. Since I never saw a wrong version in the Editor or on a Nextion device, the Editor seems to know pretty well which version it‘s supposed to use, and compiles only this version. Have a look at the sizes in the compiler output. They scale pretty well with the amount of components you place on each page and no pages are multiple times larger than others when they have similar complexity.

Also, I‘m not saying that this is dumb or so. While the Editor doesn‘t allow to go back to past versions after a restart this could be a useful feature they had foreseen when designing the HMI file.

Kind regards,
Max

HMI File Version 33 uses a 512Kb file header TWICE, so even an empty HMI project will start at 1Mb of pure 00’s… it’s utterly rediculous.

There is a flag indicating whether the (duplicate) object is deleted or not:
An HMI starts with 4 bytes which is the object count. Followed by a struct for each object. This includes FileName, StartPosition, ObjectLength and Deleted flag.

Doing a Save As… also clears unused objects from the hmi file.

2 Likes

With the great help of @fvanroie I got a big step closer to actually knowing what I’m doing. At this point I tend to agree a bit more with DVEous; there’s some weird stuff going on in these files.

The script is mostly* fixed, and works as expected. Here’s an example of a commit diff: https://github.com/MMMZZZZ/Nextion2Text/commit/f973ae2f13539c2c6a4b75de33a59943dda9ab27
Surprise, you can actually read and understand what changes were made to the .HMI file.

*That means that the actual components are still parsed in a rather dodgy way. If f.ex. you write a line that has more than 255 characters - even worse if it’s the last one of an event - something will go wrong.
Additionally, there’s still no support for some components and and for some component properties. Wouldn’t be as much fun if it was perfect, right?

Kind regards,
Max


This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).