String formatting in Nextion

Hello, I have a problem that I could not find any solution on the internet.

I am trying to send a protocol to an Arduino from Nextion device, which goes as “*/num4/num2/num3/num1/arg1/arg2/arg3/arg4/arg5/#”. arg1 to arg5 are used only for control variables, but all nums are data extracted from a counter. I wanted to make string formatting using %d but it does not seem to work. How can I send such a data to Nextion? Thank you.

It is not clear to me whether you want to generate the protocol string on Nextion to send it to the Arduino or the other way round.

In case, you want to generate it on the Nextion, you need two string variables, one to assemble the big string (with enough txt_maxlen) and one for temporary conversions:

big.txt="*/"
covx num4,tmp.txt,0,0
big.txt+=tmp.txt
big.txt+="/"
covx num2,tmp.txt,0,0
big.txt+=tmp.txt
big.txt+="/"
covx num3,tmp.txt,0,0
big.txt+=tmp.txt
big.txt+="/"
covx num1,tmp.txt,0,0
big.txt+=tmp.txt
big.txt+="/"

Afterwards, everything depends if your arg1 to arg5 are numeric or strings. If numeric, do the same with covx as for num1 to num4. It strings, append these (and the required slashes) directly to big.txt. At the end, don’t forget to finish with

big.txt+="/#"

… and you are done!

2 Likes