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