Have you ever wondered why the Nextion Editor can upload TFT files faster than any other tool? Simple. It uses a newer version of the Nextion Upload Protocol that allows to skip parts of the TFT file if they haven’t been modified. In practice this means that all of your pictures, fonts, etc (<= ressource section of the TFT file) will be skipped if you did not touch anyone of them. Only the stuff you coded/designed in the editor will be uploaded in that case.
As a lot of other useful information Nextion does not share any details about this improved protocol. However, it is not more complicated than the well-known protocol v1.1; the differences are minor. You should know and understand how that protocol works before continuing.
I wrote a Python script called Nexus that implements this improved upload protocol. It can easily be used via command line. The script can be found here: Nexus - Nextion Upload Script
How it works
The faster protocol (let‘s call it v1.2) is essentially the same as v1.1 except for the following differences:
- While v1.1 initiates the upload by sending the
command, v1.2 uses
(there is an additional
s!). The meaning of the third argument is not clear. However the Nextion editor seems to always set it to
1and I had no problems with a
- After sending the first block of 4096 bytes, which contains the file header, the screen will not return the usual
0x05response but indicate at what address the download shall continue. The response begins with
0x08followed by a 4-byte integer (little endian/lowest byte first). If that integer equals 0 the upload continues without skipping anything. Otherwise it continues at the specified offset.
08 00 00 11 00means f.ex. you shall continue at offset
0x110000. Note that the offset is relative to the beginning of the file, not the current position.
- The TFT file size is actually included in the TFT file at offset
0x3c-0x3f(little endian/lowest byte first). Could be easier/faster to read than to get the file size with other methods.
- For some reason the first command after the
connectprocedure never works (for me at least). Doesn’t matter if I send a
FF FF FFfirst or not, whatever is the next command it will fail (returns
1A FF FF FF). My solution is to send a dummy command and then continue normally.