Nextion. GetValue -Stack smashing protect failure!

Hello friends,

Since many of us here are using the nextion libary i wanted to try to solve the following problem with this library. I am talking specifily about the getValue - function of this library to get numbers from the nextion.

I know, that this lib isnt the best and that there are many other ways, but i would love to find the problem in this lib.

It happens sometimes when i use the function getValue() often after another (via a button) , that i get the following error and my esp32 is restarting (When i comment this function out, this error vanishs):

Stack smashing protect failure!

abort() was called at PC 0x400f0350 on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x40085a10:0x3ffb1e30 0x40085c8d:0x3ffb1e50 0x400f0350:0x3ffb1e70 0x400d2c12:0x3ffb1e90 0x4011b4e1:0x3ffb1f20 0x400d6672:0x3ffb1f40 0x400d62b2:0x3ffb1f60 0x400d2fa7:0x3ffb1f90 0x400d97ad:0x3ffb1fb0 0x40086c9e:0x3ffb1fd0

I try to unravel the function. Maybe someone of you spots something that could cause this problem:

bool NexNumber::getValue(uint32_t *number)
{   
    String cmd = String("get ");
    cmd += getObjName();
    cmd += ".val";
    sendCommand(cmd.c_str());
    return recvRetNumber(number);
}

const char* NexObject::getObjName(void)
{
    return __name;
}

void sendCommand(const char* cmd)
{  
//    dbSerialPrintf("[%08ld]sendCommand Sent: |%s| FF FF FF\n", millis(), cmd);    
    nexSerial.print(cmd);
    nexSerial.write(0xFF);
    nexSerial.write(0xFF);
    nexSerial.write(0xFF);
}

bool recvRetNumber(uint32_t *number, uint32_t timeout)
{
     
    bool ret = false;
     
    uint8_t temp[4] = { 0, 0, 0, 0 };
    if (number)
    {
        
        ret = getNumber((byte *)number, timeout); 
         
    }

    if (!ret) 
    {
         
        dbSerialPrintf("recvRetNumber err\n");
         
    }
    return ret;
}

boolean getNumber(byte *p, int timeout)
{
    uint32_t t = millis();
    boolean ret = false;
    dataMsgAvailable = false;
    parseRx(p, sizeof(uint32_t));

    while (!dataMsgAvailable)
    {
        if (((millis() - t) > timeout) || (timeout == 0))
        {
            dbSerial.println("getNumber timeout");
            break;
        }

        parseRx(NULL, 0);
    }

    if (dataMsgAvailable)
    {
        dataMsgAvailable = false;
        ret = true;
    }

    return ret;
}

Anyone an idea? What i noticed. A delay(1000) kinda solves this problem. What does it tell us?

Thank you

Something went wrong with the stack. I can not see it in the code, but I would start to check the parseRx() function.

The code uses many things that we can't see. We prefer to see the full sketch. There is even a website for it: https://snippets-r-us.com/.

Can you make the code more simple and straightforward ?

The code is giving me a bad feeling.
For example:

  • The variable 'temp[4]' is not used.
  • The variable 'number' is not a number, but it is a pointer.
  • A pointer to a 32-bit variable is changed into a pointer to a byte.
  • I have doubts if the timing works with the flag 'dataMsgAvailable'.
  • What is calling parseRx(NULL, 0) about, when there is no data.
  • I can't see the 'recvRetNumber()' prototype, so I don't know what the second parameter is when it is not used

Which Nextion library do you use ?
If this is the code to make it work, then I suggest to abandon this and start over with a simple library.

thank you for the reply.

I will try to make the code easier to read.

Do you use a nextion? If so what lib. would you suggest?

Thank you

I started with the ITEAD Nextion Arduino library and kept changing it until one day I noticed that I used nothing of the library anymore.
My code is only a small subset, and I have split the RX and TX streams and handle them separately.

This is the starting point for something simpler: https://forum.arduino.cc/t/using-nextion-displays-with-arduino/580289

Did you know that you can still change the Category of this topic on the forum ? Go to your top post, edit it, and change the category to "Displays".

[EDIT] It was the wrong link ! fixed.

1 Like

Thank your for the response.

May can i ask you how you read numbers from your nextion? The getNumber() function is somehow broken

Thank you

It is a while ago, but I think that I don't.
I put as much as possible in the Arduino and let the Nextion display do as little as possible. When I press a button on the Nextion display, then that is send to the Arduino.
To set the time, I have buttons for up and down, not for entering numbers.

I think I know where the confusion comes from. You are still trying to make the ITEAD_Nextion_Arduino library work.
I'm very sorry, I put the wrong link in my previous post. This is the starting point to use a Nextion display without the ITEAD library: https://forum.arduino.cc/t/using-nextion-displays-with-arduino/580289